Skip to content

Commit ac9558c

Browse files
authored
codegen: move undef freeze before promotion point (#55428)
Fixes #55396
1 parent e7e8768 commit ac9558c

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/cgutils.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3947,8 +3947,6 @@ static jl_cgval_t emit_new_struct(jl_codectx_t &ctx, jl_value_t *ty, size_t narg
39473947
else {
39483948
strct = emit_static_alloca(ctx, lt);
39493949
setName(ctx.emission_context, strct, arg_typename);
3950-
if (nargs < nf)
3951-
promotion_point = ctx.builder.CreateStore(ctx.builder.CreateFreeze(UndefValue::get(lt)), strct);
39523950
if (tracked.count)
39533951
undef_derived_strct(ctx, strct, sty, ctx.tbaa().tbaa_stack);
39543952
}
@@ -4104,6 +4102,14 @@ static jl_cgval_t emit_new_struct(jl_codectx_t &ctx, jl_value_t *ty, size_t narg
41044102
}
41054103
}
41064104
}
4105+
if (promotion_point && nargs < nf) {
4106+
assert(!init_as_value);
4107+
IRBuilderBase::InsertPoint savedIP = ctx.builder.saveIP();
4108+
ctx.builder.SetInsertPoint(promotion_point);
4109+
promotion_point = cast<FreezeInst>(ctx.builder.CreateFreeze(UndefValue::get(lt)));
4110+
ctx.builder.CreateStore(promotion_point, strct);
4111+
ctx.builder.restoreIP(savedIP);
4112+
}
41074113
if (type_is_ghost(lt))
41084114
return mark_julia_const(ctx, sty->instance);
41094115
else if (init_as_value)

test/compiler/codegen.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,3 +956,13 @@ function foonopreds()
956956
pkgid.uuid !== nothing ? pkgid.uuid : false
957957
end
958958
@test foonopreds() !== nothing
959+
960+
# issue 55396
961+
struct Incomplete55396
962+
x::Tuple{Int}
963+
y::Int
964+
@noinline Incomplete55396(x::Int) = new((x,))
965+
end
966+
let x = Incomplete55396(55396)
967+
@test x.x === (55396,)
968+
end

0 commit comments

Comments
 (0)