From: Reid Kleckner Date: Tue, 21 Jun 2016 14:56:24 +0000 (+0000) Subject: [codeview] Fix DenseMap pointer invalidation bug X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1582ea95a9fd2cfd152b4b5c96d9b6e676324235;p=llvm [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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273268 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp b/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp index 704f135208d..62509b6ebb2 100644 --- a/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp +++ b/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp @@ -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(Ty) && "Expects structure or union type"); - const DICompositeType *DCTy = dyn_cast(Ty); + const DICompositeType *DCTy = cast(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()}); - std::unique_ptr &Info = Insertion.first->second; - if (!Insertion.second) - return *Info; - Info.reset(new ClassInfo()); + ClassInfo *Info = nullptr; + { + std::unique_ptr &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();