Skip to content

Commit ddbaca5

Browse files
committed
fix void and empty struct ret
1 parent c8905ea commit ddbaca5

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

compiler/rustc_codegen_llvm/src/builder/autodiff.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,5 +378,12 @@ pub(crate) fn generate_enzyme_call<'ll, 'tcx>(
378378

379379
let call = builder.call(enzyme_ty, None, None, ad_fn, &args, None, None);
380380

381-
builder.store_to_place(call, dest.val);
381+
let fn_ret_ty = builder.cx.val_ty(call);
382+
if fn_ret_ty != builder.cx.type_void() && fn_ret_ty != builder.cx.type_struct(&[], false) {
383+
// If we return void or an empty struct, then our caller (due to how we generated it)
384+
// does not expect a return value. As such, we have no pointer (or place) into which
385+
// we could store our value, and would store into an undef, which would cause UB.
386+
// As such, we just ignore the return value in those cases.
387+
builder.store_to_place(call, dest.val);
388+
}
382389
}

0 commit comments

Comments
 (0)