Skip to content

Commit da96c50

Browse files
committed
Cover Metal exception allocation during Bool conversion
Use an opaque allocator in the Bool conversion regression so LLVM retains the heap-reference stores that exposed #904. The constant-null test allocator otherwise removes those stores before AIR lowering.
1 parent 33b39e7 commit da96c50

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

test/metal.jl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,6 +1557,38 @@ end
15571557
end
15581558
end
15591559

1560+
@testset "Bool conversion exception allocation" begin
1561+
mod = @eval module $(gensym())
1562+
using ..GPUCompiler
1563+
module Runtime
1564+
# Keep allocation visible to LLVM; a constant-null allocator erases
1565+
# the heap-reference stores which exposed #904.
1566+
malloc(sz) = ccall("extern test_malloc", llvmcall, Ptr{Nothing}, (Csize_t,), sz)
1567+
signal_exception() = return
1568+
report_oom(sz) = return
1569+
report_exception(ex) = return
1570+
report_exception_name(ex) = return
1571+
report_exception_frame(idx, func, file, line) = return
1572+
end
1573+
struct Params <: GPUCompiler.AbstractCompilerParams end
1574+
GPUCompiler.runtime_module(::CompilerJob{<:Any,Params}) = Runtime
1575+
function kernel(out, x)
1576+
unsafe_store!(out, Bool(x))
1577+
return
1578+
end
1579+
end
1580+
source = methodinstance(typeof(mod.kernel), Tuple{Core.LLVMPtr{Bool,1},Int},
1581+
Base.get_world_counter())
1582+
target = MetalCompilerTarget(; macos=v"12.2", metal=v"3.0", air=v"3.0")
1583+
job = CompilerJob(source, CompilerConfig(target, mod.Params(); kernel=true))
1584+
ir = sprint(io -> GPUCompiler.code_llvm(io, job; dump_module=true))
1585+
if VERSION >= v"1.12-"
1586+
@test occursin(r"store atomic .* unordered", ir)
1587+
end
1588+
air = sprint(io -> GPUCompiler.code_native(io, job; dump_module=true))
1589+
@test !occursin(r"(load|store) atomic", air)
1590+
end
1591+
15601592
@testset "unordered atomic demotion" begin
15611593
# Demote unordered LLVM loads/stores, but preserve stronger atomics.
15621594
Context() do ctx

0 commit comments

Comments
 (0)