Skip to content

Commit

Permalink
Initializer the union selector of undefined upsilon nodes
Browse files Browse the repository at this point in the history
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).

Fixes #29152
  • Loading branch information
Keno committed Sep 12, 2018
1 parent c2b61df commit 8c22e94
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6142,10 +6142,18 @@ static std::unique_ptr<Module> emit_function(
// If the val is null, we can ignore the store.
// The middle end guarantees that the value from this
// upsilon node is not dynamically observed.
jl_varinfo_t &vi = ctx.phic_slots[upsilon_to_phic[cursor+1]];
if (val) {
jl_cgval_t rval_info = emit_expr(ctx, val);
jl_varinfo_t &vi = ctx.phic_slots[upsilon_to_phic[cursor+1]];
emit_varinfo_assign(ctx, vi, rval_info);
} else if (vi.pTIndex) {
// We don't care what the contents of the variable are, but it
// does need to satisfy the union invariants (i.e. inbounds
// tindex).
ctx.builder.CreateStore(
vi.boxroot ? ConstantInt::get(T_int8, 0x80) :
ConstantInt::get(T_int8, 0x01),
vi.pTIndex, true);
}
find_next_stmt(cursor + 1);
continue;
Expand Down
11 changes: 11 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6706,3 +6706,14 @@ end
# issue #28812
@test Tuple{Vararg{Array{T},3} where T} === Tuple{Array,Array,Array}
@test Tuple{Vararg{Array{T} where T,3}} === Tuple{Array,Array,Array}

# issue #29152
function f29152()
try
g29152()
finally
end
end
g29152() = (_true29152 ? error() : _true29152 ? 0 : false)
_true29152 = true;
@test_throws ErrorException f29152()

0 comments on commit 8c22e94

Please sign in to comment.