During module cloning copy aliases too. This fixes PR1544
authorAnton Korobeynikov <asl@math.spbu.ru>
Tue, 10 Jul 2007 19:07:35 +0000 (19:07 +0000)
committerAnton Korobeynikov <asl@math.spbu.ru>
Tue, 10 Jul 2007 19:07:35 +0000 (19:07 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@38505 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Utils/CloneModule.cpp

index dbe40a36465465433572749fee5df70baacba948..d64d58f38395f36c2b8598fbf6fa8c4406ddcbab 100644 (file)
@@ -69,6 +69,12 @@ Module *llvm::CloneModule(const Module *M,
     ValueMap[I]= NF;
   }
 
+  // Loop over the aliases in the module
+  for (Module::const_alias_iterator I = M->alias_begin(), E = M->alias_end();
+       I != E; ++I)
+    ValueMap[I] = new GlobalAlias(I->getType(), GlobalAlias::ExternalLinkage,
+                                  I->getName(), NULL, New);
+  
   // Now that all of the things that global variable initializer can refer to
   // have been created, loop through and copy the global variable referrers
   // over...  We also set the attributes on the global now.
@@ -103,6 +109,15 @@ Module *llvm::CloneModule(const Module *M,
     F->setLinkage(I->getLinkage());
   }
 
+  // And aliases
+  for (Module::const_alias_iterator I = M->alias_begin(), E = M->alias_end();
+       I != E; ++I) {
+    GlobalAlias *GA = cast<GlobalAlias>(ValueMap[I]);
+    GA->setLinkage(I->getLinkage());
+    if (const Constant* C = I->getAliasee())
+      GA->setAliasee(cast<Constant>(MapValue(C, ValueMap)));
+  }
+  
   return New;
 }