[llvm] r320750 - Fix many -Wsign-compare and -Wtautological-constant-compare warnings.

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 14 14:07:04 PST 2017


Author: zturner
Date: Thu Dec 14 14:07:03 2017
New Revision: 320750

URL: http://llvm.org/viewvc/llvm-project?rev=320750&view=rev
Log:
Fix many -Wsign-compare and -Wtautological-constant-compare warnings.

Most of the -Wsign-compare warnings are due to the fact that
enums are signed by default in the MS ABI, while the
tautological comparison warnings trigger on x86 builds where
sizeof(size_t) is 4 bytes, so N > numeric_limits<unsigned>::max()
is always false.

Differential Revision: https://reviews.llvm.org/D41256

Modified:
    llvm/trunk/include/llvm/BinaryFormat/COFF.h
    llvm/trunk/include/llvm/Object/COFF.h
    llvm/trunk/include/llvm/Object/ELFObjectFile.h
    llvm/trunk/include/llvm/Object/MachO.h
    llvm/trunk/include/llvm/Object/ObjectFile.h
    llvm/trunk/include/llvm/Object/RelocVisitor.h
    llvm/trunk/include/llvm/Object/Wasm.h
    llvm/trunk/lib/Analysis/InstructionSimplify.cpp
    llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
    llvm/trunk/lib/Object/COFFObjectFile.cpp
    llvm/trunk/lib/Object/MachOObjectFile.cpp
    llvm/trunk/lib/Object/WasmObjectFile.cpp
    llvm/trunk/lib/ProfileData/InstrProfReader.cpp
    llvm/trunk/lib/ProfileData/SampleProfReader.cpp
    llvm/trunk/lib/Support/ARMAttributeParser.cpp
    llvm/trunk/lib/Target/X86/X86ISelLowering.cpp

Modified: llvm/trunk/include/llvm/BinaryFormat/COFF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/BinaryFormat/COFF.h?rev=320750&r1=320749&r2=320750&view=diff
==============================================================================
--- llvm/trunk/include/llvm/BinaryFormat/COFF.h (original)
+++ llvm/trunk/include/llvm/BinaryFormat/COFF.h Thu Dec 14 14:07:03 2017
@@ -91,7 +91,7 @@ struct BigObjHeader {
   uint32_t NumberOfSymbols;
 };
 
