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

Fixes for non-linearized cglobal #47068

Merged
merged 2 commits into from
Oct 6, 2022
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
4 changes: 4 additions & 0 deletions base/compiler/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ function stmt_effect_flags(lattice::AbstractLattice, @nospecialize(stmt), @nospe
nothrow = _builtin_nothrow(lattice, f, argtypes, rt)
return (true, nothrow, nothrow)
end
if f === Intrinsics.cglobal
# TODO: these are not yet linearized
return (false, false, false)
end
isa(f, Builtin) || return (false, false, false)
# Needs to be handled in inlining to look at the callee effects
f === Core._apply_iterate && return (false, false, false)
Expand Down
8 changes: 6 additions & 2 deletions base/compiler/ssair/verify.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ function check_op(ir::IRCode, domtree::DomTree, @nospecialize(op), use_bb::Int,
else
if !dominates(domtree, def_bb, use_bb) && !(bb_unreachable(domtree, def_bb) && bb_unreachable(domtree, use_bb))
# At the moment, we allow GC preserve tokens outside the standard domination notion
#@Base.show ir
@verify_error "Basic Block $def_bb does not dominate block $use_bb (tried to use value $(op.id))"
error("")
end
Expand All @@ -62,7 +61,6 @@ function check_op(ir::IRCode, domtree::DomTree, @nospecialize(op), use_bb::Int,
end
end
elseif isa(op, Union{OldSSAValue, NewSSAValue})
#@Base.show ir
@verify_error "Left over SSA marker"
error("")
elseif isa(op, Union{SlotNumber, TypedSlot})
Expand Down Expand Up @@ -245,6 +243,12 @@ function verify_ir(ir::IRCode, print::Bool=true, allow_frontend_forms::Bool=fals
(stmt.args[1] isa GlobalRef || (stmt.args[1] isa Expr && stmt.args[1].head === :static_parameter))
# a GlobalRef or static_parameter isdefined check does not evaluate its argument
continue
elseif stmt.head === :call
f = stmt.args[1]
if f isa GlobalRef && f.name === :cglobal
# TODO: these are not yet linearized
continue
end
end
end
n = 1
Expand Down
11 changes: 11 additions & 0 deletions test/compiler/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4233,3 +4233,14 @@ function unused_apply_iterate()
return nothing
end
@test fully_eliminated(unused_apply_iterate, ())

@testset "#45956: non-linearized cglobal needs special treatment for stmt effects" begin
function foo()
cglobal((a, ))
ccall(0, Cvoid, (Nothing,), b)
end
@test only(code_typed() do
cglobal((a, ))
ccall(0, Cvoid, (Nothing,), b)
end)[2] === Nothing
end
12 changes: 11 additions & 1 deletion test/compiler/ssair.jl
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,17 @@ let ci = make_ci([
])
ir = Core.Compiler.inflate_ir(ci)
ir = Core.Compiler.compact!(ir, true)
@test Core.Compiler.verify_ir(ir) == nothing
@test Core.Compiler.verify_ir(ir) === nothing
end

# Test that the verifier doesn't choke on cglobals (which aren't linearized)
let ci = make_ci([
Expr(:call, GlobalRef(Main, :cglobal),
Expr(:call, Core.tuple, :(:c)), Nothing),
Core.Compiler.ReturnNode()
])
ir = Core.Compiler.inflate_ir(ci)
@test Core.Compiler.verify_ir(ir) === nothing
end

# Test that GlobalRef in value position is non-canonical
Expand Down