Skip to content

Commit

Permalink
fix #29718, union field alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Oct 19, 2018
1 parent 5f2759d commit 0484546
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
21 changes: 7 additions & 14 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,10 +556,10 @@ static bool julia_struct_has_layout(jl_datatype_t *dt, jl_unionall_t *ua)

static unsigned jl_field_align(jl_datatype_t *dt, size_t i)
{
unsigned al = jl_field_offset(dt, i);
al |= 16;
al &= -al;
return std::min(al, jl_datatype_align(dt));
jl_value_t *ty = jl_field_type(dt, i);
size_t fsz = 0, al = 1;
(void)jl_islayout_inline(ty, &fsz, &al);
return al;
}

static Type *julia_struct_to_llvm(jl_value_t *jt, jl_unionall_t *ua, bool *isboxed)
Expand Down Expand Up @@ -596,16 +596,9 @@ static Type *julia_struct_to_llvm(jl_value_t *jt, jl_unionall_t *ua, bool *isbox
jlasttype = ty;
bool isptr;
size_t fsz = 0, al = 0;
if (jst->layout) {
isptr = jl_field_isptr(jst, i);
fsz = jl_field_size(jst, i);
al = jl_field_align(jst, i);
}
else { // compute what jl_compute_field_offsets would say
isptr = !jl_islayout_inline(ty, &fsz, &al);
if (!isptr && jl_is_uniontype(jst))
fsz += 1;
}
isptr = !jl_islayout_inline(ty, &fsz, &al);
if (!isptr && jl_is_uniontype(ty))
fsz += 1;
Type *lty;
if (isptr) {
lty = T_pjlvalue;
Expand Down
20 changes: 20 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6324,6 +6324,26 @@ let A=[0, missing], B=[missing, 0], C=Vector{Union{Int, Missing}}(undef, 6)
@test isequal(C, [0, missing, missing, missing, 0, missing])
end

# issue #29718
function f29718()
nt = NamedTuple{(:a, :b, :c, :d, :e, :f,),
Tuple{Union{Missing, Float64},
Tuple{UInt8},
Union{Missing, Int8},
Int8,
Tuple{UInt8,UInt8},
Union{Missing, Int16}}
}((missing,
(1,),
1,
41,
(1,2),
1915,
))
return Ref{Any}(nt)[].f
end
@test f29718() == 1915

end # module UnionOptimizations

# issue #6614, argument destructuring
Expand Down

0 comments on commit 0484546

Please sign in to comment.