Skip to content

Commit f21fac3

Browse files
committed
verify that our check works
1 parent 5967598 commit f21fac3

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
error: using the autodiff feature requires using fat-lto.
2+
3+
error: aborting due to 1 previous error
4+

tests/ui/autodiff/incorrect_usage.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//@ needs-enzyme
2+
//@ no-prefer-dynamic
3+
//@ revisions: with_lto no_lto
4+
//@[with_lto] compile-flags: -Zautodiff=Enable -C opt-level=3 -Clto=fat
5+
//@[no_lto] compile-flags: -Zautodiff=Enable -C opt-level=3 -Clto=thin
6+
7+
#![feature(autodiff)]
8+
//@[no_lto] build-fail
9+
//@[with_lto] build-pass
10+
11+
// Autodiff requires users to enable lto=fat (for now).
12+
// In the past, autodiff did not run if users forget to enable fat-lto, which caused functions to
13+
// returning zero-derivatives. That's obviously wrong and confusing to users. We now added a check
14+
// which will abort compilation instead.
15+
16+
use std::autodiff::autodiff_reverse;
17+
//[no_lto]~? ERROR using the autodiff feature requires using fat-lto.
18+
19+
#[autodiff_reverse(d_square, Duplicated, Active)]
20+
fn square(x: &f64) -> f64 {
21+
*x * *x
22+
}
23+
24+
fn main() {
25+
let xf64: f64 = std::hint::black_box(3.0);
26+
27+
let mut df_dxf64: f64 = std::hint::black_box(0.0);
28+
29+
let _output_f64 = d_square(&xf64, &mut df_dxf64, 1.0);
30+
assert_eq!(6.0, df_dxf64);
31+
}

0 commit comments

Comments
 (0)