Index: include/llvm/ADT/DenseMapInfo.h =================================================================== --- include/llvm/ADT/DenseMapInfo.h +++ include/llvm/ADT/DenseMapInfo.h @@ -30,14 +30,21 @@ // Provide DenseMapInfo for all pointers. template struct DenseMapInfo { + // Objects of types T may require large alignment, which we might not know (if + // T is forward-declared). Generate empty/tombstone keys to account for that. + enum { MaxAlignmentLog = 5 }; static inline T* getEmptyKey() { uintptr_t Val = static_cast(-1); - Val <<= PointerLikeTypeTraits::NumLowBitsAvailable; + Val <<= PointerLikeTypeTraits::NumLowBitsAvailable < MaxAlignmentLog + ? MaxAlignmentLog + : PointerLikeTypeTraits::NumLowBitsAvailable; return reinterpret_cast(Val); } static inline T* getTombstoneKey() { uintptr_t Val = static_cast(-2); - Val <<= PointerLikeTypeTraits::NumLowBitsAvailable; + Val <<= PointerLikeTypeTraits::NumLowBitsAvailable < MaxAlignmentLog + ? MaxAlignmentLog + : PointerLikeTypeTraits::NumLowBitsAvailable; return reinterpret_cast(Val); } static unsigned getHashValue(const T *PtrVal) {