r309501 - CodeGenModule.cpp: [PR33810][Modules] Avoid reusing FoundStr to try to fix crash.

NAKAMURA Takumi via cfe-commits cfe-commits at lists.llvm.org
Sat Jul 29 22:06:26 PDT 2017


Author: chapuni
Date: Sat Jul 29 22:06:26 2017
New Revision: 309501

URL: http://llvm.org/viewvc/llvm-project?rev=309501&view=rev
Log:
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().

Modified:
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=309501&r1=309500&r2=309501&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Sat Jul 29 22:06:26 2017
@@ -712,9 +712,9 @@ StringRef CodeGenModule::getMangledName(
     }
   }
 
-  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<NamedDecl>(GD.getDecl());
   SmallString<256> Buffer;
@@ -745,9 +745,9 @@ StringRef CodeGenModule::getMangledName(
 
   // 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,




More information about the cfe-commits mailing list