about summary refs log tree commit diff
diff options
context:
space:
mode:
authorWANG Rui <wangrui@loongson.cn>2023-09-11 16:05:49 +0800
committerWANG Rui <wangrui@loongson.cn>2023-09-20 09:22:02 +0800
commit0163768e0d98ea41432f4c144d900e4865c5be39 (patch)
tree8539880f4da6e36075d92b19bd1593886ddf5fa0
parentbdb0fa3ee5ffb4cc1a1b53cbe8344a2b83b1ae2a (diff)
downloadrust-0163768e0d98ea41432f4c144d900e4865c5be39.tar.gz
rust-0163768e0d98ea41432f4c144d900e4865c5be39.zip
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 https://github.com/rust-lang/rust/issues/115509
-rw-r--r--compiler/rustc_target/src/abi/call/loongarch.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/compiler/rustc_target/src/abi/call/loongarch.rs b/compiler/rustc_target/src/abi/call/loongarch.rs
index 247256f076b..e649d58bbca 100644
--- a/compiler/rustc_target/src/abi/call/loongarch.rs
+++ b/compiler/rustc_target/src/abi/call/loongarch.rs
@@ -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);
                 }
             }