Skip to content

LLVM GC invariant violation (Illegal inttoptr) with in-place NonlinearProblem on Julia 1.12 #3012

@ChrisRackauckas-Claude

Description

@ChrisRackauckas-Claude

Description

Enzyme.gradient through a NonlinearProblem with an in-place function f!(residual, u, p) causes an LLVM abort due to Illegal inttoptr in the GC invariant verifier on Julia 1.12. On Julia 1.10, the same code works.

The crash occurs during Enzyme's code generation for the augmented_primal rule in NonlinearSolveBaseEnzymeExt. Simplified in-place functions without NonlinearSolve work fine, so the bug is triggered by the specific code patterns in NonlinearSolve's Enzyme extension interacting with Enzyme's LLVM passes.

MWE (NonlinearSolve + Enzyme, no MTK)

import Pkg
Pkg.activate(; temp = true)
Pkg.add(["Enzyme", "NonlinearSolve", "SciMLSensitivity"])

using NonlinearSolve, Enzyme, SciMLSensitivity

function f!(residual, u, p)
    residual .= u .^ 2 .- p
end

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

println("Forward: ", loss_inplace([2.0]))

# Crashes on Julia 1.12, works on Julia 1.10
Enzyme.gradient(Enzyme.set_runtime_activity(Enzyme.Reverse), loss_inplace, [2.0])

Error (Julia 1.12.4)

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

signal 6 (-6): Aborted

Full crash trace shows the abort originates in llvm-gc-invariant-verifier.cpp:196 during LLVMRunJuliaPasses, called from Enzyme's post_optimize!_thunkcached_compilation.

Notes

  • Works on Julia 1.10 with same package versions
  • Simplified in-place code (hand-written Newton iteration without NonlinearSolve) works fine on Julia 1.12 — the crash is specific to Enzyme processing the NonlinearSolveBaseEnzymeExt augmented_primal/reverse rules
  • Out-of-place f(u, p) with NonlinearSolve works on both Julia versions

Environment

  • Julia 1.12.4 (linux x64)
  • Enzyme v0.13.132
  • NonlinearSolve v4.16.0
  • SciMLSensitivity v7.99.0

Context

From investigation in SciML/SciMLSensitivity.jl#1358 (comment)

🤖 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
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions