From 1e6e551b738f61ac83883061fac00870eed13a28 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Thu, 18 Oct 2018 22:24:32 -0400 Subject: [PATCH] fix #29718, union field alignment --- src/cgutils.cpp | 8 ++++---- test/core.jl | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/cgutils.cpp b/src/cgutils.cpp index 248cbe4c902e2..61a8bbc586676 100644 --- a/src/cgutils.cpp +++ b/src/cgutils.cpp @@ -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) diff --git a/test/core.jl b/test/core.jl index b7db56af115e0..17d2b0c6161ac 100644 --- a/test/core.jl +++ b/test/core.jl @@ -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