Skip to content

Commit

Permalink
optimizer: add missing bounds checks to avoid ICE (#41048)
Browse files Browse the repository at this point in the history
Fixes #40804

(cherry picked from commit a3243a0)
  • Loading branch information
vtjnash authored and staticfloat committed Dec 22, 2022
1 parent a347511 commit 2437a57
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 @@ -537,7 +537,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 @@ -557,7 +557,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 @@ -2990,3 +2990,7 @@ f28971() = (1, [2,3]...)::Tuple{Int,Int,Int}
let f() = sin{Int}()
@test Base.return_types(f, ()) == Any[Union{}]
end

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

0 comments on commit 2437a57

Please sign in to comment.