[llvm-commits] CVS: llvm/lib/Support/Mangler.cpp

Chris Lattner lattner at cs.uiuc.edu
Fri Feb 13 18:31:01 PST 2004


Changes in directory llvm/lib/Support:

Mangler.cpp updated: 1.9 -> 1.10

---
Log message:

Fix the logic in the name mangler.  If there are two symbols named 'X', and one
is external, make sure to mangle the *internal* one, not external one


---
Diffs of the changes:  (+27 -12)

Index: llvm/lib/Support/Mangler.cpp
diff -u llvm/lib/Support/Mangler.cpp:1.9 llvm/lib/Support/Mangler.cpp:1.10
--- llvm/lib/Support/Mangler.cpp:1.9	Tue Feb 10 21:29:16 2004
+++ llvm/lib/Support/Mangler.cpp	Fri Feb 13 18:30:23 2004
@@ -80,22 +80,37 @@
   return name;
 }
 
+void Mangler::InsertName(GlobalValue *GV,
+                         std::map<std::string, GlobalValue*> &Names) {
+  if (!GV->hasName()) {   // We must mangle unnamed globals.
+    MangledGlobals.insert(GV);
+    return;
+  }
+
+  // Figure out if this is already used.
+  GlobalValue *&ExistingValue = Names[GV->getName()];
+  if (!ExistingValue) {
+    ExistingValue = GV;
+  } else {
+    // If GV is external but the existing one is static, mangle the existing one
+    if (GV->hasExternalLinkage() && !ExistingValue->hasExternalLinkage()) {
+      MangledGlobals.insert(ExistingValue);
+      ExistingValue = GV;
+    } else {
+      // Otherwise, mangle GV
+      MangledGlobals.insert(GV);
+    }
+  }
+}
+
+
 Mangler::Mangler(Module &m, bool addUnderscorePrefix)
   : M(m), AddUnderscorePrefix(addUnderscorePrefix), Count(0) {
   // Calculate which global values have names that will collide when we throw
   // away type information.
-  std::set<std::string> FoundNames;
+  std::map<std::string, GlobalValue*> Names;
   for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
-    if (I->hasName())                      // If the global has a name...
-      if (FoundNames.count(I->getName()))  // And the name is already used
-        MangledGlobals.insert(I);          // Mangle the name
-      else
-        FoundNames.insert(I->getName());   // Otherwise, keep track of name
-
+    InsertName(I, Names);
   for (Module::giterator I = M.gbegin(), E = M.gend(); I != E; ++I)
-    if (I->hasName())                      // If the global has a name...
-      if (FoundNames.count(I->getName()))  // And the name is already used
-        MangledGlobals.insert(I);          // Mangle the name
-      else
-        FoundNames.insert(I->getName());   // Otherwise, keep track of name
+    InsertName(I, Names);
 }





More information about the llvm-commits mailing list