Skip to content

Commit ad36b5a

Browse files
committed
Auto merge of #115987 - loongarch-rs:fix-transparent-union-abi, 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 #115509 r? `@bjorn3`
2 parents 9da3e81 + 10d55c3 commit ad36b5a

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

Diff for: compiler/rustc_target/src/abi/call/loongarch.rs

+11
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,17 @@ where
8383
}
8484
FieldsShape::Union(_) => {
8585
if !arg_layout.is_zst() {
86+
if arg_layout.is_transparent() {
87+
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;
88+
return should_use_fp_conv_helper(
89+
cx,
90+
&non_1zst_elem,
91+
xlen,
92+
flen,
93+
field1_kind,
94+
field2_kind,
95+
);
96+
}
8697
return Err(CannotUseFpConv);
8798
}
8899
}

Diff for: tests/ui/abi/compatibility.rs

-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use std::ptr::NonNull;
1010
// Hence there are `cfg` throughout this test to disable parts of it on those targets.
1111
// sparc64: https://github.com/rust-lang/rust/issues/115336
1212
// mips64: https://github.com/rust-lang/rust/issues/115404
13-
// loongarch64: https://github.com/rust-lang/rust/issues/115509
1413

1514
macro_rules! assert_abi_compatible {
1615
($name:ident, $t1:ty, $t2:ty) => {
@@ -109,7 +108,6 @@ macro_rules! test_transparent {
109108
test_abi_compatible!(wrap1, $t, Wrapper1<$t>);
110109
test_abi_compatible!(wrap2, $t, Wrapper2<$t>);
111110
test_abi_compatible!(wrap3, $t, Wrapper3<$t>);
112-
#[cfg(not(target_arch = "loongarch64"))]
113111
test_abi_compatible!(wrap4, $t, WrapperUnion<$t>);
114112
}
115113
};

0 commit comments

Comments
 (0)