Skip to content

Commit

Permalink
fix JuliaLang#40855, alignment calculation in julia_const_to_llvm (J…
Browse files Browse the repository at this point in the history
…uliaLang#40864)

This appears as a regression due to doing more constant folding in 1.6+
  • Loading branch information
JeffBezanson authored and johanmon committed Jul 5, 2021
1 parent 3a5983a commit 3044b88
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/intrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,9 @@ static Constant *julia_const_to_llvm(jl_codectx_t &ctx, const void *ptr, jl_data
const uint8_t *ov = (const uint8_t*)ptr + offs;
if (jl_is_uniontype(ft)) {
// compute the same type layout as julia_struct_to_llvm
size_t fsz = jl_field_size(bt, i);
size_t al = jl_field_align(bt, i);
size_t fsz = 0, al = 0;
(void)jl_islayout_inline(ft, &fsz, &al);
fsz = jl_field_size(bt, i);
uint8_t sel = ((const uint8_t*)ptr)[offs + fsz - 1];
jl_value_t *active_ty = jl_nth_union_component(ft, sel);
size_t active_sz = jl_datatype_size(active_ty);
Expand Down
9 changes: 9 additions & 0 deletions test/compiler/codegen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -561,3 +561,12 @@ function f32843(vals0, v)
vals
end
@test_throws UndefVarError f32843([6], Vector[[1]])

# issue #40855, struct constants with union fields
@enum T40855 X40855
struct A40855
d::Union{Nothing, T40855}
b::Union{Nothing, Int}
end
g() = string(A40855(X40855, 1))
@test g() == "$(@__MODULE__).A40855($(@__MODULE__).X40855, 1)"

0 comments on commit 3044b88

Please sign in to comment.