Skip to content

Commit 91cdfb7

Browse files
wsmosesKristofferC
authored andcommitted
Fix partially_inline for unreachable (#56787)
(cherry picked from commit 9118ea7)
1 parent fa238ff commit 91cdfb7

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

base/meta.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,10 +365,15 @@ function _partially_inline!(@nospecialize(x), slot_replacements::Vector{Any},
365365
return x
366366
end
367367
if isa(x, Core.ReturnNode)
368+
# Unreachable doesn't have val defined
369+
if !isdefined(x, :val)
370+
return x
371+
else
368372
return Core.ReturnNode(
369373
_partially_inline!(x.val, slot_replacements, type_signature, static_param_values,
370374
slot_offset, statement_offset, boundscheck),
371375
)
376+
end
372377
end
373378
if isa(x, Core.GotoIfNot)
374379
return Core.GotoIfNot(

test/meta.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,4 +283,9 @@ ci = code_lowered(g, Tuple{Val{true}})[1]
283283
@test Meta.partially_inline!(copy(ci.code), Any[isdefined_globalref, 1], Tuple{typeof(isdefined_globalref), Int},
284284
[], 0, 0, :propagate)[1] == Expr(:isdefined, GlobalRef(Base, :foo))
285285

286+
withunreachable(s::String) = sin(s)
287+
ci = code_lowered(withunreachable, Tuple{String})[1]
288+
ci.code[end] = Core.ReturnNode()
289+
@test Meta.partially_inline!(copy(ci.code), Any[withunreachable, "foo"], Tuple{typeof(withunreachable), String},
290+
[], 0, 0, :propagate)[end] == Core.ReturnNode()
286291
end

0 commit comments

Comments
 (0)