Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

irinterp: Don't introduce invalid CFGs #49797

Merged
merged 1 commit into from
May 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions base/compiler/ssair/irinterp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,19 @@ function _ir_abstract_constant_propagation(interp::AbstractInterpreter, irsv::IR
inst = ir.stmts[idx][:inst]
typ = ir.stmts[idx][:type]
end
if idx == lstmt
process_terminator!(ir, inst, idx, bb, all_rets, bb_ip) && @goto residual_scan
(isa(inst, GotoNode) || isa(inst, GotoIfNot) || isa(inst, ReturnNode) || isexpr(inst, :enter)) && continue
end
if typ === Bottom && !isa(inst, PhiNode)
if typ === Bottom && !(isa(inst, PhiNode) || isa(inst, GotoNode) || isa(inst, GotoIfNot) || isa(inst, ReturnNode) || isexpr(inst, :enter))
kill_terminator_edges!(irsv, lstmt, bb)
if idx != lstmt
for idx2 in (idx+1:lstmt-1)
ir[SSAValue(idx2)] = nothing
end
ir[SSAValue(lstmt)][:inst] = ReturnNode()
end
break
end
if idx == lstmt
process_terminator!(ir, inst, idx, bb, all_rets, bb_ip) && @goto residual_scan
end
end
end
@goto compute_rt
Expand Down
10 changes: 8 additions & 2 deletions base/compiler/ssair/verify.jl
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,14 @@ function verify_ir(ir::IRCode, print::Bool=true,
end
isa(stmt, PhiNode) || break
end
@verify_error "Block $idx successors ($(block.succs)), does not match fall-through terminator ($terminator)"
error("")
if isempty(block.succs) && ir.stmts[idx][:type] == Union{}
# Allow fallthrough terminators that are known to error to
# be removed from the CFG. Ideally we'd add an unreachable
# here, but that isn't always possible.
else
@verify_error "Block $idx successors ($(block.succs)), does not match fall-through terminator ($terminator)"
error("")
end
end
end
end
Expand Down