Skip to content

Commit

Permalink
Fix llvm-assertion: don't load ghost types
Browse files Browse the repository at this point in the history
As I understand it, LLVM doesn't support 0-sized structs (ghost types),
which julia makes significant use of. This fixes an incorrect behavior
in the julia compiler accidentally attempting to instantiate such
0-sized structs.

When using a debug build of LLVM, this fails with an assertion error,
but failed silently on standard LLVM.
  • Loading branch information
NHDaly committed Mar 21, 2019
1 parent 7f7fe9a commit 0d0b853
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 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 mark_julia_const(((jl_datatype_t*)ety)->instance);
}
}
}

Expand Down Expand Up @@ -663,8 +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);
} else {
return e;
}
}
return mark_julia_type(ctx, thePtr, false, aty);
}
Expand Down

0 comments on commit 0d0b853

Please sign in to comment.