Skip to content

Commit f27619c

Browse files
authored
codegen: check addresspace before doing a bitcast for small tags (#51517)
Fixes JuliaGPU/GPUCompiler.jl#504. Similar to #38424
1 parent af9a7af commit f27619c

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/cgutils.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,13 @@ static Constant *literal_pointer_val_slot(jl_codectx_t &ctx, jl_value_t *p)
411411
// some common builtin datatypes have a special pool for accessing them by smalltag id
412412
Constant *tag = ConstantInt::get(getInt32Ty(ctx.builder.getContext()), addr->smalltag << 4);
413413
Constant *smallp = ConstantExpr::getInBoundsGetElementPtr(getInt8Ty(ctx.builder.getContext()), prepare_global_in(jl_Module, jl_small_typeof_var), tag);
414-
return ConstantExpr::getBitCast(smallp, ctx.types().T_ppjlvalue);
414+
auto ty = ctx.types().T_ppjlvalue;
415+
if (ty->getPointerAddressSpace() == smallp->getType()->getPointerAddressSpace())
416+
return ConstantExpr::getBitCast(smallp, ty);
417+
else {
418+
Constant *newsmallp = ConstantExpr::getAddrSpaceCast(smallp, ty);
419+
return ConstantExpr::getBitCast(newsmallp, ty);
420+
}
415421
}
416422
// DataTypes are prefixed with a +
417423
return julia_pgv(ctx, "+", addr->name->name, addr->name->module, p);

0 commit comments

Comments
 (0)