Skip to content

Commit 6bd9866

Browse files
committed
Make the code after throwing an error unreachable and do not even emit GC pop after throw
1 parent 9a0b83a commit 6bd9866

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/codegen.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -634,10 +634,11 @@ class LocalGCFrame {
634634
}
635635
}
636636
void
637-
restore()
637+
restore(bool unreachable=false)
638638
{
639639
if (frame_swapped) {
640-
emit_gcpop(ctx);
640+
if (!unreachable)
641+
emit_gcpop(ctx);
641642
finalize_gc_frame(ctx);
642643
std::swap(gc, ctx->gc);
643644
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,
22312232
builder.CreateCall2(prepare_call(jlthrow_line_func), arg1,
22322233
ConstantInt::get(T_int32, ctx->lineno));
22332234
#endif
2234-
local_gc_frame.restore();
2235+
builder.CreateUnreachable();
2236+
// New (unreachable) block since LLVM is not happy about terminator
2237+
// in the middle of a block
2238+
BasicBlock *nextBB =
2239+
BasicBlock::Create(getGlobalContext(), "unreachable", ctx->f);
2240+
builder.SetInsertPoint(nextBB);
2241+
// Update GC frame creation. The GC pop instructions should be removed
2242+
// by LLVM anyway but not emitting those instructions save us some work
2243+
local_gc_frame.restore(true); // unreachable=true
22352244
JL_GC_POP();
22362245
return V_null;
22372246
}

0 commit comments

Comments
 (0)