GC segfault with `OverrideBCMaterialize`
- Dominant language
- Julia
- Stars
- 586
- Forks
- 108
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 44
Description
This needs to be run with 2 or more threads. It's also non-deterministic, so sometimes it will work (but not often in my experience)
```julia
import Enzyme
@assert Threads.nthreads() > 1
struct ScalMat{T}
dim::Int
value::T
end
function invquad(a::ScalMat, x::AbstractVector)
a.dim == size(x, 1) || throw(DimensionMismatch("Inconsistent argument dimensions.")) # This is necessary
return sum(abs2, x) * a.value
end
sqmahal(a, μ, x) = invquad(a, x .- μ)
function f(μ)
total = 0.0
for _ in 1:10
total += sqmahal(ScalMat(2, 1.0), μ, ones(2))
end
return total
end
tasks = [Threads.@spawn begin
μ, dμ = randn(2), zeros(2)
for _ in 1:50_000
fill!(dμ, 0.0)
Enzyme.autodiff(Enzyme.Reverse, f, Enzyme.Active, Enzyme.Duplicated(μ, dμ))
end
end for _ in 1:2]
fetch.(tasks)
```
~~I am currently trying to get Claude to minimise it further but idk if I will have enough tokens, will report back if it gets anywhere.~~ Minimised now.
The errors vary quite a bit (unsurprisingly). It's usually not very informative, but you can run it again and again until you get this backtrace:
```julia
[28448] signal 11 (2): Segmentation fault: 11
in expression starting at /Users/pysm/jl/enzyme_mwe_nodeps.jl:29
gc_mark_obj8 at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/builder-honeycrisp-R17H3W25T9.1/019ebd63-635e-4155-b60a-9d2815900786/trusted/build/builder-honeycrisp-R17H3W25T9-1/julialang/julia-ci/src/gc-stock.c:0 [inlined]
gc_mark_outrefs at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/builder-honeycrisp-R17H3W25T9.1/019ebd63-635e-4155-b60a-9d2815900786/trusted/build/builder-honeycrisp-R17H3W25T9-1/julialang/julia-ci/src/gc-stock.c:2468 [inlined]
gc_mark_and_steal at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/builder-honeycrisp-R17H3W25T9.1/019ebd63-635e-4155-b60a-9d2815900786/trusted/build/builder-honeycrisp-R17H3W25T9-1/julialang/julia-ci/src/gc-stock.c:2572
gc_mark_loop_parallel at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/builder-honeycrisp-R17H3W25T9.1/019ebd63-635e-4155-b60a-9d2815900786/trusted/build/builder-honeycrisp-R17H3W25T9-1/julialang/julia-ci/src/gc-stock.c:2719 [inlined]
gc_mark_loop at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/builder-honeycrisp-R17H3W25T9.1/019ebd63-635e-4155-b60a-9d2815900786/trusted/build/builder-honeycrisp-R17H3W25T9-1/julialang/julia-ci/src/gc-stock.c:2738
_jl_gc_collect at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/builder-honeycrisp-R17H3W25T9.1/019ebd63-635e-4155-b60a-9d2815900786/trusted/build/builder-honeycrisp-R17H3W25T9-1/julialang/julia-ci/src/gc-stock.c:3079
ijl_gc_collect at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/builder-honeycrisp-R17H3W25T9.1/019ebd63-635e-4155-b60a-9d2815900786/trusted/build/builder-honeycrisp-R17H3W25T9-1/julialang/julia-ci/src/gc-stock.c:3480
maybe_collect at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/builder-honeycrisp-R17H3W25T9.1/019ebd63-635e-4155-b60a-9d2815900786/trusted/build/builder-honeycrisp-R17H3W25T9-1/julialang/julia-ci/src/gc-stock.c:351 [inlined]
jl_gc_small_alloc_inner at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/builder-honeycrisp-R17H3W25T9.1/019ebd63-635e-4155-b60a-9d2815900786/trusted/build/builder-honeycrisp-R17H3W25T9-1/julialang/julia-ci/src/gc-stock.c:727 [inlined]
ijl_gc_small_alloc at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/builder-honeycrisp-R17H3W25T9.1/019ebd63-635e-4155-b60a-9d2815900786/trusted/build/builder-honeycrisp-R17H3W25T9-1/julialang/julia-ci/src/gc-stock.c:776
GenericMemory at ./boot.jl:588 [inlined]
Array at ./boot.jl:647 [inlined]
Array at ./boot.jl:660 [inlined]
ones at ./array.jl:595 [inlined]
ones at ./array.jl:592 [inlined]
ones at ./array.jl:590 [inlined]
f at /Users/pysm/jl/enzyme_mwe_nodeps.jl:17 [inlined]
diffejulia_f_3017wrap at /Users/pysm/jl/enzyme_mwe_nodeps.jl:0
macro expansion at /Users/pysm/.julia/packages/Enzyme/OvStQ/src/compiler.jl:7109 [inlined]
enzyme_call at /Users/pysm/.julia/packages/Enzyme/OvStQ/src/compiler.jl:6575 [inlined]
CombinedAdjointThunk at /Users/pysm/.julia/packages/Enzyme/OvStQ/src/compiler.jl:6457 [inlined]
autodiff at /Users/pysm/.julia/packages/Enzyme/OvStQ/src/Enzyme.jl:539 [inlined]
autodiff at /Users/pysm/.julia/packages/Enzyme/OvStQ/src/Enzyme.jl:560 [inlined]
#5 at /Users/pysm/jl/enzyme_mwe_nodeps.jl:26
unknown function (ip: 0x1310bc1a7) at (unknown file)
jl_apply at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/builder-honeycrisp-R17H3W25T9.1/019ebd63-635e-4155-b60a-9d2815900786/trusted/build/builder-honeycrisp-R17H3W25T9-1/julialang/julia-ci/src/julia.h:2394 [inlined]
start_task at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/builder-honeycrisp-R17H3W25T9.1/019ebd63-635e-4155-b60a-9d2815900786/trusted/build/builder-honeycrisp-R17H3W25T9-1/julialang/julia-ci/src/task.c:1253
Allocations: 22387615 (Pool: 22387396; Big: 219); GC: 25
Segmentation fault: 11 julia "${args[@]}" "$@"
```
Versioninfo:
```julia
julia> versioninfo()
Julia Version 1.12.7
Commit 6d172b025e4 (2026-08-15 08:05 UTC)
Build Info:
Official https://julialang.org release
Platform Info:
OS: macOS (arm64-apple-darwin25.5.0)
CPU: 15 × Apple M5 Pro
WORD_SIZE: 64
LLVM: libLLVM-18.1.7 (ORCJIT, apple-m1)
GC: Built with stock GC
Threads: 2 default, 1 interactive, 2 GC (on 5 virtual cores)
```
Contributor guide
Assessment
This issue has not been assessed yet.