From 9415a79dffd77501d2c25be4ee4da71d0f6c335c Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Thu, 24 Sep 2026 18:41:21 +0200 Subject: [PATCH] Expand Julia's atomic modify pseudo-intrinsic. From Julia 1.13, codegen emits atomic modifications (e.g. `@atomic x.f += 1`) as calls to `julia.atomicmodify`, which Julia's pipeline expands after GC lowering with `ExpandAtomicModifyPass` (JuliaLang/julia#57010). Our pipeline didn't, so the call survived and failed validation as a call to an unknown function. --- src/optim.jl | 6 ++++++ test/native.jl | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/optim.jl b/src/optim.jl index 932f316bf..3c1d64087 100644 --- a/src/optim.jl +++ b/src/optim.jl @@ -365,6 +365,12 @@ function buildIntrinsicLoweringPipeline(mpm, @nospecialize(job::CompilerJob), op if uses_julia_runtime(job) && VERSION >= v"1.11.0-DEV.208" add!(fpm, FinalLowerGCPass()) end + # codegen emits atomic modifications (e.g. `@atomic x.f += 1`) as calls to the + # `julia.atomicmodify` pseudo-intrinsic, which Julia expands after GC lowering + # (JuliaLang/julia#57010) + @static if VERSION >= v"1.13.0-DEV.321" + add!(fpm, ExpandAtomicModifyPass()) + end end if uses_julia_runtime(job) && VERSION < v"1.11.0-DEV.208" add!(mpm, FinalLowerGCPass()) diff --git a/test/native.jl b/test/native.jl index 9b2a61b3b..b5323661d 100644 --- a/test/native.jl +++ b/test/native.jl @@ -765,6 +765,25 @@ end end end +@testset "atomic field modifications" begin + # from Julia 1.13, `@atomic x.f += 1` is a call to the `julia.atomicmodify` + # pseudo-intrinsic, which has to be expanded (JuliaLang/julia#57010) + mod = @eval module $(gensym()) + mutable struct Counter + @atomic n::Int + end + function increment(c::Counter) + @atomic c.n += 1 + return + end + end + + @test @filecheck implicit_check_not=["julia.atomicmodify"] begin + @check "{{atomicrmw add|cmpxchg}}" + Native.code_llvm(mod.increment, Tuple{mod.Counter}) + end +end + @testset "tracked pointers" begin mod = @eval module $(gensym()) function kernel(a)