Skip to content

Commit

Permalink
Merge pull request #17431 from JuliaLang/kf/uses
Browse files Browse the repository at this point in the history
Don't accidentally introduce constant uses from unowned functions
  • Loading branch information
Keno authored Jul 16, 2016
2 parents 1fd440e + 2b54555 commit a1fbb84
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/jitlayers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 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.
#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
Expand Down

0 comments on commit a1fbb84

Please sign in to comment.