[llvm-branch-commits] [llvm-branch] r134473 - /llvm/branches/type-system-rewrite/lib/Linker/LinkModules.cpp

Chris Lattner sabre at nondot.org
Tue Jul 5 23:14:01 PDT 2011


Author: lattner
Date: Wed Jul  6 01:14:01 2011
New Revision: 134473

URL: http://llvm.org/viewvc/llvm-project?rev=134473&view=rev
Log:
simplify the 'link from source' logic for global variables:
we already propagate the is-constant bit in the ctor and 
we can avoid 'force renaming' by just nuking the name of the
replaced global early.

Modified:
    llvm/branches/type-system-rewrite/lib/Linker/LinkModules.cpp

Modified: llvm/branches/type-system-rewrite/lib/Linker/LinkModules.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/type-system-rewrite/lib/Linker/LinkModules.cpp?rev=134473&r1=134472&r2=134473&view=diff
==============================================================================
--- llvm/branches/type-system-rewrite/lib/Linker/LinkModules.cpp (original)
+++ llvm/branches/type-system-rewrite/lib/Linker/LinkModules.cpp Wed Jul  6 01:14:01 2011
@@ -608,6 +608,8 @@
   if (DGV->hasAppendingLinkage() || SGV->hasAppendingLinkage())
     return linkAppendingVars(cast<GlobalVariable>(DGV), SGV);
 
+  // Determine whether linkage of these two globals follows the source module's
+  // definition or the destination module's definition.
   GlobalValue::LinkageTypes NewLinkage = GlobalValue::InternalLinkage;
   bool LinkFromSrc = false;
   if (getLinkageResult(DGV, SGV, NewLinkage, LinkFromSrc))
@@ -618,6 +620,9 @@
       return emitError("Global alias collision on '" + SGV->getName() +
                    "': symbol multiple defined");
 
+    // Clear the name of DGV so we don't get a name conflict.
+    DGV->setName("");
+    
     // If the types don't match, and if we are to link from the source, nuke
     // DGV and create a new one of the appropriate type.  Note that the thing
     // we are replacing may be a function (if a prototype, weak, etc) or a
@@ -625,7 +630,7 @@
     GlobalVariable *NewDGV =
       new GlobalVariable(*DstM, TypeMap.get(SGV->getType()->getElementType()),
                          SGV->isConstant(), NewLinkage, /*init*/0,
-                         DGV->getName(), 0, false,
+                         SGV->getName(), 0, false,
                          SGV->getType()->getAddressSpace());
 
     // Propagate alignment, section, visibility info, unnamed_addr, etc.
@@ -641,14 +646,6 @@
     else
       cast<Function>(DGV)->eraseFromParent();
 
-    // If the symbol table renamed the global, but it is an externally visible
-    // symbol, DGV must be an existing global with internal linkage.  Rename.
-    if (NewDGV->getName() != SGV->getName() && !NewDGV->hasLocalLinkage())
-      forceRenaming(NewDGV, SGV->getName());
-
-    // Inherit const as appropriate.
-    NewDGV->setConstant(SGV->isConstant());
-
     // Make sure to remember this mapping.
     ValueMap[SGV] = NewDGV;
     return false;





More information about the llvm-branch-commits mailing list