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

Chandler Carruth chandlerc at gmail.com
Mon Dec 22 20:13:34 PST 2014


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.
On Dec 22, 2014 7:56 PM, "Alexey Samsonov" <vonosmas at gmail.com> wrote:

> Hi chandlerc, rsmith,
>
> Use large alignment when calculating empty/tombstone keys
> for T*. We can't use alignof(T), as T may be forward-declared at
> this point, and PointerLikeTypeTraits<T*>::NumLowBitsAvailable may
> be too small.
>
> http://reviews.llvm.org/D6768
>
> Files:
>   include/llvm/ADT/DenseMapInfo.h
>
> 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<typename T>
>  struct DenseMapInfo<T*> {
> +  // 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<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);
>    }
>    static unsigned getHashValue(const T *PtrVal) {
>
> EMAIL PREFERENCES
>   http://reviews.llvm.org/settings/panel/emailpreferences/
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141222/e9ade4fd/attachment.html>


More information about the llvm-commits mailing list