Fix handling of multiple unnamed globals with the same type
authorChris Lattner <sabre@nondot.org>
Tue, 15 Nov 2005 01:32:03 +0000 (01:32 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 15 Nov 2005 01:32:03 +0000 (01:32 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24362 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/Mangler.cpp

index 5257ca13a0c08a5a0f4c6fe32185edf2fcb23a46..f68959abe64fbf5e43427545511ea587e63ca59f 100644 (file)
@@ -132,6 +132,11 @@ std::string Mangler::getValueName(const GlobalValue *GV) {
   // - Otherwise, mangling occurs if global collides with existing name.
   if (isa<Function>(GV) && cast<Function>(GV)->getIntrinsicID()) {
     Name = GV->getName(); // Is an intrinsic function
+  } else if (!GV->hasName()) {
+    // Must mangle the global into a unique ID.
+    unsigned TypeUniqueID = getTypeID(GV->getType());
+    static unsigned GlobalID = 0;
+    Name = "__unnamed_" + utostr(TypeUniqueID) + "_" + utostr(GlobalID++);
   } else if (!MangledGlobals.count(GV)) {
     Name = makeNameProper(GV->getName(), Prefix);
   } else {
@@ -144,10 +149,8 @@ std::string Mangler::getValueName(const GlobalValue *GV) {
 
 void Mangler::InsertName(GlobalValue *GV,
                          std::map<std::string, GlobalValue*> &Names) {
-  if (!GV->hasName()) {   // We must mangle unnamed globals.
-    MangledGlobals.insert(GV);
+  if (!GV->hasName())   // We must mangle unnamed globals.
     return;
-  }
 
   // Figure out if this is already used.
   GlobalValue *&ExistingValue = Names[GV->getName()];