diff options
Diffstat (limited to 'include/llvm/ADT/PointerEmbeddedInt.h')
-rw-r--r-- | include/llvm/ADT/PointerEmbeddedInt.h | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/include/llvm/ADT/PointerEmbeddedInt.h b/include/llvm/ADT/PointerEmbeddedInt.h index 2279d43405fa..34323b5b8af4 100644 --- a/include/llvm/ADT/PointerEmbeddedInt.h +++ b/include/llvm/ADT/PointerEmbeddedInt.h @@ -13,7 +13,10 @@ #include "llvm/ADT/DenseMapInfo.h" #include "llvm/Support/MathExtras.h" #include "llvm/Support/PointerLikeTypeTraits.h" +#include <cassert> #include <climits> +#include <cstdint> +#include <type_traits> namespace llvm { @@ -29,7 +32,7 @@ namespace llvm { /// Also, the default constructed value zero initializes the integer. template <typename IntT, int Bits = sizeof(IntT) * CHAR_BIT> class PointerEmbeddedInt { - uintptr_t Value; + uintptr_t Value = 0; // Note: This '<' is correct; using '<=' would result in some shifts // overflowing their storage types. @@ -54,15 +57,12 @@ class PointerEmbeddedInt { explicit PointerEmbeddedInt(uintptr_t Value, RawValueTag) : Value(Value) {} public: - PointerEmbeddedInt() : Value(0) {} + PointerEmbeddedInt() = default; - PointerEmbeddedInt(IntT I) { - *this = I; - } + PointerEmbeddedInt(IntT I) { *this = I; } PointerEmbeddedInt &operator=(IntT I) { - assert((std::is_signed<IntT>::value ? llvm::isInt<Bits>(I) - : llvm::isUInt<Bits>(I)) && + assert((std::is_signed<IntT>::value ? isInt<Bits>(I) : isUInt<Bits>(I)) && "Integer has bits outside those preserved!"); Value = static_cast<uintptr_t>(I) << Shift; return *this; @@ -81,15 +81,17 @@ public: // types. template <typename IntT, int Bits> class PointerLikeTypeTraits<PointerEmbeddedInt<IntT, Bits>> { - typedef PointerEmbeddedInt<IntT, Bits> T; + using T = PointerEmbeddedInt<IntT, Bits>; public: static inline void *getAsVoidPointer(const T &P) { return reinterpret_cast<void *>(P.Value); } + static inline T getFromVoidPointer(void *P) { return T(reinterpret_cast<uintptr_t>(P), typename T::RawValueTag()); } + static inline T getFromVoidPointer(const void *P) { return T(reinterpret_cast<uintptr_t>(P), typename T::RawValueTag()); } @@ -101,17 +103,19 @@ public: // itself can be a key. template <typename IntT, int Bits> struct DenseMapInfo<PointerEmbeddedInt<IntT, Bits>> { - typedef PointerEmbeddedInt<IntT, Bits> T; - - typedef DenseMapInfo<IntT> IntInfo; + using T = PointerEmbeddedInt<IntT, Bits>; + using IntInfo = DenseMapInfo<IntT>; static inline T getEmptyKey() { return IntInfo::getEmptyKey(); } static inline T getTombstoneKey() { return IntInfo::getTombstoneKey(); } + static unsigned getHashValue(const T &Arg) { return IntInfo::getHashValue(Arg); } + static bool isEqual(const T &LHS, const T &RHS) { return LHS == RHS; } }; -} -#endif +} // end namespace llvm + +#endif // LLVM_ADT_POINTEREMBEDDEDINT_H |