llvm.org GIT mirror llvm / b5a1802
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@265043 91177308-0d34-0410-b5e6-96231b3b80d8 Evgeniy Stepanov 4 years ago
2 changed file(s) with 26 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
108108 //
109109 for (Module::const_global_iterator I = M->global_begin(), E = M->global_end();
110110 I != E; ++I) {
111 if (I->isDeclaration())
112 continue;
113
111114 GlobalVariable *GV = cast(VMap[&*I]);
112115 if (!ShouldCloneDefinition(&*I)) {
113116 // Skip after setting the correct linkage for an external reference.
121124 // Similarly, copy over function bodies now...
122125 //
123126 for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I) {
127 if (I->isDeclaration())
128 continue;
129
124130 Function *F = cast(VMap[&*I]);
125131 if (!ShouldCloneDefinition(&*I)) {
126132 // Skip after setting the correct linkage for an external reference.
129135 F->setPersonalityFn(nullptr);
130136 continue;
131137 }
132 if (!I->isDeclaration()) {
133 Function::arg_iterator DestI = F->arg_begin();
134 for (Function::const_arg_iterator J = I->arg_begin(); J != I->arg_end();
135 ++J) {
136 DestI->setName(J->getName());
137 VMap[&*J] = &*DestI++;
138 }
139138
140 SmallVector Returns; // Ignore returns cloned.
141 CloneFunctionInto(F, &*I, VMap, /*ModuleLevelChanges=*/true, Returns);
139 Function::arg_iterator DestI = F->arg_begin();
140 for (Function::const_arg_iterator J = I->arg_begin(); J != I->arg_end();
141 ++J) {
142 DestI->setName(J->getName());
143 VMap[&*J] = &*DestI++;
142144 }
145
146 SmallVector Returns; // Ignore returns cloned.
147 CloneFunctionInto(F, &*I, VMap, /*ModuleLevelChanges=*/true, Returns);
143148
144149 if (I->hasPersonalityFn())
145150 F->setPersonalityFn(MapValue(I->getPersonalityFn(), VMap));
0 ; Test that extern_weak linkage is preserved.
1 ; RUN: llvm-split -o %t %s
2 ; RUN: llvm-dis -o - %t0 | FileCheck %s
3 ; RUN: llvm-dis -o - %t1 | FileCheck %s
4
5 ; Both declarations are extern_weak in all partitions.
6
7 ; CHECK: @x = extern_weak global i32, align 4
8 @x = extern_weak global i32, align 4
9
10 ; CHECK: declare extern_weak void @f(...)
11 declare extern_weak void @f(...)