aboutsummaryrefslogtreecommitdiffstats
path: root/include/llvm
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-03-29 06:33:22 +0000
committerChris Lattner <sabre@nondot.org>2009-03-29 06:33:22 +0000
commitc913e7242f319846697339610fb4f66512b1d669 (patch)
tree6702eb7be774f82108aa5fdfd22acdf9b44d5488 /include/llvm
parent37168f4fd66ebe639aa2a321b66864d99134986f (diff)
downloadexternal_llvm-c913e7242f319846697339610fb4f66512b1d669.zip
external_llvm-c913e7242f319846697339610fb4f66512b1d669.tar.gz
external_llvm-c913e7242f319846697339610fb4f66512b1d669.tar.bz2
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
Diffstat (limited to 'include/llvm')
-rw-r--r--include/llvm/ADT/DenseMap.h14
-rw-r--r--include/llvm/ADT/PointerIntPair.h9
2 files changed, 17 insertions, 6 deletions
diff --git a/include/llvm/ADT/DenseMap.h b/include/llvm/ADT/DenseMap.h
index 9a66c8b..c0f8cee 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 <cassert>
#include <utility>
@@ -33,8 +33,16 @@ struct DenseMapInfo {
// Provide DenseMapInfo for all pointers.
template<typename T>
struct DenseMapInfo<T*> {
- static inline T* getEmptyKey() { return reinterpret_cast<T*>(-1); }
- static inline T* getTombstoneKey() { return reinterpret_cast<T*>(-2); }
+ static inline T* getEmptyKey() {
+ intptr_t Val = -1;
+ Val <<= PointerLikeTypeTraits<T*>::NumLowBitsAvailable;
+ return reinterpret_cast<T*>(Val);
+ }
+ static inline T* getTombstoneKey() {
+ intptr_t Val = -2;
+ Val <<= PointerLikeTypeTraits<T*>::NumLowBitsAvailable;
+ return reinterpret_cast<T*>(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 f189a32..51a0c77 100644
--- a/include/llvm/ADT/PointerIntPair.h
+++ b/include/llvm/ADT/PointerIntPair.h
@@ -107,11 +107,14 @@ template<typename PointerTy, unsigned IntBits, typename IntType>
struct DenseMapInfo<PointerIntPair<PointerTy, IntBits, IntType> > {
typedef PointerIntPair<PointerTy, IntBits, IntType> Ty;
static Ty getEmptyKey() {
- return Ty(reinterpret_cast<PointerTy>(-1 << IntBits),
- IntType((1 << IntBits)-1));
+ intptr_t Val = -1;
+ Val <<= PointerLikeTypeTraits<PointerTy>::NumLowBitsAvailable;
+ return Ty(reinterpret_cast<PointerTy>(Val), IntType((1 << IntBits)-1));
}
static Ty getTombstoneKey() {
- return Ty(reinterpret_cast<PointerTy>(-2 << IntBits), IntType(0));
+ intptr_t Val = -2;
+ Val <<= PointerLikeTypeTraits<PointerTy>::NumLowBitsAvailable;
+ return Ty(reinterpret_cast<PointerTy>(Val), IntType(0));
}
static unsigned getHashValue(Ty V) {
uintptr_t IV = reinterpret_cast<uintptr_t>(V.getOpaqueValue());