[llvm] r265043 - Preserve extern_weak linkage in CloneModule.
Evgeniy Stepanov via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 31 13:21:32 PDT 2016
Author: eugenis
Date: Thu Mar 31 15:21:31 2016
New Revision: 265043
URL: http://llvm.org/viewvc/llvm-project?rev=265043&view=rev
Log:
Preserve extern_weak linkage in CloneModule.
Only force "extern" linkage if the function used to be a definition
in the source module. Declarations keep their original linkage.
Added:
llvm/trunk/test/tools/llvm-split/extern_linkage.ll
Modified:
llvm/trunk/lib/Transforms/Utils/CloneModule.cpp
Modified: llvm/trunk/lib/Transforms/Utils/CloneModule.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/CloneModule.cpp?rev=265043&r1=265042&r2=265043&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/CloneModule.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/CloneModule.cpp Thu Mar 31 15:21:31 2016
@@ -109,6 +109,9 @@ std::unique_ptr<Module> llvm::CloneModul
//
for (Module::const_global_iterator I = M->global_begin(), E = M->global_end();
I != E; ++I) {
+ if (I->isDeclaration())
+ continue;
+
GlobalVariable *GV = cast<GlobalVariable>(VMap[&*I]);
if (!ShouldCloneDefinition(&*I)) {
// Skip after setting the correct linkage for an external reference.
@@ -122,6 +125,9 @@ std::unique_ptr<Module> llvm::CloneModul
// Similarly, copy over function bodies now...
//
for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I) {
+ if (I->isDeclaration())
+ continue;
+
Function *F = cast<Function>(VMap[&*I]);
if (!ShouldCloneDefinition(&*I)) {
// Skip after setting the correct linkage for an external reference.
@@ -130,18 +136,17 @@ std::unique_ptr<Module> llvm::CloneModul
F->setPersonalityFn(nullptr);
continue;
}
- if (!I->isDeclaration()) {
- Function::arg_iterator DestI = F->arg_begin();
- for (Function::const_arg_iterator J = I->arg_begin(); J != I->arg_end();
- ++J) {
- DestI->setName(J->getName());
- VMap[&*J] = &*DestI++;
- }
- SmallVector<ReturnInst*, 8> Returns; // Ignore returns cloned.
- CloneFunctionInto(F, &*I, VMap, /*ModuleLevelChanges=*/true, Returns);
+ Function::arg_iterator DestI = F->arg_begin();
+ for (Function::const_arg_iterator J = I->arg_begin(); J != I->arg_end();
+ ++J) {
+ DestI->setName(J->getName());
+ VMap[&*J] = &*DestI++;
}
+ SmallVector<ReturnInst *, 8> Returns; // Ignore returns cloned.
+ CloneFunctionInto(F, &*I, VMap, /*ModuleLevelChanges=*/true, Returns);
+
if (I->hasPersonalityFn())
F->setPersonalityFn(MapValue(I->getPersonalityFn(), VMap));
}
Added: llvm/trunk/test/tools/llvm-split/extern_linkage.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-split/extern_linkage.ll?rev=265043&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-split/extern_linkage.ll (added)
+++ llvm/trunk/test/tools/llvm-split/extern_linkage.ll Thu Mar 31 15:21:31 2016
@@ -0,0 +1,12 @@
+; Test that extern_weak linkage is preserved.
+; RUN: llvm-split -o %t %s
+; RUN: llvm-dis -o - %t0 | FileCheck %s
+; RUN: llvm-dis -o - %t1 | FileCheck %s
+
+; Both declarations are extern_weak in all partitions.
+
+; CHECK: @x = extern_weak global i32, align 4
+ at x = extern_weak global i32, align 4
+
+; CHECK: declare extern_weak void @f(...)
+declare extern_weak void @f(...)
More information about the llvm-commits
mailing list