Skip to content

Commit

Permalink
optimizer: add missing bounds checks to avoid ICE
Browse files Browse the repository at this point in the history
Fixes #40804
  • Loading branch information
vtjnash committed Jun 1, 2021
1 parent 58ffe7e commit a474530
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions base/compiler/ssair/passes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ function getfield_elim_pass!(ir::IRCode)
elseif is_known_call(stmt, isa, compact)
# TODO
continue
elseif is_known_call(stmt, typeassert, compact)
elseif is_known_call(stmt, typeassert, compact) && length(stmt.args) == 3
# Canonicalize
# X = typeassert(Y, T)::S
# into
Expand All @@ -592,7 +592,7 @@ function getfield_elim_pass!(ir::IRCode)
compact.result[idx][:line]), true)
compact.ssa_rename[compact.idx-1] = pi
continue
elseif is_known_call(stmt, (===), compact)
elseif is_known_call(stmt, (===), compact) && length(stmt.args) == 3
c1 = compact_exprtype(compact, stmt.args[2])
c2 = compact_exprtype(compact, stmt.args[3])
if !(isa(c1, Const) || isa(c2, Const))
Expand Down
4 changes: 4 additions & 0 deletions test/compiler/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3313,3 +3313,7 @@ end |> first === Tuple{Int, String}

# issue #40742
@test Base.return_types(string, (Vector{Tuple{:x}},)) == Any[String]

# issue #40804
@test Base.return_types(()) do; ===(); end == Any[Union{}]
@test Base.return_types(()) do; typeassert(); end == Any[Union{}]

0 comments on commit a474530

Please sign in to comment.