From 78ee2569de01a5f0954a2f76869d19b9c1d628de Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Thu, 1 Feb 2024 19:53:40 +0000 Subject: [PATCH] Fix interpreter_exec.jl test This test was supposed to check that we correctly handled PhiNodes in uninferred code in both the interpreter and the compiler. However, the compiler path wasn't actually exercised, because the `inferred=true` part of this forced it to be skipped. Drop that and fix the exposed issues in the compiler where we didn't handle PhiNodes properly. --- base/compiler/abstractinterpretation.jl | 4 ++++ base/compiler/optimize.jl | 2 +- test/compiler/interpreter_exec.jl | 10 ++++------ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/base/compiler/abstractinterpretation.jl b/base/compiler/abstractinterpretation.jl index 2b736dbeff9d8..ad07e68151d8f 100644 --- a/base/compiler/abstractinterpretation.jl +++ b/base/compiler/abstractinterpretation.jl @@ -3304,6 +3304,10 @@ function typeinf_local(interp::AbstractInterpreter, frame::InferenceState) end if rt === Bottom ssavaluetypes[currpc] = Bottom + # Special case: Union typed PhiNodes do not error (but must also be unused) + if isa(stmt, PhiNode) + continue + end @goto find_next_bb end if changes !== nothing diff --git a/base/compiler/optimize.jl b/base/compiler/optimize.jl index f634fc0bcb7e4..cbe80a65fc607 100644 --- a/base/compiler/optimize.jl +++ b/base/compiler/optimize.jl @@ -1086,7 +1086,7 @@ function convert_to_ircode(ci::CodeInfo, sv::OptimizationState) idx += 1 prevloc = codeloc end - if ssavaluetypes[idx] === Union{} && !(oldidx in sv.unreachable) + if ssavaluetypes[idx] === Union{} && !(oldidx in sv.unreachable) && !isa(code[idx], PhiNode) # We should have converted any must-throw terminators to an equivalent w/o control-flow edges @assert !isterminator(code[idx]) diff --git a/test/compiler/interpreter_exec.jl b/test/compiler/interpreter_exec.jl index ce0704be15178..2e5fa09dd9a9e 100644 --- a/test/compiler/interpreter_exec.jl +++ b/test/compiler/interpreter_exec.jl @@ -20,10 +20,9 @@ let m = Meta.@lower 1 + 1 ReturnNode(SSAValue(6)), ] nstmts = length(src.code) - src.ssavaluetypes = Any[ Any for _ = 1:nstmts ] + src.ssavaluetypes = nstmts src.ssaflags = fill(UInt8(0x00), nstmts) src.codelocs = fill(Int32(1), nstmts) - src.inferred = true Core.Compiler.verify_ir(Core.Compiler.inflate_ir(src)) global test29262 = true @test :a === @eval $m @@ -61,13 +60,13 @@ let m = Meta.@lower 1 + 1 ReturnNode(SSAValue(18)), ] nstmts = length(src.code) - src.ssavaluetypes = Any[ Any for _ = 1:nstmts ] + src.ssavaluetypes = nstmts src.ssaflags = fill(UInt8(0x00), nstmts) src.codelocs = fill(Int32(1), nstmts) - src.inferred = true Core.Compiler.verify_ir(Core.Compiler.inflate_ir(src)) global test29262 = true @test (:b, :a, :c, :c) === @eval $m + src.ssavaluetypes = nstmts global test29262 = false @test (:b, :a, :c, :b) === @eval $m end @@ -98,10 +97,9 @@ let m = Meta.@lower 1 + 1 ReturnNode(SSAValue(11)), ] nstmts = length(src.code) - src.ssavaluetypes = Any[ Any for _ = 1:nstmts ] + src.ssavaluetypes = nstmts src.ssaflags = fill(UInt8(0x00), nstmts) src.codelocs = fill(Int32(1), nstmts) - src.inferred = true Core.Compiler.verify_ir(Core.Compiler.inflate_ir(src)) global test29262 = true @test :a === @eval $m