rust-lang / rust-lang/rust

ICE: autodiff_reverse crashes in Enzyme's invertPointerM on Active reference/pointer parameters

Open
#159,267 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug F-autodiff I-ICE needs-triage requires-nightly
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
#![feature(autodiff)]
use std::autodiff::autodiff_reverse;

#[autodiff_reverse(df, Active, Active, Active)]
fn f<'a>(x: &'a f32, y: &'a f32) -> f32 {
    *x * *y
}

fn main() {
    let x = 3.0;
    let y = 4.0;
    let (val, dx, dy) = df(&x, &y, 1.0);
    println!("val: {}, dx: {}, dy: {}", val, *dx, *dy);
}

Build command:

rustc -Z autodiff=Enable -C lto=fat test_references.rs

Differentiating a function that takes reference (&f32) or pointer (*mut f32/*const f32) parameters marked Active in reverse mode crashes the compiler during LLVM/Enzyme codegen, rather than producing a diagnostic. The activity model appears to expect Duplicated (a caller-provided shadow pointer) for reference/pointer-typed parameters rather than Active (gradient returned by value) — using Duplicated instead of Active for the same function compiles and runs correctly, producing the right gradient. So this looks like a case where an unsupported-but-plausible activity choice should produce a clean error rather than an ICE.

Meta

rustc --version --verbose:

rustc 1.99.0-nightly (daf2e5e18 2026-07-13)
host: x86_64-unknown-linux-gnu (WSL2 Ubuntu)

Built with rustup component add rustc-dev llvm-tools-preview enzyme on the same nightly, -Z autodiff=Enable -C lto=fat.

Error output
rustc: /checkout/src/tools/enzyme/enzyme/Enzyme/GradientUtils.cpp:6654: Value *GradientUtils::invertPointerM(Value *const, IRBuilder<> &, TypeTree): Assertion `0 && "cannot find deal with ptr that isnt arg"' failed.
Full crash context
oval=ptr %1 icv=0
rustc: /checkout/src/tools/enzyme/enzyme/Enzyme/GradientUtils.cpp:6654: Value *GradientUtils::invertPointerM(Value *const, IRBuilder<> &, TypeTree): Assertion `0 && "cannot find deal with ptr that isnt arg"' failed.
Suggested fix direction

Detect Active activity on reference/pointer-typed parameters in reverse mode before reaching the Enzyme/LLVM codegen boundary, and emit a diagnostic suggesting Duplicated instead (with a shadow-parameter example), rather than asserting inside Enzyme's GradientUtils::invertPointerM.

I wrote a small third-party static checker (ad-safety, MIR-level rustc_private lint) that catches this pattern at compile time with a suggestion to use Duplicated, in case the reproducer or approach is useful: https://github.com/sangmorg1-debug/ad-safety

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied Rust reproducer and build command, then trace reverse-mode autodiff activity handling up to the Enzyme/LLVM codegen boundary. Compare the failing Active reference/pointer case with the working Duplicated case and inspect Enzyme's GradientUtils::invertPointerM context. Done means an unsupported Active parameter produces a clear diagnostic suggesting Duplicated instead of an ICE.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.