Skip to content

Commit

Permalink
Auto merge of rust-lang#115987 - loongarch-rs:fix-transparent-union-a…
Browse files Browse the repository at this point in the history
…bi, r=bjorn3

rustc_target/loongarch: Fix passing of transparent unions with only one non-ZST member

This ensures that `MaybeUninit<T>` has the same ABI as `T` when passed through an `extern "C"` function.

Fixes rust-lang#115509

r? `@bjorn3`
  • Loading branch information
bors committed Sep 20, 2023
2 parents 9da3e81 + 10d55c3 commit ad36b5a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 11 additions & 0 deletions compiler/rustc_target/src/abi/call/loongarch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,17 @@ where
}
FieldsShape::Union(_) => {
if !arg_layout.is_zst() {
if arg_layout.is_transparent() {
let non_1zst_elem = arg_layout.non_1zst_field(cx).expect("not exactly one non-1-ZST field in non-ZST repr(transparent) union").1;
return should_use_fp_conv_helper(
cx,
&non_1zst_elem,
xlen,
flen,
field1_kind,
field2_kind,
);
}
return Err(CannotUseFpConv);
}
}
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/abi/compatibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use std::ptr::NonNull;
// Hence there are `cfg` throughout this test to disable parts of it on those targets.
// sparc64: https://github.com/rust-lang/rust/issues/115336
// mips64: https://github.com/rust-lang/rust/issues/115404
// loongarch64: https://github.com/rust-lang/rust/issues/115509

macro_rules! assert_abi_compatible {
($name:ident, $t1:ty, $t2:ty) => {
Expand Down Expand Up @@ -109,7 +108,6 @@ macro_rules! test_transparent {
test_abi_compatible!(wrap1, $t, Wrapper1<$t>);
test_abi_compatible!(wrap2, $t, Wrapper2<$t>);
test_abi_compatible!(wrap3, $t, Wrapper3<$t>);
#[cfg(not(target_arch = "loongarch64"))]
test_abi_compatible!(wrap4, $t, WrapperUnion<$t>);
}
};
Expand Down

0 comments on commit ad36b5a

Please sign in to comment.