[llvm] r217058 - Fix downcasts of unaligned empty/tombstone DenseMap keys for DenseMap<AssertVH<T>, Foo>.

Alexey Samsonov vonosmas at gmail.com
Wed Sep 3 11:11:48 PDT 2014


Author: samsonov
Date: Wed Sep  3 13:11:48 2014
New Revision: 217058

URL: http://llvm.org/viewvc/llvm-project?rev=217058&view=rev
Log:
Fix downcasts of unaligned empty/tombstone DenseMap keys for DenseMap<AssertVH<T>, Foo>.

Test Plan: llvm regression test suite

Reviewers: chandlerc, rsmith

Reviewed By: rsmith

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D4976

Modified:
    llvm/trunk/include/llvm/IR/ValueHandle.h

Modified: llvm/trunk/include/llvm/IR/ValueHandle.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/ValueHandle.h?rev=217058&r1=217057&r2=217058&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/ValueHandle.h (original)
+++ llvm/trunk/include/llvm/IR/ValueHandle.h Wed Sep  3 13:11:48 2014
@@ -189,6 +189,7 @@ class AssertingVH
   : public ValueHandleBase
 #endif
   {
+  friend struct DenseMapInfo<AssertingVH<ValueTy> >;
 
 #ifndef NDEBUG
   ValueTy *getValPtr() const {
@@ -248,11 +249,19 @@ struct DenseMapInfo<AssertingVH<T> > {
   static unsigned getHashValue(const AssertingVH<T> &Val) {
     return PointerInfo::getHashValue(Val);
   }
+#ifndef NDEBUG
+  static bool isEqual(const AssertingVH<T> &LHS, const AssertingVH<T> &RHS) {
+    // Avoid downcasting AssertingVH<T> 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<T> &LHS, const AssertingVH<T> &RHS) {
     return LHS == RHS;
   }
+#endif
 };
-  
+
 template <typename T>
 struct isPodLike<AssertingVH<T> > {
 #ifdef NDEBUG





More information about the llvm-commits mailing list