Skip to content

Commit

Permalink
Clear the IRBuilder's insertion point after emitting a function.
Browse files Browse the repository at this point in the history
The function might get finalized, invalidating the IP.
However, in some cases this invalid IP may get saved and restored, accessing the invalid IP while doing so.

Example code path accessing an invalid IP:
 -> jl_cfunction_object (nested_compile=true, but doesn't change IP)
 -> gen_cfun_wrapper
 -> jl_compile_linfo (saves and restores invalid IP)
  • Loading branch information
maleadt committed Aug 16, 2016
1 parent c270a23 commit ebd24a8
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4718,6 +4718,8 @@ static std::unique_ptr<Module> emit_function(jl_lambda_info_t *lam, jl_llvm_func
}
}

builder.ClearInsertionPoint();

// step 13, Apply LLVM level inlining
for(std::vector<CallInst*>::iterator it = ctx.to_inline.begin(); it != ctx.to_inline.end(); ++it) {
Function *inlinef = (*it)->getCalledFunction();
Expand Down

0 comments on commit ebd24a8

Please sign in to comment.