Skip to content

Commit

Permalink
Make the code after throwing an error unreachable and do not even emi…
Browse files Browse the repository at this point in the history
…t GC pop after throw
  • Loading branch information
yuyichao committed Jun 9, 2015
1 parent 9a0b83a commit 6bd9866
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 6bd9866

Please sign in to comment.