[llvm-commits] [llvm] r171614 - in /llvm/trunk: include/llvm/IR/Attributes.h lib/IR/Attributes.cpp

Chandler Carruth chandlerc at gmail.com
Sat Jan 5 00:47:26 PST 2013


Author: chandlerc
Date: Sat Jan  5 02:47:26 2013
New Revision: 171614

URL: http://llvm.org/viewvc/llvm-project?rev=171614&view=rev
Log:
Switch the empty and tombstone key enumerators to not have explicit
values -- that's not required to fix the bug that was cropping up, and
the values selected made the enumeration's underlying type signed and
introduced some warnings. This fixes the -Werror build.

The underlying issue here was that the DenseMapInfo was casting values
completely outside the range of the underlying storage of the
enumeration to the enumeration's type. GCC went and "optimized" that
into infloops and other misbehavior. By providing designated special
values for these keys in the dense map, we ensure they are indeed
representable and that they won't be used for anything else.

It might be better to reuse None for the empty key and have the
tombstone share the value of the sentinel enumerator, but honestly
having 2 extra enumerators seemed not to matter and this seems a bit
simpler. I'll let Bill shuffle this around (or ask me to shuffle it
around) if he prefers it to look a different way.

I also made the switch a bit more clear (and produce a better assert)
that the enumerators are *never* going to show up and are errors if they
do.

Modified:
    llvm/trunk/include/llvm/IR/Attributes.h
    llvm/trunk/lib/IR/Attributes.cpp

Modified: llvm/trunk/include/llvm/IR/Attributes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Attributes.h?rev=171614&r1=171613&r2=171614&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Attributes.h (original)
+++ llvm/trunk/include/llvm/IR/Attributes.h Sat Jan  5 02:47:26 2013
@@ -95,9 +95,8 @@
 
     EndAttrKinds,          ///< Sentinal value useful for loops
 
-    // Values for DenseMapInfo
-    EmptyKey     = 0x7FFFFFFF,
-    TombstoneKey = -0x7FFFFFFF - 1
+    AttrKindEmptyKey,      ///< Empty key value for DenseMapInfo
+    AttrKindTombstoneKey   ///< Tombstone key value for DenseMapInfo
   };
 private:
   AttributeImpl *pImpl;
@@ -169,10 +168,10 @@
 /// AttrBuilder.
 template<> struct DenseMapInfo<Attribute::AttrKind> {
   static inline Attribute::AttrKind getEmptyKey() {
-    return Attribute::EmptyKey;
+    return Attribute::AttrKindEmptyKey;
   }
   static inline Attribute::AttrKind getTombstoneKey() {
-    return Attribute::TombstoneKey;
+    return Attribute::AttrKindTombstoneKey;
   }
   static unsigned getHashValue(const Attribute::AttrKind &Val) {
     return Val * 37U;

Modified: llvm/trunk/lib/IR/Attributes.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Attributes.cpp?rev=171614&r1=171613&r2=171614&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Attributes.cpp (original)
+++ llvm/trunk/lib/IR/Attributes.cpp Sat Jan  5 02:47:26 2013
@@ -425,9 +425,11 @@
 
 uint64_t AttributeImpl::getAttrMask(Attribute::AttrKind Val) {
   switch (Val) {
-  case Attribute::EndAttrKinds:    break;
-  case Attribute::EmptyKey:        break;
-  case Attribute::TombstoneKey:    break;
+  case Attribute::EndAttrKinds:
+  case Attribute::AttrKindEmptyKey:
+  case Attribute::AttrKindTombstoneKey:
+    llvm_unreachable("Synthetic enumerators which should never get here");
+
   case Attribute::None:            return 0;
   case Attribute::ZExt:            return 1 << 0;
   case Attribute::SExt:            return 1 << 1;





More information about the llvm-commits mailing list