about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorStuart Cook <Zalathar@users.noreply.github.com>2025-10-01 22:15:01 +1000
committerGitHub <noreply@github.com>2025-10-01 22:15:01 +1000
commit7b0236fbd8ce4f4f433f66a4289b4c3b94f24ea2 (patch)
tree30975c98360583b0291f759029d3a98eab4506b2 /compiler
parentd4a0f21290ac23337ef385d539c72896c3373509 (diff)
parentde189fa982ad8830c326fac443ab830728567aff (diff)
downloadrust-7b0236fbd8ce4f4f433f66a4289b4c3b94f24ea2.tar.gz
rust-7b0236fbd8ce4f4f433f66a4289b4c3b94f24ea2.zip
Rollup merge of #147200 - ZuseZ4:fix-autodiff-emptry-ret, r=Zalathar
Fix autodiff empty ret regression

closes https://github.com/rust-lang/rust/issues/147144

The two gsoc summer projects caused a bit of churn, which was to be expected, especially since we don't run autodiff in CI yet.
This adds a void return testcase that we should have had anyway, and fixes the regression.

r? `@Zalathar` (Just guessing since I've seen you in a few LLVM PRs and Oli is probably still busy. Feel free to reroll!)
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_codegen_llvm/src/builder/autodiff.rs9
1 files changed, 8 insertions, 1 deletions
diff --git a/compiler/rustc_codegen_llvm/src/builder/autodiff.rs b/compiler/rustc_codegen_llvm/src/builder/autodiff.rs
index c3485f56391..4a749642265 100644
--- a/compiler/rustc_codegen_llvm/src/builder/autodiff.rs
+++ b/compiler/rustc_codegen_llvm/src/builder/autodiff.rs
@@ -378,5 +378,12 @@ pub(crate) fn generate_enzyme_call<'ll, 'tcx>(
 
     let call = builder.call(enzyme_ty, None, None, ad_fn, &args, None, None);
 
-    builder.store_to_place(call, dest.val);
+    let fn_ret_ty = builder.cx.val_ty(call);
+    if fn_ret_ty != builder.cx.type_void() && fn_ret_ty != builder.cx.type_struct(&[], false) {
+        // If we return void or an empty struct, then our caller (due to how we generated it)
+        // does not expect a return value. As such, we have no pointer (or place) into which
+        // we could store our value, and would store into an undef, which would cause UB.
+        // As such, we just ignore the return value in those cases.
+        builder.store_to_place(call, dest.val);
+    }
 }