Skip to content

Commit 735c639

Browse files
committed
fix #7836, speed bump due to unreachable code
1 parent b7c6d0b commit 735c639

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

base/inference.jl

+4-1
Original file line numberDiff line numberDiff line change
@@ -1681,7 +1681,10 @@ function type_annotate(ast::Expr, states::Array{Any,1}, sv::ANY, rettype::ANY,
16811681
body = ast.args[3].args::Array{Any,1}
16821682
for i=1:length(body)
16831683
st_i = states[i]
1684-
body[i] = eval_annotate(body[i], (st_i === () ? emptydict : st_i), sv, decls, closures)
1684+
if st_i !== ()
1685+
# st_i === () => unreached statement (see issue #7836)
1686+
body[i] = eval_annotate(body[i], st_i, sv, decls, closures)
1687+
end
16851688
end
16861689
ast.args[3].typ = rettype
16871690

src/codegen.cpp

+14-9
Original file line numberDiff line numberDiff line change
@@ -2362,15 +2362,20 @@ static Value *var_binding_pointer(jl_sym_t *s, jl_binding_t **pbnd,
23622362
static Value *emit_checked_var(Value *bp, jl_sym_t *name, jl_codectx_t *ctx)
23632363
{
23642364
Value *v = tpropagate(bp, builder.CreateLoad(bp, false));
2365-
Value *ok = builder.CreateICmpNE(v, V_null);
2366-
BasicBlock *err = BasicBlock::Create(getGlobalContext(), "err", ctx->f);
2367-
BasicBlock *ifok = BasicBlock::Create(getGlobalContext(), "ok");
2368-
builder.CreateCondBr(ok, ifok, err);
2369-
builder.SetInsertPoint(err);
2370-
builder.CreateCall(prepare_call(jlundefvarerror_func), literal_pointer_val((jl_value_t*)name));
2371-
builder.CreateBr(ifok);
2372-
ctx->f->getBasicBlockList().push_back(ifok);
2373-
builder.SetInsertPoint(ifok);
2365+
// in unreachable code, there might be a poorly-typed instance of a variable
2366+
// that has a concrete type everywhere it's actually used. tolerate this
2367+
// situation by just skipping the NULL check if it wouldn't be valid. (issue #7836)
2368+
if (v->getType() == jl_pvalue_llvmt) {
2369+
Value *ok = builder.CreateICmpNE(v, V_null);
2370+
BasicBlock *err = BasicBlock::Create(getGlobalContext(), "err", ctx->f);
2371+
BasicBlock *ifok = BasicBlock::Create(getGlobalContext(), "ok");
2372+
builder.CreateCondBr(ok, ifok, err);
2373+
builder.SetInsertPoint(err);
2374+
builder.CreateCall(prepare_call(jlundefvarerror_func), literal_pointer_val((jl_value_t*)name));
2375+
builder.CreateBr(ifok);
2376+
ctx->f->getBasicBlockList().push_back(ifok);
2377+
builder.SetInsertPoint(ifok);
2378+
}
23742379
return v;
23752380
}
23762381

0 commit comments

Comments
 (0)