[llvm] r273268 - [codeview] Fix DenseMap pointer invalidation bug

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 21 07:56:25 PDT 2016


Author: rnk
Date: Tue Jun 21 09:56:24 2016
New Revision: 273268

URL: http://llvm.org/viewvc/llvm-project?rev=273268&view=rev
Log:
[codeview] Fix DenseMap pointer invalidation bug

When you have a map holding a unique_ptr, hold a reference to the raw
pointer instead of the unique pointer. The unique_ptr will be moved on
rehash.

Modified:
    llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp?rev=273268&r1=273267&r2=273268&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp Tue Jun 21 09:56:24 2016
@@ -1297,8 +1297,7 @@ void CodeViewDebug::collectMemberInfo(Cl
   assert((DDTy->getOffsetInBits() % 8) == 0 && "Unnamed bitfield member!");
   unsigned offset = DDTy->getOffsetInBits() / 8;
   const DIType *Ty = DDTy->getBaseType().resolve();
-  assert(dyn_cast<DICompositeType>(Ty) && "Expects structure or union type");
-  const DICompositeType *DCTy = dyn_cast<DICompositeType>(Ty);
+  const DICompositeType *DCTy = cast<DICompositeType>(Ty);
   ClassInfo &NestedInfo = collectClassInfo(DCTy);
   ClassInfo::MemberList &Members = NestedInfo.Members;
   for (unsigned i = 0, e = Members.size(); i != e; ++i)
@@ -1308,10 +1307,14 @@ void CodeViewDebug::collectMemberInfo(Cl
 
 ClassInfo &CodeViewDebug::collectClassInfo(const DICompositeType *Ty) {
   auto Insertion = ClassInfoMap.insert({Ty, std::unique_ptr<ClassInfo>()});
-  std::unique_ptr<ClassInfo> &Info = Insertion.first->second;
-  if (!Insertion.second)
-    return *Info;
-  Info.reset(new ClassInfo());
+  ClassInfo *Info = nullptr;
+  {
+    std::unique_ptr<ClassInfo> &InfoEntry = Insertion.first->second;
+    if (!Insertion.second)
+      return *InfoEntry;
+    InfoEntry.reset(new ClassInfo());
+    Info = InfoEntry.get();
+  }
 
   // Add elements to structure type.
   DINodeArray Elements = Ty->getElements();




More information about the llvm-commits mailing list