Fix the label name generation for address-taken labels to avoid potential
authorDan Gohman <gohman@apple.com>
Thu, 5 Nov 2009 23:14:35 +0000 (23:14 +0000)
committerDan Gohman <gohman@apple.com>
Thu, 5 Nov 2009 23:14:35 +0000 (23:14 +0000)
problems with name collisions.

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

lib/CodeGen/AsmPrinter/AsmPrinter.cpp

index bb6bd957f063bddb15cb12620c71e20caa1be2ed..4c4e0d311b0b868a64c526e7fc13cd5fda4407b1 100644 (file)
@@ -1636,13 +1636,17 @@ MCSymbol *AsmPrinter::GetBlockAddressSymbol(const Function *F,
   assert(BB->hasName() &&
          "Address of anonymous basic block not supported yet!");
 
-  // FIXME: This isn't guaranteed to produce a unique name even if the
-  // block and function have a name.
-  std::string Mangled =
-    Mang->getMangledName(F, Mang->makeNameProper(BB->getName()).c_str(),
-                         /*ForcePrivate=*/true);
+  // This code must use the function name itself, and not the function number,
+  // since it must be possible to generate the label name from within other
+  // functions.
+  std::string FuncName = Mang->getMangledName(F);
 
-  return OutContext.GetOrCreateSymbol(StringRef(Mangled));
+  SmallString<60> Name;
+  raw_svector_ostream(Name) << MAI->getPrivateGlobalPrefix() << "BA"
+    << FuncName.size() << '_' << FuncName << '_'
+    << Mang->makeNameProper(BB->getName());
+
+  return OutContext.GetOrCreateSymbol(Name.str());
 }
 
 MCSymbol *AsmPrinter::GetMBBSymbol(unsigned MBBID) const {