diff --git a/src/codegen.cpp b/src/codegen.cpp index f44a04ea1c0aff..5e2c26a2055e0a 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -634,10 +634,11 @@ class LocalGCFrame { } } void - restore() + restore(bool unreachable=false) { if (frame_swapped) { - emit_gcpop(ctx); + if (!unreachable) + emit_gcpop(ctx); finalize_gc_frame(ctx); std::swap(gc, ctx->gc); if (gc.argSpaceOffs + gc.maxDepth != 0) { @@ -2231,7 +2232,15 @@ static Value *emit_known_call(jl_value_t *ff, jl_value_t **args, size_t nargs, builder.CreateCall2(prepare_call(jlthrow_line_func), arg1, ConstantInt::get(T_int32, ctx->lineno)); #endif - local_gc_frame.restore(); + builder.CreateUnreachable(); + // New (unreachable) block since LLVM is not happy about terminator + // in the middle of a block + BasicBlock *nextBB = + BasicBlock::Create(getGlobalContext(), "unreachable", ctx->f); + builder.SetInsertPoint(nextBB); + // Update GC frame creation. The GC pop instructions should be removed + // by LLVM anyway but not emitting those instructions save us some work + local_gc_frame.restore(true); // unreachable=true JL_GC_POP(); return V_null; }