Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #29718, union field alignment #29722

Merged
merged 1 commit into from
Oct 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
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
27 changes: 27 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5722,6 +5722,13 @@ let x5 = UnionField5(nothing, Int8(3))
@test hash(x5) === hash(x5copy)
end

struct UnionField6
alignment::Int32
padding::NTuple{3, UInt8}
#= implicit-padding::UInt8 =#
maybe_val::Union{UInt16, Nothing} # offset = 8, align = 8, size = 2
end
@test UnionField6(1,(1,1,1),2018).maybe_val == 2018

# PR #23367
struct A23367
Expand Down Expand Up @@ -6324,6 +6331,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