[PATCH] Fix -fsanitize=alignment reports on DenseMap empty/tombstone keys.
Alexey Samsonov
vonosmas at gmail.com
Mon Dec 22 21:35:45 PST 2014
In http://reviews.llvm.org/D6768#103892, @chandlerc wrote:
> I'm curious why we need to support forward declared types. It seems really
> brittle. Have you looked into this much? If not, I can.
If your class has a member `llvm::DenseMap<llvm::AllocaInst *, Foo>`, it's a common practice to forward-declare llvm::AllocaInst.
In http://reviews.llvm.org/D6768#103896, @majnemer wrote:
> 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).
Right, your patch looks slightly better. I'd be happy to see either of these commited :)
================
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);
----------------
majnemer wrote:
> Would using `std::max` make this more readable?
This header is included by almost every LLVM source. I didn't want to #include <algorithm> here.
http://reviews.llvm.org/D6768
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
More information about the llvm-commits
mailing list