Skip to content

Commit 2f9e739

Browse files
committed
bitcast: ensure the target pointer address space is used.
1 parent 3686743 commit 2f9e739

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/intrinsics.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,16 @@ static jl_cgval_t generic_bitcast(jl_codectx_t &ctx, ArrayRef<jl_cgval_t> argv)
638638
if (isa<Instruction>(vx) && !vx->hasName())
639639
// emit_inttoptr may undo an PtrToInt
640640
setName(ctx.emission_context, vx, "bitcast_coercion");
641+
} else if (vxt->isPointerTy() && llvmt->isPointerTy()) {
642+
// emit_bitcast preserves the origin address space, which we can't have here
643+
#if JL_LLVM_VERSION >= 170000
644+
vx = ctx.builder.CreateAddrSpaceCast(vx, llvmt);
645+
#else
646+
vx = ctx.builder.CreatePointerBitCastOrAddrSpaceCast(vx, llvmt);
647+
#endif
648+
if (isa<Instruction>(vx) && !vx->hasName())
649+
// cast may have been folded
650+
setName(ctx.emission_context, vx, "bitcast_coercion");
641651
} else {
642652
vx = emit_bitcast(ctx, vx, llvmt);
643653
if (isa<Instruction>(vx) && !vx->hasName())

0 commit comments

Comments
 (0)