@@ -2362,15 +2362,20 @@ static Value *var_binding_pointer(jl_sym_t *s, jl_binding_t **pbnd,
2362
2362
static Value *emit_checked_var (Value *bp, jl_sym_t *name, jl_codectx_t *ctx)
2363
2363
{
2364
2364
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
+ }
2374
2379
return v;
2375
2380
}
2376
2381
0 commit comments