about summary refs log tree commit diff
diff options
context:
space:
mode:
authorManuel Drehwald <git@manuel.drehwald.info>2025-09-30 17:56:12 -0400
committerManuel Drehwald <git@manuel.drehwald.info>2025-09-30 22:47:40 -0400
commitddbaca521edf274b1462fced5b50ee6983fb8d01 (patch)
treee66d224f9b687aacbc41153222dfb5cf4a5c0491
parentc8905eaa66e0c35a33626e974b9ce6955c739b5b (diff)
downloadrust-ddbaca521edf274b1462fced5b50ee6983fb8d01.tar.gz
rust-ddbaca521edf274b1462fced5b50ee6983fb8d01.zip
fix void and empty struct ret
-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);
+    }
 }