[PATCH] Fix -fsanitize=alignment reports on DenseMap empty/tombstone keys.

David Majnemer david.majnemer at gmail.com
Mon Dec 22 21:30:07 PST 2014


I had a similar patch here: http://reviews.llvm.org/D5428

I went with a different approach to handle global objects which were massively over-aligned (unlikely, but possible).


================
Comment at: include/llvm/ADT/DenseMapInfo.h:38-47
@@ -34,8 +37,12 @@
     uintptr_t Val = static_cast<uintptr_t>(-1);
-    Val <<= PointerLikeTypeTraits<T*>::NumLowBitsAvailable;
+    Val <<= PointerLikeTypeTraits<T *>::NumLowBitsAvailable < MaxAlignmentLog
+                ? MaxAlignmentLog
+                : PointerLikeTypeTraits<T *>::NumLowBitsAvailable;
     return reinterpret_cast<T*>(Val);
   }
   static inline T* getTombstoneKey() {
     uintptr_t Val = static_cast<uintptr_t>(-2);
-    Val <<= PointerLikeTypeTraits<T*>::NumLowBitsAvailable;
+    Val <<= PointerLikeTypeTraits<T *>::NumLowBitsAvailable < MaxAlignmentLog
+                ? MaxAlignmentLog
+                : PointerLikeTypeTraits<T *>::NumLowBitsAvailable;
     return reinterpret_cast<T*>(Val);
----------------
Would using `std::max` make this more readable?

http://reviews.llvm.org/D6768

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the llvm-commits mailing list