Skip to content

Commit

Permalink
Work to ensure immutable isbits Union fields get set correctly. #23351
Browse files Browse the repository at this point in the history
  • Loading branch information
quinnj committed Aug 20, 2017
1 parent d537999 commit fe66832
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2268,15 +2268,27 @@ static jl_cgval_t emit_new_struct(jl_codectx_t &ctx, jl_value_t *ty, size_t narg
Type *fty = julia_type_to_llvm(jtype);
const jl_cgval_t &fval_info = argv[i + 1];
emit_typecheck(ctx, fval_info, jtype, "new");
if (!type_is_ghost(fty)) {
Value *fval = NULL, *dest = NULL;
if (!init_as_value) {
Value *dest = NULL;
if (!init_as_value) {
bool isunion = jl_is_uniontype(jtype);
if (!type_is_ghost(fty) || isunion) {
// avoid unboxing the argument explicitly
// and use memcpy instead
dest = ctx.builder.CreateConstInBoundsGEP2_32(lt, strct, 0, i);
}
if (isunion) {
int fsz = jl_field_size(sty, i);
// compute tindex from rhs
// jl_cgval_t rhs_union = convert_julia_type(ctx, rhs, jtype);
Value *tindex = compute_tindex_unboxed(ctx, fval_info, jtype);
tindex = ctx.builder.CreateNUWSub(tindex, ConstantInt::get(T_int8, 1));
Value *ptindex = ctx.builder.CreateGEP(T_int8, emit_bitcast(ctx, dest, T_pint8), ConstantInt::get(T_size, fsz - 1));
ctx.builder.CreateStore(tindex, ptindex);
}
}
if (!type_is_ghost(fty)) {
Value *fval = NULL;
fval = emit_unbox(ctx, fty, fval_info, jtype, dest);

if (init_as_value) {
if (lt->isVectorTy())
strct = ctx.builder.CreateInsertElement(strct, fval, ConstantInt::get(T_int32, idx));
Expand Down
2 changes: 2 additions & 0 deletions src/datatype.c
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,8 @@ JL_DLLEXPORT jl_value_t *jl_get_nth_field(jl_value_t *v, size_t i)
if (jl_is_uniontype(ty)) {
uint8_t sel = ((uint8_t*)v)[offs + jl_field_size(st, i) - 1];
ty = jl_nth_union_component(ty, sel);
if (jl_is_datatype_singleton((jl_datatype_t*)ty))
return ((jl_datatype_t*)ty)->instance;
}
return jl_new_bits(ty, (char*)v + offs);
}
Expand Down

0 comments on commit fe66832

Please sign in to comment.