diff --git a/src/intrinsics.cpp b/src/intrinsics.cpp index 7d7c24cdda0b6..61b9431177905 100644 --- a/src/intrinsics.cpp +++ b/src/intrinsics.cpp @@ -600,8 +600,13 @@ static jl_cgval_t emit_pointerref(jl_codectx_t &ctx, jl_cgval_t *argv) bool isboxed; Type *ptrty = julia_type_to_llvm(ety, &isboxed); assert(!isboxed); - Value *thePtr = emit_unbox(ctx, ptrty->getPointerTo(), e, e.typ); - return typed_load(ctx, thePtr, im1, ety, tbaa_data, nullptr, true, align_nb); + if (!type_is_ghost(ptrty)) { + Value *thePtr = emit_unbox(ctx, ptrty->getPointerTo(), e, e.typ); + return typed_load(ctx, thePtr, im1, ety, tbaa_data, nullptr, true, align_nb); + } + else { + return ghostValue(ety); + } } } @@ -663,10 +668,12 @@ static jl_cgval_t emit_pointerset(jl_codectx_t &ctx, jl_cgval_t *argv) bool isboxed; Type *ptrty = julia_type_to_llvm(ety, &isboxed); assert(!isboxed); - thePtr = emit_unbox(ctx, ptrty->getPointerTo(), e, e.typ); - typed_store(ctx, thePtr, im1, x, ety, tbaa_data, nullptr, nullptr, align_nb); + if (!type_is_ghost(ptrty)) { + thePtr = emit_unbox(ctx, ptrty->getPointerTo(), e, e.typ); + typed_store(ctx, thePtr, im1, x, ety, tbaa_data, nullptr, nullptr, align_nb); + } } - return mark_julia_type(ctx, thePtr, false, aty); + return e; } static Value *emit_checked_srem_int(jl_codectx_t &ctx, Value *x, Value *den) diff --git a/test/intrinsics.jl b/test/intrinsics.jl index 993efc63a4c03..a5f3308c68639 100644 --- a/test/intrinsics.jl +++ b/test/intrinsics.jl @@ -100,3 +100,9 @@ let f = Core.Intrinsics.ashr_int @test f(Int32(-1), -10) == -1 @test f(Int32(2), -1) == 0 end + +# issue #29929 +@test unsafe_store!(Ptr{Nothing}(C_NULL), nothing) === Ptr{Nothing}(0) +@test unsafe_load(Ptr{Nothing}(0)) === nothing +struct GhostStruct end +@test unsafe_load(Ptr{GhostStruct}(rand(Int))) === GhostStruct()