about summary refs log tree commit diff
path: root/tests/ui/abi/numbers-arithmetic/float-struct.rs
diff options
context:
space:
mode:
authorbeetrees <b@beetr.ee>2025-04-03 23:53:06 +0100
committerbeetrees <b@beetr.ee>2025-06-16 10:14:07 +0100
commit5723c9997c41be799fcaec791e591fb8406421ff (patch)
treeccbc2db7167d1f853c231370aab00d77082da181 /tests/ui/abi/numbers-arithmetic/float-struct.rs
parent68ac5abb067806a88464ddbfbd3c7eec877b488d (diff)
downloadrust-5723c9997c41be799fcaec791e591fb8406421ff.tar.gz
rust-5723c9997c41be799fcaec791e591fb8406421ff.zip
Fix RISC-V C function ABI when passing/returning structs containing floats
Diffstat (limited to 'tests/ui/abi/numbers-arithmetic/float-struct.rs')
-rw-r--r--tests/ui/abi/numbers-arithmetic/float-struct.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/ui/abi/numbers-arithmetic/float-struct.rs b/tests/ui/abi/numbers-arithmetic/float-struct.rs
new file mode 100644
index 00000000000..a958dc27272
--- /dev/null
+++ b/tests/ui/abi/numbers-arithmetic/float-struct.rs
@@ -0,0 +1,44 @@
+//@ run-pass
+
+use std::fmt::Debug;
+use std::hint::black_box;
+
+#[repr(C)]
+#[derive(Copy, Clone, PartialEq, Debug, Default)]
+struct Regular(f32, f64);
+
+#[repr(C, packed)]
+#[derive(Copy, Clone, PartialEq, Debug, Default)]
+struct Packed(f32, f64);
+
+#[repr(C, align(64))]
+#[derive(Copy, Clone, PartialEq, Debug, Default)]
+struct AlignedF32(f32);
+
+#[repr(C)]
+#[derive(Copy, Clone, PartialEq, Debug, Default)]
+struct Aligned(f64, AlignedF32);
+
+#[inline(never)]
+extern "C" fn read<T: Copy>(x: &T) -> T {
+    *black_box(x)
+}
+
+#[inline(never)]
+extern "C" fn write<T: Copy>(x: T, dest: &mut T) {
+    *dest = black_box(x)
+}
+
+#[track_caller]
+fn check<T: Copy + PartialEq + Debug + Default>(x: T) {
+    assert_eq!(read(&x), x);
+    let mut out = T::default();
+    write(x, &mut out);
+    assert_eq!(out, x);
+}
+
+fn main() {
+    check(Regular(1.0, 2.0));
+    check(Packed(3.0, 4.0));
+    check(Aligned(5.0, AlignedF32(6.0)));
+}