Skip to content

Commit a3243a0

Browse files
authored
optimizer: add missing bounds checks to avoid ICE (#41048)
Fixes #40804
1 parent 33fa18b commit a3243a0

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

base/compiler/ssair/passes.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ function getfield_elim_pass!(ir::IRCode)
571571
elseif is_known_call(stmt, isa, compact)
572572
# TODO
573573
continue
574-
elseif is_known_call(stmt, typeassert, compact)
574+
elseif is_known_call(stmt, typeassert, compact) && length(stmt.args) == 3
575575
# Canonicalize
576576
# X = typeassert(Y, T)::S
577577
# into
@@ -592,7 +592,7 @@ function getfield_elim_pass!(ir::IRCode)
592592
compact.result[idx][:line]), true)
593593
compact.ssa_rename[compact.idx-1] = pi
594594
continue
595-
elseif is_known_call(stmt, (===), compact)
595+
elseif is_known_call(stmt, (===), compact) && length(stmt.args) == 3
596596
c1 = compact_exprtype(compact, stmt.args[2])
597597
c2 = compact_exprtype(compact, stmt.args[3])
598598
if !(isa(c1, Const) || isa(c2, Const))

test/compiler/inference.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3313,3 +3313,7 @@ end |> first === Tuple{Int, String}
33133313

33143314
# issue #40742
33153315
@test Base.return_types(string, (Vector{Tuple{:x}},)) == Any[String]
3316+
3317+
# issue #40804
3318+
@test Base.return_types(()) do; ===(); end == Any[Union{}]
3319+
@test Base.return_types(()) do; typeassert(); end == Any[Union{}]

0 commit comments

Comments
 (0)