Skip to content

Commit

Permalink
codegen: move undef freeze before promotion point (#55428)
Browse files Browse the repository at this point in the history
Fixes #55396
  • Loading branch information
vtjnash authored Aug 9, 2024
1 parent e7e8768 commit ac9558c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3947,8 +3947,6 @@ static jl_cgval_t emit_new_struct(jl_codectx_t &ctx, jl_value_t *ty, size_t narg
else {
strct = emit_static_alloca(ctx, lt);
setName(ctx.emission_context, strct, arg_typename);
if (nargs < nf)
promotion_point = ctx.builder.CreateStore(ctx.builder.CreateFreeze(UndefValue::get(lt)), strct);
if (tracked.count)
undef_derived_strct(ctx, strct, sty, ctx.tbaa().tbaa_stack);
}
Expand Down Expand Up @@ -4104,6 +4102,14 @@ static jl_cgval_t emit_new_struct(jl_codectx_t &ctx, jl_value_t *ty, size_t narg
}
}
}
if (promotion_point && nargs < nf) {
assert(!init_as_value);
IRBuilderBase::InsertPoint savedIP = ctx.builder.saveIP();
ctx.builder.SetInsertPoint(promotion_point);
promotion_point = cast<FreezeInst>(ctx.builder.CreateFreeze(UndefValue::get(lt)));
ctx.builder.CreateStore(promotion_point, strct);
ctx.builder.restoreIP(savedIP);
}
if (type_is_ghost(lt))
return mark_julia_const(ctx, sty->instance);
else if (init_as_value)
Expand Down
10 changes: 10 additions & 0 deletions test/compiler/codegen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -956,3 +956,13 @@ function foonopreds()
pkgid.uuid !== nothing ? pkgid.uuid : false
end
@test foonopreds() !== nothing

# issue 55396
struct Incomplete55396
x::Tuple{Int}
y::Int
@noinline Incomplete55396(x::Int) = new((x,))
end
let x = Incomplete55396(55396)
@test x.x === (55396,)
end

0 comments on commit ac9558c

Please sign in to comment.