Skip to content

Commit a1e70ac

Browse files
committed
add empty struct ret testcase
1 parent 98d754d commit a1e70ac

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//@ compile-flags: -Zautodiff=Enable,NoTT,NoPostopt -C no-prepopulate-passes -C opt-level=3 -Clto=fat
2+
//@ no-prefer-dynamic
3+
//@ needs-enzyme
4+
5+
#![feature(autodiff)]
6+
use std::autodiff::*;
7+
8+
// Usually we would store the return value of the differentiated function.
9+
// However, if the return type is void or an empty struct,
10+
// we don't need to store anything. Verify this, since it caused a bug.
11+
12+
// CHECK:; void_ret::main
13+
// CHECK-NEXT: ; Function Attrs:
14+
// CHECK-NEXT: define internal
15+
// CHECK-NOT: store {} undef, ptr undef
16+
// CHECK: ret void
17+
18+
19+
#[autodiff_reverse(bar, Duplicated, Duplicated)]
20+
pub fn foo(r: &[f64; 10], res: &mut f64) {
21+
let mut output = [0.0; 10];
22+
output[0] = r[0];
23+
output[1] = r[1] * r[2];
24+
output[2] = r[4] * r[5];
25+
output[3] = r[2] * r[6];
26+
output[4] = r[1] * r[7];
27+
output[5] = r[2] * r[8];
28+
output[6] = r[1] * r[9];
29+
output[7] = r[5] * r[6];
30+
output[8] = r[5] * r[7];
31+
output[9] = r[4] * r[8];
32+
*res = output.iter().sum();
33+
}
34+
fn main() {
35+
let inputs = Box::new([3.1; 10]);
36+
let mut d_inputs = Box::new([0.0; 10]);
37+
let mut res = Box::new(0.0);
38+
let mut d_res = Box::new(1.0);
39+
40+
bar(&inputs, &mut d_inputs, &mut res, &mut d_res);
41+
dbg!(&d_inputs);
42+
}

0 commit comments

Comments
 (0)