Don't use -1 as a value of an unsigned 7-bit enumeration; that has undefined
authorRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 20 Dec 2012 04:02:58 +0000 (04:02 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 20 Dec 2012 04:02:58 +0000 (04:02 +0000)
behavior and violates the !range constraints we put on loads of this enum.
Found by clang -fsanitize=enum.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@170653 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/DataLayout.h
lib/VMCore/DataLayout.cpp

index 4cb77663876e3a4dc71d7ed0aa28689ed2e6c2e9..cc02017189943f471a6b4942531fdb7a58bb1149 100644 (file)
@@ -39,6 +39,7 @@ class ArrayRef;
 
 /// Enum used to categorize the alignment types stored by LayoutAlignElem
 enum AlignTypeEnum {
+  INVALID_ALIGN = 0,                 ///< An invalid alignment
   INTEGER_ALIGN = 'i',               ///< Integer type alignment
   VECTOR_ALIGN = 'v',                ///< Vector type alignment
   FLOAT_ALIGN = 'f',                 ///< Floating point type alignment
index b0ac62686d105576db26962318982146771f9215..6cf51f5a4dd6ce1d778041c8d2ebc7ffef755bec 100644 (file)
@@ -118,8 +118,7 @@ LayoutAlignElem::operator==(const LayoutAlignElem &rhs) const {
 }
 
 const LayoutAlignElem
-DataLayout::InvalidAlignmentElem =
-            LayoutAlignElem::get((AlignTypeEnum) -1, 0, 0, 0);
+DataLayout::InvalidAlignmentElem = LayoutAlignElem::get(INVALID_ALIGN, 0, 0, 0);
 
 //===----------------------------------------------------------------------===//
 // PointerAlignElem, PointerAlign support