Commit b0051dfa by Jim Stichnoth

Subzero: Fix g++ warnings.

This tries to use the same -W options that the buildbots use, to reduce the amount of warning spam in the logs. BUG= none R=jpp@chromium.org Review URL: https://codereview.chromium.org/1575873006 .
parent 5aa4b89f
......@@ -189,9 +189,14 @@ LLVM_EXTRA_WARNINGS := -Wcovered-switch-default
ifdef GPLUSPLUS
CXX := CCACHE_CPP2=yes $(CCACHE) g++
STDLIB_FLAGS :=
LLVM_EXTRA_WARNINGS := -Wno-unknown-pragmas -Wno-unused-parameter \
-Wno-comment -Wno-enum-compare -Wno-strict-aliasing \
-Wno-return-type
LLVM_EXTRA_WARNINGS := \
-Wcast-qual \
-Wno-comment \
-Wno-long-long \
-Wno-maybe-uninitialized \
-Wno-missing-field-initializers \
-Wno-unused-parameter \
-Wwrite-strings
OBJDIR := $(OBJDIR)+Gplusplus
endif
......
......@@ -387,6 +387,7 @@ IValueT encodeImmRegOffset(OpEncoding AddressEncoding, IValueT Reg,
assert(Mode == OperandARM32Mem::Offset);
return Reg << kRnShift;
}
llvm_unreachable("(silence g++ warning)");
}
// Encodes memory address Opnd, and encodes that information into Value, based
......
......@@ -526,6 +526,7 @@ void CfgNode::advancedPhiLowering() {
}
}
assert(Found);
(void)Found;
}
// Now that a cycle (if any) has been broken, create the actual
// assignment.
......
......@@ -19,10 +19,16 @@
#include "IceClFlagsExtra.h"
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#endif // __clang__
#include "llvm/Support/CommandLine.h"
#ifdef __clang__
#pragma clang diagnostic pop
#endif // __clang__
namespace cl = llvm::cl;
......
......@@ -17,11 +17,17 @@
#include "IceDefs.h"
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#pragma clang diagnostic ignored "-Wredundant-move"
#endif // __clang__
#include "llvm/IRReader/IRReader.h"
#ifdef __clang__
#pragma clang diagnostic pop
#endif // __clang__
namespace Ice {
......
......@@ -19,15 +19,21 @@
#include "IceELFStreamer.h"
#include "IceGlobalContext.h"
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#endif // __clang__
#include "llvm/Bitcode/NaCl/NaClBitcodeMungeUtils.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/raw_os_ostream.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/StreamingMemoryObject.h"
#ifdef __clang__
#pragma clang diagnostic pop
#endif // __clang__
#include <cstdio>
#include <fstream>
......
......@@ -27,8 +27,11 @@
#include "IceELFObjectWriter.h"
#include "PNaClTranslator.h"
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#endif // __clang__
#include "llvm/ADT/STLExtras.h"
#include "llvm/Bitcode/NaCl/NaClReaderWriter.h"
#include "llvm/IR/LLVMContext.h"
......@@ -37,9 +40,11 @@
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/StreamingMemoryObject.h"
#include <regex>
#ifdef __clang__
#pragma clang diagnostic pop
#endif // __clang__
#include <regex>
namespace Ice {
......
......@@ -26,8 +26,11 @@
#include "IceTypes.h"
#include "IceTypeConverter.h"
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#endif // __clang__
#include "llvm/IR/Constant.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
......@@ -35,7 +38,10 @@
#include "llvm/IR/Instructions.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#ifdef __clang__
#pragma clang diagnostic pop
#endif // __clang__
// TODO(kschimpf): Remove two namespaces being visible at once.
using namespace llvm;
......
......@@ -26,10 +26,16 @@
#include "IceTimerTree.h"
#include "IceTypes.h"
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#endif // __clang__
#include "llvm/Support/Timer.h"
#ifdef __clang__
#pragma clang diagnostic pop
#endif // __clang__
#include <algorithm> // max()
#include <cctype> // isdigit(), isupper()
......
......@@ -23,13 +23,19 @@
#include "IceGlobalContext.h"
#include "IceTypes.h"
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#pragma clang diagnostic ignored "-Wredundant-move"
#endif // __clang__
#include "llvm/Bitcode/NaCl/NaClBitcodeParser.h" // for NaClBitcodeRecord.
#include "llvm/IR/CallingConv.h"
#include "llvm/IR/GlobalValue.h" // for GlobalValue::LinkageTypes.
#ifdef __clang__
#pragma clang diagnostic pop
#endif // __clang__
#include <memory>
#include <utility>
......
......@@ -347,7 +347,7 @@ bool OperandARM32FlexFpImm::canHoldImm(Operand *C, uint32_t *ModifiedImm) {
static_assert(AllowedBits == 0xFFF80000u,
"Invalid mask for f32 modified immediates.");
const float F32 = llvm::cast<ConstantFloat>(C)->getValue();
const uint32_t I32 = *reinterpret_cast<const uint32_t *>(&F32);
const uint32_t I32 = Utils::bitCopy<uint32_t>(F32);
if (I32 & ~AllowedBits) {
// constant has disallowed bits.
return false;
......@@ -376,7 +376,7 @@ bool OperandARM32FlexFpImm::canHoldImm(Operand *C, uint32_t *ModifiedImm) {
static_assert(AllowedBits == 0xFFFF0000u,
"Invalid mask for f64 modified immediates.");
const double F64 = llvm::cast<ConstantDouble>(C)->getValue();
const uint64_t I64 = *reinterpret_cast<const uint64_t *>(&F64);
const uint64_t I64 = Utils::bitCopy<uint64_t>(F64);
if (I64 & 0xFFFFFFFFu) {
// constant has disallowed bits.
return false;
......@@ -2100,7 +2100,7 @@ float materializeFloatImmediate(uint32_t ModifiedImm) {
const uint32_t Ret = ((ModifiedImm & a) ? 0x80000000 : 0) |
((ModifiedImm & b) ? 0x3E000000 : 0x40000000) |
((ModifiedImm & cdefgh) << 19);
return *reinterpret_cast<const float *>(&Ret);
return Utils::bitCopy<float>(Ret);
}
} // end of anonymous namespace
......
......@@ -2623,6 +2623,7 @@ public:
case AO_Sub:
return false;
}
llvm_unreachable("(silence g++ warning)");
}
uint32_t shAmt() const { return ShAmt; }
......@@ -3767,11 +3768,11 @@ enum {
_fcmp_hl_NUM
};
static_assert(_fcmp_hl_NUM == _fcmp_ll_NUM,
static_assert((uint32_t)_fcmp_hl_NUM == (uint32_t)_fcmp_ll_NUM,
"Inconsistency between high-level and low-level fcmp tags.");
#define X(tag, str) \
static_assert( \
_fcmp_hl_##tag == _fcmp_ll_##tag, \
(uint32_t)_fcmp_hl_##tag == (uint32_t)_fcmp_ll_##tag, \
"Inconsistency between high-level and low-level fcmp tag " #tag);
ICEINSTFCMP_TABLE
#undef X
......@@ -6302,7 +6303,7 @@ template <> struct ConstantPoolEmitterTraits<float> {
static uint64_t bitcastToUint64(float Value) {
static_assert(sizeof(Value) == sizeof(uint32_t),
"Float should be 4 bytes.");
uint32_t IntValue = *reinterpret_cast<uint32_t *>(&Value);
const uint32_t IntValue = Utils::bitCopy<uint32_t>(Value);
return static_cast<uint64_t>(IntValue);
}
};
......@@ -6317,7 +6318,7 @@ template <> struct ConstantPoolEmitterTraits<double> {
static uint64_t bitcastToUint64(double Value) {
static_assert(sizeof(double) == sizeof(uint64_t),
"Double should be 8 bytes.");
return *reinterpret_cast<uint64_t *>(&Value);
return Utils::bitCopy<uint64_t>(Value);
}
};
const char ConstantPoolEmitterTraits<double>::AsmTag[] = ".quad";
......
......@@ -116,7 +116,10 @@ struct TargetX8632Traits {
int32_t disp32() const {
assert(length_ >= 5);
return bit_copy<int32_t>(encoding_[length_ - 4]);
// TODO(stichnot): This method is not currently used. Delete it along
// with other unused methods, or use a safe version of bitCopy().
llvm::report_fatal_error("Unexpected call to disp32()");
// return Utils::bitCopy<int32_t>(encoding_[length_ - 4]);
}
AssemblerFixup *fixup() const { return fixup_; }
......
......@@ -132,7 +132,10 @@ struct TargetX8664Traits {
int32_t disp32() const {
assert(length_ >= 5);
return bit_copy<int32_t>(encoding_[length_ - 4]);
// TODO(stichnot): This method is not currently used. Delete it along
// with other unused methods, or use a safe version of bitCopy().
llvm::report_fatal_error("Unexpected call to disp32()");
// return Utils::bitCopy<int32_t>(encoding_[length_ - 4]);
}
AssemblerFixup *fixup() const { return fixup_; }
......
......@@ -17,10 +17,16 @@
#include "IceDefs.h"
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#endif // __clang__
#include "llvm/Support/Timer.h"
#ifdef __clang__
#pragma clang diagnostic pop
#endif // __clang__
namespace Ice {
......
......@@ -18,11 +18,18 @@
#include "IceDefs.h"
#include "IceTypes.h"
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#pragma clang diagnostic ignored "-Wredundant-move"
#endif // __clang__
#include "llvm/IR/DerivedTypes.h"
#ifdef __clang__
#pragma clang diagnostic pop
#endif // __clang__
namespace llvm {
class LLVMContext;
......
......@@ -19,114 +19,111 @@
#include <cmath> // std::signbit()
namespace Ice {
/// Similar to bit_cast, but allows copying from types of unrelated sizes. This
/// method was introduced to enable the strict aliasing optimizations of GCC
/// 4.4. Basically, GCC mindlessly relies on obscure details in the C++ standard
/// that make reinterpret_cast virtually useless.
template <class D, class S> inline D bit_copy(const S &source) {
D destination;
namespace Utils {
/// Allows copying from types of unrelated sizes. This method was introduced to
/// enable the strict aliasing optimizations of GCC 4.4. Basically, GCC
/// mindlessly relies on obscure details in the C++ standard that make
/// reinterpret_cast virtually useless.
template <typename D, typename S> inline D bitCopy(const S &Source) {
static_assert(sizeof(D) <= sizeof(S),
"bitCopy between incompatible type widths");
static_assert(!std::is_pointer<S>::value, "");
D Destination;
// This use of memcpy is safe: source and destination cannot overlap.
memcpy(&destination, reinterpret_cast<const void *>(&source),
sizeof(destination));
return destination;
memcpy(&Destination, reinterpret_cast<const void *>(&Source), sizeof(D));
return Destination;
}
/// Check whether an N-bit two's-complement representation can hold value.
template <typename T> static inline bool IsInt(int N, T value) {
assert((0 < N) &&
(static_cast<unsigned int>(N) < (CHAR_BIT * sizeof(value))));
T limit = static_cast<T>(1) << (N - 1);
return (-limit <= value) && (value < limit);
}
class Utils {
Utils() = delete;
Utils(const Utils &) = delete;
Utils &operator=(const Utils &) = delete;
public:
/// Check whether an N-bit two's-complement representation can hold value.
template <typename T> static inline bool IsInt(int N, T value) {
assert((0 < N) &&
(static_cast<unsigned int>(N) < (CHAR_BIT * sizeof(value))));
T limit = static_cast<T>(1) << (N - 1);
return (-limit <= value) && (value < limit);
}
template <typename T> static inline bool IsUint(int N, T value) {
assert((0 < N) &&
(static_cast<unsigned int>(N) < (CHAR_BIT * sizeof(value))));
T limit = static_cast<T>(1) << N;
return (0 <= value) && (value < limit);
}
/// Check whether the magnitude of value fits in N bits, i.e., whether an
/// (N+1)-bit sign-magnitude representation can hold value.
template <typename T> static inline bool IsAbsoluteUint(int N, T Value) {
assert((0 < N) &&
(static_cast<unsigned int>(N) < (CHAR_BIT * sizeof(Value))));
if (Value < 0)
Value = -Value;
return IsUint(N, Value);
}
/// Return true if the addition X + Y will cause integer overflow for integers
/// of type T.
template <typename T> static inline bool WouldOverflowAdd(T X, T Y) {
return ((X > 0 && Y > 0 && (X > std::numeric_limits<T>::max() - Y)) ||
(X < 0 && Y < 0 && (X < std::numeric_limits<T>::min() - Y)));
}
/// Adds x to y and stores the result in sum. Returns true if the addition
/// overflowed.
static inline bool add_overflow(uint32_t x, uint32_t y, uint32_t *sum) {
static_assert(std::is_same<uint32_t, unsigned>::value, "Must match type");
template <typename T> static inline bool IsUint(int N, T value) {
assert((0 < N) &&
(static_cast<unsigned int>(N) < (CHAR_BIT * sizeof(value))));
T limit = static_cast<T>(1) << N;
return (0 <= value) && (value < limit);
}
/// Check whether the magnitude of value fits in N bits, i.e., whether an
/// (N+1)-bit sign-magnitude representation can hold value.
template <typename T> static inline bool IsAbsoluteUint(int N, T Value) {
assert((0 < N) &&
(static_cast<unsigned int>(N) < (CHAR_BIT * sizeof(Value))));
if (Value < 0)
Value = -Value;
return IsUint(N, Value);
}
/// Return true if the addition X + Y will cause integer overflow for integers
/// of type T.
template <typename T> static inline bool WouldOverflowAdd(T X, T Y) {
return ((X > 0 && Y > 0 && (X > std::numeric_limits<T>::max() - Y)) ||
(X < 0 && Y < 0 && (X < std::numeric_limits<T>::min() - Y)));
}
/// Adds x to y and stores the result in sum. Returns true if the addition
/// overflowed.
static inline bool add_overflow(uint32_t x, uint32_t y, uint32_t *sum) {
static_assert(std::is_same<uint32_t, unsigned>::value, "Must match type");
#if __has_builtin(__builtin_uadd_overflow)
return __builtin_uadd_overflow(x, y, sum);
return __builtin_uadd_overflow(x, y, sum);
#else
*sum = x + y;
return WouldOverflowAdd(x, y);
*sum = x + y;
return WouldOverflowAdd(x, y);
#endif
}
/// Return true if X is already aligned by N, where N is a power of 2.
template <typename T> static inline bool IsAligned(T X, intptr_t N) {
assert(llvm::isPowerOf2_64(N));
return (X & (N - 1)) == 0;
}
/// Return Value adjusted to the next highest multiple of Alignment.
static inline uint32_t applyAlignment(uint32_t Value, uint32_t Alignment) {
assert(llvm::isPowerOf2_32(Alignment));
return (Value + Alignment - 1) & -Alignment;
}
/// Return amount which must be added to adjust Pos to the next highest
/// multiple of Align.
static inline uint64_t OffsetToAlignment(uint64_t Pos, uint64_t Align) {
assert(llvm::isPowerOf2_64(Align));
uint64_t Mod = Pos & (Align - 1);
if (Mod == 0)
return 0;
return Align - Mod;
}
/// Rotate the value bit pattern to the left by shift bits.
/// Precondition: 0 <= shift < 32
static inline uint32_t rotateLeft32(uint32_t value, uint32_t shift) {
if (shift == 0)
return value;
return (value << shift) | (value >> (32 - shift));
}
/// Rotate the value bit pattern to the right by shift bits.
static inline uint32_t rotateRight32(uint32_t value, uint32_t shift) {
if (shift == 0)
return value;
return (value >> shift) | (value << (32 - shift));
}
/// Returns true if Val is +0.0. It requires T to be a floating point type.
template <typename T> static bool isPositiveZero(T Val) {
static_assert(std::is_floating_point<T>::value,
"Input type must be floating point");
return Val == 0 && !std::signbit(Val);
}
};
}
/// Return true if X is already aligned by N, where N is a power of 2.
template <typename T> static inline bool IsAligned(T X, intptr_t N) {
assert(llvm::isPowerOf2_64(N));
return (X & (N - 1)) == 0;
}
/// Return Value adjusted to the next highest multiple of Alignment.
static inline uint32_t applyAlignment(uint32_t Value, uint32_t Alignment) {
assert(llvm::isPowerOf2_32(Alignment));
return (Value + Alignment - 1) & -Alignment;
}
/// Return amount which must be added to adjust Pos to the next highest
/// multiple of Align.
static inline uint64_t OffsetToAlignment(uint64_t Pos, uint64_t Align) {
assert(llvm::isPowerOf2_64(Align));
uint64_t Mod = Pos & (Align - 1);
if (Mod == 0)
return 0;
return Align - Mod;
}
/// Rotate the value bit pattern to the left by shift bits.
/// Precondition: 0 <= shift < 32
static inline uint32_t rotateLeft32(uint32_t value, uint32_t shift) {
if (shift == 0)
return value;
return (value << shift) | (value >> (32 - shift));
}
/// Rotate the value bit pattern to the right by shift bits.
static inline uint32_t rotateRight32(uint32_t value, uint32_t shift) {
if (shift == 0)
return value;
return (value >> shift) | (value << (32 - shift));
}
/// Returns true if Val is +0.0. It requires T to be a floating point type.
template <typename T> static bool isPositiveZero(T Val) {
static_assert(std::is_floating_point<T>::value,
"Input type must be floating point");
return Val == 0 && !std::signbit(Val);
}
} // end of namespace Utils
} // end of namespace Ice
#endif // SUBZERO_SRC_ICEUTILS_H
......@@ -23,8 +23,11 @@
#include "IceInst.h"
#include "IceOperand.h"
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#endif // __clang__
#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Bitcode/NaCl/NaClBitcodeDecoders.h"
......@@ -35,8 +38,12 @@
#include "llvm/Support/Format.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/raw_ostream.h"
#include <unordered_set>
#ifdef __clang__
#pragma clang diagnostic pop
#endif // __clang__
#include <unordered_set>
// Define a hash function for SmallString's, so that it can be used in hash
// tables.
......@@ -190,7 +197,7 @@ public:
"IntType and FpType should be the same width");
assert(BitWidth == sizeof(IntType) * CHAR_BIT);
auto V = static_cast<IntType>(Val);
return reinterpret_cast<FpType &>(V);
return Ice::Utils::bitCopy<FpType>(V);
}
private:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment