From b761098630d3135a073773599acd54ef48ca85db Mon Sep 17 00:00:00 2001 From: Martin Holters Date: Thu, 18 Aug 2022 21:24:27 +0200 Subject: [PATCH] Handle `PhiNode` with `edge==0` (#46388) (cherry picked from commit fd66c303cc3f6e80f5b1d42837fa9f5cae927a06) --- base/compiler/ssair/legacy.jl | 2 +- test/compiler/inference.jl | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/base/compiler/ssair/legacy.jl b/base/compiler/ssair/legacy.jl index 1fa847734359b..584eff4ebc898 100644 --- a/base/compiler/ssair/legacy.jl +++ b/base/compiler/ssair/legacy.jl @@ -59,7 +59,7 @@ function replace_code_newstyle!(ci::CodeInfo, ir::IRCode, nargs::Int) elseif isa(stmt, GotoIfNot) stmt = GotoIfNot(stmt.cond, first(ir.cfg.blocks[stmt.dest].stmts)) elseif isa(stmt, PhiNode) - stmt = PhiNode(Int32[last(ir.cfg.blocks[edge].stmts) for edge in stmt.edges], stmt.values) + stmt = PhiNode(Int32[edge == 0 ? 0 : last(ir.cfg.blocks[edge].stmts) for edge in stmt.edges], stmt.values) elseif isa(stmt, Expr) && stmt.head === :enter stmt.args[1] = first(ir.cfg.blocks[stmt.args[1]::Int].stmts) end diff --git a/test/compiler/inference.jl b/test/compiler/inference.jl index 9238ce65475f5..8ed8b7c1926f9 100644 --- a/test/compiler/inference.jl +++ b/test/compiler/inference.jl @@ -3090,3 +3090,15 @@ end f41908(x::Complex{T}) where {String<:T<:String} = 1 g41908() = f41908(Any[1][1]) @test only(Base.return_types(g41908, ())) <: Int + +# issue #45600 +@test only(code_typed() do + while true + x = try finally end + end +end)[2] == Union{} +@test only(code_typed() do + while true + @time 1 + end +end)[2] == Union{}