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

Allow using ReturnNode() in @generated code #51715

Merged
merged 1 commit into from
Oct 16, 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
1 change: 1 addition & 0 deletions base/compiler/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ function find_ssavalue_uses(body::Vector{Any}, nvals::Int)
for line in 1:length(body)
e = body[line]
if isa(e, ReturnNode)
isdefined(e, :val) || continue
e = e.val
elseif isa(e, GotoIfNot)
e = e.cond
Expand Down
29 changes: 29 additions & 0 deletions test/staged.jl
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,32 @@ let world = Base.get_world_counter()
@test all(lin->lin.method === :sin, src.linetable)
@test sin_generated(42) == sin(42)
end

# Allow passing unreachable insts in generated codeinfo
let
dummy() = return
dummy_m = which(dummy, Tuple{})

src = Base.uncompressed_ir(dummy_m)
src.code = Any[
# block 1
Core.ReturnNode(nothing),
# block 2
Core.ReturnNode(),
]
nstmts = length(src.code)
nslots = 1
src.ssavaluetypes = nstmts
src.codelocs = fill(Int32(1), nstmts)
src.ssaflags = fill(Int32(0), nstmts)
src.slotflags = fill(0, nslots)
src.slottypes = Any[Any]

@eval function f_unreachable()
$(Expr(:meta, :generated, Returns(src)))
$(Expr(:meta, :generated_only))
end

ir, _ = Base.code_ircode(f_unreachable, ()) |> only
@test length(ir.cfg.blocks) == 1
end