From: Teresa Johnson Date: Tue, 12 Jan 2016 00:24:24 +0000 (+0000) Subject: [IRMover] Don't copy personality, etc unless creating def X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=132f8670a3b60601ac94b30b8a19f748f060fc46;p=oota-llvm.git [IRMover] Don't copy personality, etc unless creating def 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 --- diff --git a/lib/Linker/IRMover.cpp b/lib/Linker/IRMover.cpp index 16de0ec88f4..8dd59f9e0e3 100644 --- a/lib/Linker/IRMover.cpp +++ b/lib/Linker/IRMover.cpp @@ -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(NewGV)) { + NewF->setPersonalityFn(nullptr); + NewF->setPrefixData(nullptr); + NewF->setPrologueData(nullptr); + } + return NewGV; } diff --git a/test/Transforms/FunctionImport/Inputs/funcimport.ll b/test/Transforms/FunctionImport/Inputs/funcimport.ll index 96555892fe3..79b766b386d 100644 --- a/test/Transforms/FunctionImport/Inputs/funcimport.ll +++ b/test/Transforms/FunctionImport/Inputs/funcimport.ll @@ -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 diff --git a/test/Transforms/FunctionImport/funcimport.ll b/test/Transforms/FunctionImport/funcimport.ll index c099b976647..52fd53d3f31 100644 --- a/test/Transforms/FunctionImport/funcimport.ll +++ b/test/Transforms/FunctionImport/funcimport.ll @@ -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()