From f341a47d10501bc69b5d4d2217992bb6e08668d8 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 29 Mar 2009 06:33:22 +0000 Subject: [PATCH] When forming sentinels for empty/tombstone, make sure to respect the pointer's expected number of zero low-bits. This should fix the breakage I introduced recently. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@67990 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ADT/DenseMap.h | 14 +++++++++++--- include/llvm/ADT/PointerIntPair.h | 9 ++++++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/include/llvm/ADT/DenseMap.h b/include/llvm/ADT/DenseMap.h index 9a66c8b6c11..c0f8cee5984 100644 --- a/include/llvm/ADT/DenseMap.h +++ b/include/llvm/ADT/DenseMap.h @@ -14,7 +14,7 @@ #ifndef LLVM_ADT_DENSEMAP_H #define LLVM_ADT_DENSEMAP_H -#include "llvm/Support/DataTypes.h" +#include "llvm/Support/PointerLikeTypeTraits.h" #include "llvm/Support/MathExtras.h" #include #include @@ -33,8 +33,16 @@ struct DenseMapInfo { // Provide DenseMapInfo for all pointers. template struct DenseMapInfo { - static inline T* getEmptyKey() { return reinterpret_cast(-1); } - static inline T* getTombstoneKey() { return reinterpret_cast(-2); } + static inline T* getEmptyKey() { + intptr_t Val = -1; + Val <<= PointerLikeTypeTraits::NumLowBitsAvailable; + return reinterpret_cast(Val); + } + static inline T* getTombstoneKey() { + intptr_t Val = -2; + Val <<= PointerLikeTypeTraits::NumLowBitsAvailable; + return reinterpret_cast(Val); + } static unsigned getHashValue(const T *PtrVal) { return (unsigned((uintptr_t)PtrVal) >> 4) ^ (unsigned((uintptr_t)PtrVal) >> 9); diff --git a/include/llvm/ADT/PointerIntPair.h b/include/llvm/ADT/PointerIntPair.h index f189a328582..51a0c77fdca 100644 --- a/include/llvm/ADT/PointerIntPair.h +++ b/include/llvm/ADT/PointerIntPair.h @@ -107,11 +107,14 @@ template struct DenseMapInfo > { typedef PointerIntPair Ty; static Ty getEmptyKey() { - return Ty(reinterpret_cast(-1 << IntBits), - IntType((1 << IntBits)-1)); + intptr_t Val = -1; + Val <<= PointerLikeTypeTraits::NumLowBitsAvailable; + return Ty(reinterpret_cast(Val), IntType((1 << IntBits)-1)); } static Ty getTombstoneKey() { - return Ty(reinterpret_cast(-2 << IntBits), IntType(0)); + intptr_t Val = -2; + Val <<= PointerLikeTypeTraits::NumLowBitsAvailable; + return Ty(reinterpret_cast(Val), IntType(0)); } static unsigned getHashValue(Ty V) { uintptr_t IV = reinterpret_cast(V.getOpaqueValue()); -- 2.34.1