[llvm-commits] CVS: llvm/lib/Linker/LinkModules.cpp

Chris Lattner lattner at cs.uiuc.edu
Thu Jun 15 18:24:16 PDT 2006



Changes in directory llvm/lib/Linker:

LinkModules.cpp updated: 1.114 -> 1.115
---
Log message:

Fix Regression/Linker/2006-06-15-GlobalVarAnment.ll


---
Diffs of the changes:  (+18 -5)

 LinkModules.cpp |   23 ++++++++++++++++++-----
 1 files changed, 18 insertions(+), 5 deletions(-)


Index: llvm/lib/Linker/LinkModules.cpp
diff -u llvm/lib/Linker/LinkModules.cpp:1.114 llvm/lib/Linker/LinkModules.cpp:1.115
--- llvm/lib/Linker/LinkModules.cpp:1.114	Thu Jun  1 14:14:22 2006
+++ llvm/lib/Linker/LinkModules.cpp	Thu Jun 15 20:24:04 2006
@@ -452,7 +452,8 @@
   SymbolTable *ST = (SymbolTable*)&Dest->getSymbolTable();
 
   // Loop over all of the globals in the src module, mapping them over as we go
-  for (Module::global_iterator I = Src->global_begin(), E = Src->global_end(); I != E; ++I) {
+  for (Module::global_iterator I = Src->global_begin(), E = Src->global_end();
+       I != E; ++I) {
     GlobalVariable *SGV = I;
     GlobalVariable *DGV = 0;
     // Check to see if may have to link the global.
@@ -487,7 +488,9 @@
         new GlobalVariable(SGV->getType()->getElementType(),
                            SGV->isConstant(), SGV->getLinkage(), /*init*/0,
                            SGV->getName(), Dest);
-
+      // Propagate alignment info.
+      NewDGV->setAlignment(SGV->getAlignment());
+      
       // If the LLVM runtime renamed the global, but it is an externally visible
       // symbol, DGV must be an existing global with internal linkage.  Rename
       // it.
@@ -509,12 +512,18 @@
                            SGV->isConstant(), SGV->getLinkage(), /*init*/0,
                            "", Dest);
 
+      // Propagate alignment info.
+      NewDGV->setAlignment(std::max(DGV->getAlignment(), SGV->getAlignment()));
+
       // Make sure to remember this mapping...
       ValueMap.insert(std::make_pair(SGV, NewDGV));
 
       // Keep track that this is an appending variable...
       AppendingVars.insert(std::make_pair(SGV->getName(), NewDGV));
     } else {
+      // Propagate alignment info.
+      DGV->setAlignment(std::max(DGV->getAlignment(), SGV->getAlignment()));
+
       // Otherwise, perform the mapping as instructed by GetLinkageResult.  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.
@@ -522,6 +531,7 @@
         GlobalVariable *NewDGV =
           new GlobalVariable(SGV->getType()->getElementType(),
                              DGV->isConstant(), DGV->getLinkage());
+        NewDGV->setAlignment(DGV->getAlignment());
         Dest->getGlobalList().insert(DGV, NewDGV);
         DGV->replaceAllUsesWith(ConstantExpr::getCast(NewDGV, DGV->getType()));
         DGV->eraseFromParent();
@@ -560,7 +570,8 @@
                             std::string *Err) {
 
   // Loop over all of the globals in the src module, mapping them over as we go
-  for (Module::const_global_iterator I = Src->global_begin(), E = Src->global_end(); I != E; ++I){
+  for (Module::const_global_iterator I = Src->global_begin(),
+       E = Src->global_end(); I != E; ++I) {
     const GlobalVariable *SGV = I;
 
     if (SGV->hasInitializer()) {      // Only process initialized GV's
@@ -709,7 +720,8 @@
           *OI = RemapOperand(*OI, GlobalMap);
 
   // There is no need to map the arguments anymore.
-  for (Function::arg_iterator I = Src->arg_begin(), E = Src->arg_end(); I != E; ++I)
+  for (Function::arg_iterator I = Src->arg_begin(), E = Src->arg_end();
+       I != E; ++I)
     GlobalMap.erase(I);
 
   return false;
@@ -892,7 +904,8 @@
   // it's functionality here.
   std::map<std::string, GlobalValue*> GlobalsByName;
 
-  for (Module::global_iterator I = Dest->global_begin(), E = Dest->global_end(); I != E; ++I) {
+  for (Module::global_iterator I = Dest->global_begin(), E = Dest->global_end();
+       I != E; ++I) {
     // Add all of the appending globals already in the Dest module to
     // AppendingVars.
     if (I->hasAppendingLinkage())






More information about the llvm-commits mailing list