Skip to content

Commit 7c33927

Browse files
committed
Fix condition for unreachable code in IRCode conversion
This is a partial back-port of JuliaLang#50924, where we discovered that the optimizer would ignore: 1. must-throw `%XX = SlotNumber(_)` statements 2. must-throw `goto #bb if not %x` statements when re-building the CFG during IRCode conversion. This is mostly harmless, except that in the case of (1) we can accidentally fall through the statically deleted (`Const()`-wrapped) code from inference and observe a control-flow edge that never should have existed, such as an edge into a catch block. Such an edge is invalid semantically and breaks our SSA conversion. This one-line change fixes (1) but not (2), which is enough for IR validity. We should follow-up with a tweak to `compute_basic_blocks` to enforce this requirement.
1 parent 7790d6f commit 7c33927

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

base/compiler/optimize.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ function convert_to_ircode(ci::CodeInfo, sv::OptimizationState)
561561
idx += 1
562562
prevloc = codeloc
563563
end
564-
if code[idx] isa Expr && ssavaluetypes[idx] === Union{}
564+
if ssavaluetypes[idx] === Union{} && !(code[idx] isa Core.Const)
565565
if !(idx < length(code) && isa(code[idx + 1], ReturnNode) && !isdefined((code[idx + 1]::ReturnNode), :val))
566566
# insert unreachable in the same basic block after the current instruction (splitting it)
567567
insert!(code, idx + 1, ReturnNode())

0 commit comments

Comments
 (0)