From 2d2b20fd76f6d7c7e3d5df9200472856cc5c540d Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Thu, 14 Jul 2016 19:25:23 -0400 Subject: [PATCH 1/2] Don't accidentally introduce constant uses from unowned functions --- src/jitlayers.h | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/jitlayers.h b/src/jitlayers.h index e9488124667d4..05f3a34faaf6b 100644 --- a/src/jitlayers.h +++ b/src/jitlayers.h @@ -92,14 +92,27 @@ static inline Function *function_proto(Function *F, Module *M = NULL) Function *NewF = Function::Create(F->getFunctionType(), Function::ExternalLinkage, F->getName(), M); - // FunctionType does not include any attributes. Copy them over manually - // as codegen may make decisions based on the presence of certain attributes - NewF->copyAttributesFrom(F); -#ifdef LLVM37 // Declarations are not allowed to have personality routines, but - // copyAttributesFrom sets them anyway, so clear them again manually - NewF->setPersonalityFn(nullptr); + // copyAttributesFrom sets them anyway. Temporarily unset the personlity + // routine from `F`, since copying it and then resetting is more expensive + // as well as introducing an extra use from this unowned function, which + // can cause crashes in the LLVMContext's global destructor. +#ifdef LLVM37 + llvm::Constant *OldPersonalityFn = nullptr; + if (F->hasPersonalityFn()) { + OldPersonalityFn = F->getPersonalityFn(); + F->setPersonalityFn(nullptr); + } +#endif + + // FunctionType does not include any attributes. Copy them over manually + // as codegen may make decisions based on the presence of certain attributes + NewF->copyAttributesFrom(F); + +#ifdef LLVM37 + if (OldPersonalityFn) + F->setPersonalityFn(OldPersonalityFn); #endif #ifdef LLVM35 From 2b54555b42e1f198fbc1a285746c5d373f2dd7aa Mon Sep 17 00:00:00 2001 From: Tony Kelman Date: Thu, 14 Jul 2016 20:35:09 -0700 Subject: [PATCH 2/2] typo fix /personlty/personality/ [ci skip] --- src/jitlayers.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jitlayers.h b/src/jitlayers.h index 05f3a34faaf6b..c4e2fe0fa5a31 100644 --- a/src/jitlayers.h +++ b/src/jitlayers.h @@ -94,7 +94,7 @@ static inline Function *function_proto(Function *F, Module *M = NULL) F->getName(), M); // Declarations are not allowed to have personality routines, but - // copyAttributesFrom sets them anyway. Temporarily unset the personlity + // copyAttributesFrom sets them anyway. Temporarily unset the personality // routine from `F`, since copying it and then resetting is more expensive // as well as introducing an extra use from this unowned function, which // can cause crashes in the LLVMContext's global destructor.