diff --git a/src/codegen.cpp b/src/codegen.cpp index 69c8ea00f1586..377700d5530e2 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -4718,6 +4718,8 @@ static std::unique_ptr emit_function(jl_lambda_info_t *lam, jl_llvm_func } } + builder.ClearInsertionPoint(); + // step 13, Apply LLVM level inlining for(std::vector::iterator it = ctx.to_inline.begin(); it != ctx.to_inline.end(); ++it) { Function *inlinef = (*it)->getCalledFunction(); diff --git a/test/core.jl b/test/core.jl index ee4605ff60704..b3dd90d9bba49 100644 --- a/test/core.jl +++ b/test/core.jl @@ -4469,3 +4469,10 @@ let k(x) = (k = x; k) @test k(1) == 1 end + +# PR #18054: compilation of cfunction leaves IRBuilder in bad state, +# causing heap-use-after-free when compiling f18054 +function f18054() + return Cint(0) +end +cfunction(f18054, Cint, ())