]> granicus.if.org Git - llvm/commitdiff
[codeview] Fix DenseMap pointer invalidation bug
authorReid Kleckner <rnk@google.com>
Tue, 21 Jun 2016 14:56:24 +0000 (14:56 +0000)
committerReid Kleckner <rnk@google.com>
Tue, 21 Jun 2016 14:56:24 +0000 (14:56 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273268 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/AsmPrinter/CodeViewDebug.cpp

index 704f135208de7ec4641e26f7c6eb760df48f3263..62509b6ebb220fdc4f125bdcecea32690bf0518c 100644 (file)
@@ -1297,8 +1297,7 @@ void CodeViewDebug::collectMemberInfo(ClassInfo &Info,
   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(ClassInfo &Info,
 
 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();