[IRMover] Don't copy personality, etc unless creating def
authorTeresa Johnson <tejohnson@google.com>
Tue, 12 Jan 2016 00:24:24 +0000 (00:24 +0000)
committerTeresa Johnson <tejohnson@google.com>
Tue, 12 Jan 2016 00:24:24 +0000 (00:24 +0000)
Function::copyAttributesFrom will copy the personality function, prefix
data and prolog data from the source function to the new function, and
is invoked when the IRMover copies the function prototype. This puts a
reference to a constant in the source module on a function in the dest
module, which causes an error when deleting the source module after
importing, since the personality function in the source module still has
uses (this would presumably also be an issue for the prologue and prefix
data). Remove the copies added to the dest copy when creating the new
prototype, as they are mapped properly when/if we link the function body.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@257420 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Linker/IRMover.cpp
test/Transforms/FunctionImport/Inputs/funcimport.ll
test/Transforms/FunctionImport/funcimport.ll

index 16de0ec88f42af184316883b8d11daf889fcfa74..8dd59f9e0e3e2f29b0de46c3d82d4809a7c39760 100644 (file)
@@ -773,6 +773,16 @@ GlobalValue *IRLinker::copyGlobalValueProto(const GlobalValue *SGV,
     NewGV->setLinkage(GlobalValue::ExternalWeakLinkage);
 
   NewGV->copyAttributesFrom(SGV);
+
+  // Remove these copied constants in case this stays a declaration, since
+  // they point to the source module. If the def is linked the values will
+  // be mapped in during linkFunctionBody.
+  if (auto *NewF = dyn_cast<Function>(NewGV)) {
+    NewF->setPersonalityFn(nullptr);
+    NewF->setPrefixData(nullptr);
+    NewF->setPrologueData(nullptr);
+  }
+
   return NewGV;
 }
 
index 96555892fe3c65520ae2a6b2457bc7ea4e5966ba..79b766b386df3801fa23460ea4942b6db098f069 100644 (file)
@@ -10,6 +10,7 @@
 
 define void @globalfunc1() #0 {
 entry:
+  call void @funcwithpersonality()
   ret void
 }
 
@@ -79,6 +80,20 @@ entry:
   ret i32 1
 }
 
+declare i32 @__gxx_personality_v0(...)
+
+; Add enough instructions to prevent import with inst limit of 5
+define internal void @funcwithpersonality() #2 personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
+entry:
+  call void @globalfunc2()
+  call void @globalfunc2()
+  call void @globalfunc2()
+  call void @globalfunc2()
+  call void @globalfunc2()
+  call void @globalfunc2()
+  ret void
+}
+
 define internal void @staticfunc2() #0 {
 entry:
   ret void
index c099b9766477d32223617bf515c6202519ec3c8b..52fd53d3f31f2122b9fb3847a4ba4cf475df2210 100644 (file)
@@ -73,3 +73,5 @@ declare void @callfuncptr(...) #1
 ; CHECK-DAG: declare void @weakfunc(...)
 declare void @weakfunc(...) #1
 
+; INSTLIMDEF-DAG: define available_externally hidden void @funcwithpersonality.llvm.2() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
+; INSTLIM5-DAG: declare hidden void @funcwithpersonality.llvm.2()