Skip to content

Enzyme LLVM crash differentiating through NonlinearSolve on Julia 1.12 #877

@ChrisRackauckas-Claude

Description

@ChrisRackauckas-Claude

Problem

Enzyme.gradient through NonlinearSolve.solve crashes with Illegal inttoptr in LLVM's GC invariant verifier on Julia 1.12. This affects both explicit algorithms (NewtonRaphson()) and the default PolyAlgorithm. The NonlinearSolveBaseEnzymeExt extension loads correctly — the crash happens during Enzyme's LLVM code generation.

Note: Enzyme.gradient through LinearSolve.solve works fine on the same Julia version, so this is specific to NonlinearSolve.

MWE

using NonlinearSolve, Enzyme

f(u, p) = u .^ 2 .- p

function loss(p)
    prob = NonlinearProblem(f, [1.0], p)
    sol = solve(prob, NewtonRaphson())
    sum(sol.u)
end

# Crashes with: Illegal inttoptr
Enzyme.gradient(Enzyme.Reverse, loss, [2.0])

Stack trace (truncated)

Illegal inttoptr
	  %13 = inttoptr i64 %.unpack3 to ptr addrspace(10), !dbg !87

signal 6 (-6): Aborted
...
run at .../llvm-gc-invariant-verifier.cpp:196
...
post_optimize! at .../Enzyme/src/compiler/optimize.jl:454
_thunk at .../Enzyme/src/compiler.jl:6775
...
augmented_julia_loss_...wrap at ./none:0

Versions

Context

This was discovered while verifying the fix for #869 (polyalgorithm type inference). The inference fix (#870) resolves the MixedReturnException on Julia 1.10 where the Enzyme extension works. This issue tracks the separate LLVM-level crash on Julia 1.12.

🤖 Generated with Claude Code

Co-Authored-By: Chris Rackauckas accounts@chrisrackauckas.com

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions