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)

(cherry picked from commit ebd24a8, ref #18054)
  • Loading branch information
maleadt committed Aug 21, 2016
1 parent f5ed767 commit bfa4e62
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 @@ -4746,6 +4746,8 @@ static std::unique_ptr<Module> emit_function(jl_lambda_info_t *lam, jl_llvm_func
}
}

builder.ClearInsertionPoint();

// step 14, 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 bfa4e62

Please sign in to comment.