From 75899aab3574022d3809614200521b9827f74293 Mon Sep 17 00:00:00 2001 From: Alexey Samsonov Date: Wed, 3 Sep 2014 18:11:48 +0000 Subject: [PATCH] Fix downcasts of unaligned empty/tombstone DenseMap keys for DenseMap, Foo>. Test Plan: llvm regression test suite Reviewers: chandlerc, rsmith Reviewed By: rsmith Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D4976 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217058 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/IR/ValueHandle.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/include/llvm/IR/ValueHandle.h b/include/llvm/IR/ValueHandle.h index aa29b2ed690..1371da5a6c6 100644 --- a/include/llvm/IR/ValueHandle.h +++ b/include/llvm/IR/ValueHandle.h @@ -189,6 +189,7 @@ class AssertingVH : public ValueHandleBase #endif { + friend struct DenseMapInfo >; #ifndef NDEBUG ValueTy *getValPtr() const { @@ -248,11 +249,19 @@ struct DenseMapInfo > { static unsigned getHashValue(const AssertingVH &Val) { return PointerInfo::getHashValue(Val); } +#ifndef NDEBUG + static bool isEqual(const AssertingVH &LHS, const AssertingVH &RHS) { + // Avoid downcasting AssertingVH to T*, as empty/tombstone keys may not + // be properly aligned pointers to T*. + return LHS.ValueHandleBase::getValPtr() == RHS.ValueHandleBase::getValPtr(); + } +#else static bool isEqual(const AssertingVH &LHS, const AssertingVH &RHS) { return LHS == RHS; } +#endif }; - + template struct isPodLike > { #ifdef NDEBUG