Skip to content

Commit

Permalink
Merge pull request JuliaLang#31431 from NHDaly/nhdaly-llvm-ghost-types
Browse files Browse the repository at this point in the history
Fix llvm-assertion: don't instantiate 0-sized structs (ghost types)
  • Loading branch information
vchuravy committed Mar 25, 2019
2 parents c46f4bb + 33c15d3 commit 92a361b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/intrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions test/intrinsics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 92a361b

Please sign in to comment.