Skip to content

Commit

Permalink
Fix interpreter_exec.jl test
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Keno committed Feb 6, 2024
1 parent a26bd7f commit b8243b3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
4 changes: 4 additions & 0 deletions base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,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])

Expand Down
10 changes: 4 additions & 6 deletions test/compiler/interpreter_exec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b8243b3

Please sign in to comment.