From 0adbc97362f090b05f50b1438de7b2dd724a4af0 Mon Sep 17 00:00:00 2001 From: NAKAMURA Takumi Date: Sun, 30 Jul 2017 05:06:26 +0000 Subject: [PATCH] CodeGenModule.cpp: [PR33810][Modules] Avoid reusing FoundStr to try to fix crash. MangledDeclNames might grow up and be reallocated when it were reused by reentering CodeGenModule::getMangledName(). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@309501 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenModule.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 63d5ff3bee..310b19c209 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -712,9 +712,9 @@ StringRef CodeGenModule::getMangledName(GlobalDecl GD) { } } - StringRef &FoundStr = MangledDeclNames[CanonicalGD]; - if (!FoundStr.empty()) - return FoundStr; + auto FoundName = MangledDeclNames.find(CanonicalGD); + if (FoundName != MangledDeclNames.end()) + return FoundName->second; const auto *ND = cast(GD.getDecl()); SmallString<256> Buffer; @@ -745,9 +745,9 @@ StringRef CodeGenModule::getMangledName(GlobalDecl GD) { // Keep the first result in the case of a mangling collision. auto Result = Manglings.insert(std::make_pair(Str, GD)); - assert(&FoundStr == &MangledDeclNames[CanonicalGD] && "FoundStr is invalidated!"); - assert(FoundStr.empty() && "FoundStr is not empty!"); - return FoundStr = Result.first->first(); + assert(MangledDeclNames.find(CanonicalGD) == MangledDeclNames.end() && + "CanonicalGD is already mangled."); + return MangledDeclNames[CanonicalGD] = Result.first->first(); } StringRef CodeGenModule::getBlockMangledName(GlobalDecl GD, -- 2.50.1