Skip to content

Commit 173514f

Browse files
simeonschaubvtjnash
authored andcommitted
fix null comparisons for non-standard address spaces (#58837)
Co-authored-by: Jameson Nash <[email protected]> (cherry picked from commit 3ed13ea)
1 parent 94107d8 commit 173514f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/cgutils.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1395,10 +1395,17 @@ static void undef_var_error_ifnot(jl_codectx_t &ctx, Value *ok, jl_sym_t *name,
13951395
ctx.builder.SetInsertPoint(ifok);
13961396
}
13971397

1398+
// ctx.builder.CreateIsNotNull(v) lowers incorrectly in non-standard
1399+
// address spaces where null is not zero
1400+
// TODO: adapt to https://github.com/llvm/llvm-project/pull/131557 once merged
13981401
static Value *null_pointer_cmp(jl_codectx_t &ctx, Value *v)
13991402
{
14001403
++EmittedNullchecks;
1401-
return ctx.builder.CreateIsNotNull(v);
1404+
Type *T = v->getType();
1405+
return ctx.builder.CreateICmpNE(
1406+
v,
1407+
ctx.builder.CreateAddrSpaceCast(
1408+
Constant::getNullValue(ctx.builder.getPtrTy(0)), T));
14021409
}
14031410

14041411

0 commit comments

Comments
 (0)