-enum MachineTypes {
+enum MachineTypes : unsigned {
   MT_Invalid = 0xffff,
 
   IMAGE_FILE_MACHINE_UNKNOWN = 0x0,
@@ -118,7 +118,7 @@ enum MachineTypes {
   IMAGE_FILE_MACHINE_WCEMIPSV2 = 0x169
 };
 
-enum Characteristics {
+enum Characteristics : unsigned {
   C_Invalid = 0,
 
   /// The file does not contain base relocations and must be loaded at its
@@ -158,7 +158,7 @@ enum Characteristics {
   IMAGE_FILE_BYTES_REVERSED_HI = 0x8000
 };
 
-enum ResourceTypeID {
+enum ResourceTypeID : unsigned {
   RID_Cursor = 1,
   RID_Bitmap = 2,
   RID_Icon = 3,
@@ -234,7 +234,7 @@ enum SymbolStorageClass {
   IMAGE_SYM_CLASS_CLR_TOKEN = 107
 };
 
-enum SymbolBaseType {
+enum SymbolBaseType : unsigned {
   IMAGE_SYM_TYPE_NULL = 0,   ///< No type information or unknown base type.
   IMAGE_SYM_TYPE_VOID = 1,   ///< Used with void pointers and functions.
   IMAGE_SYM_TYPE_CHAR = 2,   ///< A character (signed byte).
@@ -253,7 +253,7 @@ enum SymbolBaseType {
   IMAGE_SYM_TYPE_DWORD = 15  ///< An unsigned 4-byte integer.
 };
 
-enum SymbolComplexType {
+enum SymbolComplexType : unsigned {
   IMAGE_SYM_DTYPE_NULL = 0,     ///< No complex type; simple scalar variable.
   IMAGE_SYM_DTYPE_POINTER = 1,  ///< A pointer to base type.
   IMAGE_SYM_DTYPE_FUNCTION = 2, ///< A function that returns a base type.
@@ -325,7 +325,7 @@ struct relocation {
   uint16_t Type;
 };
 
-enum RelocationTypeI386 {
+enum RelocationTypeI386 : unsigned {
   IMAGE_REL_I386_ABSOLUTE = 0x0000,
   IMAGE_REL_I386_DIR16 = 0x0001,
   IMAGE_REL_I386_REL16 = 0x0002,
@@ -339,7 +339,7 @@ enum RelocationTypeI386 {
   IMAGE_REL_I386_REL32 = 0x0014
 };
 
-enum RelocationTypeAMD64 {
+enum RelocationTypeAMD64 : unsigned {
   IMAGE_REL_AMD64_ABSOLUTE = 0x0000,
   IMAGE_REL_AMD64_ADDR64 = 0x0001,
   IMAGE_REL_AMD64_ADDR32 = 0x0002,
@@ -359,7 +359,7 @@ enum RelocationTypeAMD64 {
   IMAGE_REL_AMD64_SSPAN32 = 0x0010
 };
 
-enum RelocationTypesARM {
+enum RelocationTypesARM : unsigned {
   IMAGE_REL_ARM_ABSOLUTE = 0x0000,
   IMAGE_REL_ARM_ADDR32 = 0x0001,
   IMAGE_REL_ARM_ADDR32NB = 0x0002,
@@ -377,7 +377,7 @@ enum RelocationTypesARM {
   IMAGE_REL_ARM_BLX23T = 0x0015
 };
 
-enum RelocationTypesARM64 {
+enum RelocationTypesARM64 : unsigned {
   IMAGE_REL_ARM64_ABSOLUTE = 0x0000,
   IMAGE_REL_ARM64_ADDR32 = 0x0001,
   IMAGE_REL_ARM64_ADDR32NB = 0x0002,
@@ -397,7 +397,7 @@ enum RelocationTypesARM64 {
   IMAGE_REL_ARM64_BRANCH14 = 0x0010,
 };
 
-enum COMDATType {
+enum COMDATType : unsigned {
   IMAGE_COMDAT_SELECT_NODUPLICATES = 1,
   IMAGE_COMDAT_SELECT_ANY,
   IMAGE_COMDAT_SELECT_SAME_SIZE,
@@ -430,7 +430,7 @@ struct AuxiliaryWeakExternal {
   uint8_t unused[10];
 };
 
-enum WeakExternalCharacteristics {
+enum WeakExternalCharacteristics : unsigned {
   IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY = 1,
   IMAGE_WEAK_EXTERN_SEARCH_LIBRARY = 2,
   IMAGE_WEAK_EXTERN_SEARCH_ALIAS = 3
@@ -572,7 +572,7 @@ struct DataDirectory {
   uint32_t Size;
 };
 
-enum DataDirectoryIndex {
+enum DataDirectoryIndex : unsigned {
   EXPORT_TABLE = 0,
   IMPORT_TABLE,
   RESOURCE_TABLE,
@@ -592,7 +592,7 @@ enum DataDirectoryIndex {
   NUM_DATA_DIRECTORIES
 };
 
-enum WindowsSubsystem {
+enum WindowsSubsystem : unsigned {
   IMAGE_SUBSYSTEM_UNKNOWN = 0, ///< An unknown subsystem.
   IMAGE_SUBSYSTEM_NATIVE = 1,  ///< Device drivers and native Windows processes
   IMAGE_SUBSYSTEM_WINDOWS_GUI = 2,      ///< The Windows GUI subsystem.
@@ -611,7 +611,7 @@ enum WindowsSubsystem {
   IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION = 16 ///< A BCD application.
 };
 
-enum DLLCharacteristics {
+enum DLLCharacteristics : unsigned {
   /// ASLR with 64 bit address space.
   IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA = 0x0020,
   /// DLL can be relocated at load time.
@@ -637,7 +637,7 @@ enum DLLCharacteristics {
   IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE = 0x8000
 };
 
-enum DebugType {
+enum DebugType : unsigned {
   IMAGE_DEBUG_TYPE_UNKNOWN = 0,
   IMAGE_DEBUG_TYPE_COFF = 1,
   IMAGE_DEBUG_TYPE_CODEVIEW = 2,
@@ -657,7 +657,7 @@ enum DebugType {
   IMAGE_DEBUG_TYPE_REPRO = 16,
 };
 
-enum BaseRelocationType {
+enum BaseRelocationType : unsigned {
   IMAGE_REL_BASED_ABSOLUTE = 0,
   IMAGE_REL_BASED_HIGH = 1,
   IMAGE_REL_BASED_LOW = 2,
@@ -670,9 +670,13 @@ enum BaseRelocationType {
   IMAGE_REL_BASED_DIR64 = 10
 };
 
-enum ImportType { IMPORT_CODE = 0, IMPORT_DATA = 1, IMPORT_CONST = 2 };
+enum ImportType : unsigned {
+  IMPORT_CODE = 0,
+  IMPORT_DATA = 1,
+  IMPORT_CONST = 2
+};
 
-enum ImportNameType {
+enum ImportNameType : unsigned {
   /// Import is by ordinal. This indicates that the value in the Ordinal/Hint
   /// field of the import header is the import's ordinal. If this constant is
   /// not specified, then the Ordinal/Hint field should always be interpreted

Modified: llvm/trunk/include/llvm/Object/COFF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/COFF.h?rev=320750&r1=320749&r2=320750&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/COFF.h (original)
+++ llvm/trunk/include/llvm/Object/COFF.h Thu Dec 14 14:07:03 2017
@@ -926,7 +926,7 @@ public:
 
   uint8_t getBytesInAddress() const override;
   StringRef getFileFormatName() const override;
-  unsigned getArch() const override;
+  Triple::ArchType getArch() const override;
   SubtargetFeatures getFeatures() const override { return SubtargetFeatures(); }
 
   import_directory_iterator import_directory_begin() const;

Modified: llvm/trunk/include/llvm/Object/ELFObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ELFObjectFile.h?rev=320750&r1=320749&r2=320750&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ELFObjectFile.h (original)
+++ llvm/trunk/include/llvm/Object/ELFObjectFile.h Thu Dec 14 14:07:03 2017
@@ -362,7 +362,7 @@ public:
 
   uint8_t getBytesInAddress() const override;
   StringRef getFileFormatName() const override;
-  unsigned getArch() const override;
+  Triple::ArchType getArch() const override;
 
   std::error_code getPlatformFlags(unsigned &Result) const override {
     Result = EF.getHeader()->e_flags;
@@ -1026,8 +1026,7 @@ StringRef ELFObjectFile<ELFT>::getFileFo
   }
 }
 
-template <class ELFT>
-unsigned ELFObjectFile<ELFT>::getArch() const {
+template <class ELFT> Triple::ArchType ELFObjectFile<ELFT>::getArch() const {
   bool IsLittleEndian = ELFT::TargetEndianness == support::little;
   switch (EF.getHeader()->e_machine) {
   case ELF::EM_386:

Modified: llvm/trunk/include/llvm/Object/MachO.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/MachO.h?rev=320750&r1=320749&r2=320750&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/MachO.h (original)
+++ llvm/trunk/include/llvm/Object/MachO.h Thu Dec 14 14:07:03 2017
@@ -360,7 +360,7 @@ public:
   uint8_t getBytesInAddress() const override;
 
   StringRef getFileFormatName() const override;
-  unsigned getArch() const override;
+  Triple::ArchType getArch() const override;
   SubtargetFeatures getFeatures() const override { return SubtargetFeatures(); }
   Triple getArchTriple(const char **McpuDefault = nullptr) const;
 

Modified: llvm/trunk/include/llvm/Object/ObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ObjectFile.h?rev=320750&r1=320749&r2=320750&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ObjectFile.h (original)
+++ llvm/trunk/include/llvm/Object/ObjectFile.h Thu Dec 14 14:07:03 2017
@@ -15,6 +15,7 @@
 #define LLVM_OBJECT_OBJECTFILE_H
 
 #include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Triple.h"
 #include "llvm/ADT/iterator_range.h"
 #include "llvm/BinaryFormat/Magic.h"
 #include "llvm/MC/SubtargetFeature.h"
@@ -279,7 +280,7 @@ public:
   virtual uint8_t getBytesInAddress() const = 0;
 
   virtual StringRef getFileFormatName() const = 0;
-  virtual /* Triple::ArchType */ unsigned getArch() const = 0;
+  virtual Triple::ArchType getArch() const = 0;
   virtual SubtargetFeatures getFeatures() const = 0;
   virtual void setARMSubArch(Triple &TheTriple) const { }
 

Modified: llvm/trunk/include/llvm/Object/RelocVisitor.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/RelocVisitor.h?rev=320750&r1=320749&r2=320750&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/RelocVisitor.h (original)
+++ llvm/trunk/include/llvm/Object/RelocVisitor.h Thu Dec 14 14:07:03 2017
@@ -302,6 +302,8 @@ private:
         return Value;
       }
       break;
+    default:
+      break;
     }
     HasError = true;
     return 0;

Modified: llvm/trunk/include/llvm/Object/Wasm.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/Wasm.h?rev=320750&r1=320749&r2=320750&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/Wasm.h (original)
+++ llvm/trunk/include/llvm/Object/Wasm.h Thu Dec 14 14:07:03 2017
@@ -201,7 +201,7 @@ public:
   section_iterator section_end() const override;
   uint8_t getBytesInAddress() const override;
   StringRef getFileFormatName() const override;
-  unsigned getArch() const override;
+  Triple::ArchType getArch() const override;
   SubtargetFeatures getFeatures() const override;
   bool isRelocatableObject() const override;
 

Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=320750&r1=320749&r2=320750&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Thu Dec 14 14:07:03 2017
@@ -327,7 +327,7 @@ static Value *ThreadBinOpOverSelect(Inst
     // Check that the simplified value has the form "X op Y" where "op" is the
     // same as the original operation.
     Instruction *Simplified = dyn_cast<Instruction>(FV ? FV : TV);
-    if (Simplified && Simplified->getOpcode() == Opcode) {
+    if (Simplified && Simplified->getOpcode() == unsigned(Opcode)) {
       // The value that didn't simplify is "UnsimplifiedLHS op UnsimplifiedRHS".
       // We already know that "op" is the same as for the simplified value.  See
       // if the operands match too.  If so, return the simplified value.

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp?rev=320750&r1=320749&r2=320750&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp Thu Dec 14 14:07:03 2017
@@ -1769,7 +1769,7 @@ void SelectionDAGBuilder::FindMergedCond
 
   // If this node is not part of the or/and tree, emit it as a branch.
   if (!BOp || !(isa<BinaryOperator>(BOp) || isa<CmpInst>(BOp)) ||
-      BOpc != Opc || !BOp->hasOneUse() ||
+      BOpc != unsigned(Opc) || !BOp->hasOneUse() ||
       BOp->getParent() != CurBB->getBasicBlock() ||
       !InBlock(BOp->getOperand(0), CurBB->getBasicBlock()) ||
       !InBlock(BOp->getOperand(1), CurBB->getBasicBlock())) {

Modified: llvm/trunk/lib/Object/COFFObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/COFFObjectFile.cpp?rev=320750&r1=320749&r2=320750&view=diff
==============================================================================
--- llvm/trunk/lib/Object/COFFObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/COFFObjectFile.cpp Thu Dec 14 14:07:03 2017
@@ -895,7 +895,7 @@ StringRef COFFObjectFile::getFileFormatN
   }
 }
 
-unsigned COFFObjectFile::getArch() const {
+Triple::ArchType COFFObjectFile::getArch() const {
   switch (getMachine()) {
   case COFF::IMAGE_FILE_MACHINE_I386:
     return Triple::x86;

Modified: llvm/trunk/lib/Object/MachOObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/MachOObjectFile.cpp?rev=320750&r1=320749&r2=320750&view=diff
==============================================================================
--- llvm/trunk/lib/Object/MachOObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/MachOObjectFile.cpp Thu Dec 14 14:07:03 2017
@@ -2573,7 +2573,7 @@ bool MachOObjectFile::isValidArch(String
       .Default(false);
 }
 
-unsigned MachOObjectFile::getArch() const {
+Triple::ArchType MachOObjectFile::getArch() const {
   return getArch(getCPUType(*this));
 }
 

Modified: llvm/trunk/lib/Object/WasmObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/WasmObjectFile.cpp?rev=320750&r1=320749&r2=320750&view=diff
==============================================================================
--- llvm/trunk/lib/Object/WasmObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/WasmObjectFile.cpp Thu Dec 14 14:07:03 2017
@@ -1038,7 +1038,7 @@ uint8_t WasmObjectFile::getBytesInAddres
 
 StringRef WasmObjectFile::getFileFormatName() const { return "WASM"; }
 
-unsigned WasmObjectFile::getArch() const { return Triple::wasm32; }
+Triple::ArchType WasmObjectFile::getArch() const { return Triple::wasm32; }
 
 SubtargetFeatures WasmObjectFile::getFeatures() const {
   return SubtargetFeatures();

Modified: llvm/trunk/lib/ProfileData/InstrProfReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProfReader.cpp?rev=320750&r1=320749&r2=320750&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/InstrProfReader.cpp (original)
+++ llvm/trunk/lib/ProfileData/InstrProfReader.cpp Thu Dec 14 14:07:03 2017
@@ -61,7 +61,7 @@ InstrProfReader::create(const Twine &Pat
 Expected<std::unique_ptr<InstrProfReader>>
 InstrProfReader::create(std::unique_ptr<MemoryBuffer> Buffer) {
   // Sanity check the buffer.
-  if (Buffer->getBufferSize() > std::numeric_limits<unsigned>::max())
+  if (uint64_t(Buffer->getBufferSize()) > std::numeric_limits<unsigned>::max())
     return make_error<InstrProfError>(instrprof_error::too_large);
 
   if (Buffer->getBufferSize() == 0)
@@ -99,7 +99,7 @@ IndexedInstrProfReader::create(const Twi
 Expected<std::unique_ptr<IndexedInstrProfReader>>
 IndexedInstrProfReader::create(std::unique_ptr<MemoryBuffer> Buffer) {
   // Sanity check the buffer.
-  if (Buffer->getBufferSize() > std::numeric_limits<unsigned>::max())
+  if (uint64_t(Buffer->getBufferSize()) > std::numeric_limits<unsigned>::max())
     return make_error<InstrProfError>(instrprof_error::too_large);
 
   // Create the reader.

Modified: llvm/trunk/lib/ProfileData/SampleProfReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/SampleProfReader.cpp?rev=320750&r1=320749&r2=320750&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/SampleProfReader.cpp (original)
+++ llvm/trunk/lib/ProfileData/SampleProfReader.cpp Thu Dec 14 14:07:03 2017
@@ -749,7 +749,7 @@ setupMemoryBuffer(const Twine &Filename)
   auto Buffer = std::move(BufferOrErr.get());
 
   // Sanity check the file.
-  if (Buffer->getBufferSize() > std::numeric_limits<uint32_t>::max())
+  if (uint64_t(Buffer->getBufferSize()) > std::numeric_limits<uint32_t>::max())
     return sampleprof_error::too_large;
 
   return std::move(Buffer);

Modified: llvm/trunk/lib/Support/ARMAttributeParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/ARMAttributeParser.cpp?rev=320750&r1=320749&r2=320750&view=diff
==============================================================================
--- llvm/trunk/lib/Support/ARMAttributeParser.cpp (original)
+++ llvm/trunk/lib/Support/ARMAttributeParser.cpp Thu Dec 14 14:07:03 2017
@@ -592,7 +592,7 @@ void ARMAttributeParser::ParseAttributeL
     bool Handled = false;
     for (unsigned AHI = 0, AHE = array_lengthof(DisplayRoutines);
          AHI != AHE && !Handled; ++AHI) {
-      if (DisplayRoutines[AHI].Attribute == Tag) {
+      if (uint64_t(DisplayRoutines[AHI].Attribute) == Tag) {
         (this->*DisplayRoutines[AHI].Routine)(ARMBuildAttrs::AttrType(Tag),
                                               Data, Offset);
         Handled = true;

Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=320750&r1=320749&r2=320750&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Thu Dec 14 14:07:03 2017
@@ -30276,7 +30276,7 @@ static SDValue matchBinOpReduction(SDNod
 
   // Match against one of the candidate binary ops.
   if (llvm::none_of(CandidateBinOps, [Op](ISD::NodeType BinOp) {
-        return Op.getOpcode() == BinOp;
+        return Op.getOpcode() == unsigned(BinOp);
       }))
     return SDValue();
 




More information about the llvm-commits mailing list