Skip to content

Commit 5c1742a

Browse files
committed
Initialize the union selector of undefined upsilon nodes
While we're guaranteed never to look at undefined values, we're not guaranteed that the type information can't change, which in the case of a union generates code to change the layout. As a result, we need to make sure to have the union selectors be valid (the actual data will be junk and no semantic operation will ever look at it, but it shouldn't be ouf of bounds). Ref #29152
1 parent 80820ac commit 5c1742a

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/codegen.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6184,10 +6184,18 @@ static std::unique_ptr<Module> emit_function(
61846184
// If the val is null, we can ignore the store.
61856185
// The middle end guarantees that the value from this
61866186
// upsilon node is not dynamically observed.
6187+
jl_varinfo_t &vi = ctx.phic_slots[upsilon_to_phic[cursor+1]];
61876188
if (val) {
61886189
jl_cgval_t rval_info = emit_expr(ctx, val);
6189-
jl_varinfo_t &vi = ctx.phic_slots[upsilon_to_phic[cursor+1]];
61906190
emit_varinfo_assign(ctx, vi, rval_info);
6191+
} else if (vi.pTIndex) {
6192+
// We don't care what the contents of the variable are, but it
6193+
// does need to satisfy the union invariants (i.e. inbounds
6194+
// tindex).
6195+
ctx.builder.CreateStore(
6196+
vi.boxroot ? ConstantInt::get(T_int8, 0x80) :
6197+
ConstantInt::get(T_int8, 0x01),
6198+
vi.pTIndex, true);
61916199
}
61926200
find_next_stmt(cursor + 1);
61936201
continue;

test/core.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6794,3 +6794,14 @@ let a = [1,2,3,4,missing,6,7]
67946794
foo(x) = x > 0 ? x : missing
67956795
@test_throws TypeError foo(missing)
67966796
end
6797+
6798+
# issue #29152
6799+
function f29152()
6800+
try
6801+
g29152()
6802+
finally
6803+
end
6804+
end
6805+
g29152() = (_true29152 ? error() : _true29152 ? 0 : false)
6806+
_true29152 = true;
6807+
@test_throws ErrorException f29152()

0 commit comments

Comments
 (0)