about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2023-08-30 11:11:02 +0200
committerRalf Jung <post@ralfj.de>2023-08-30 17:04:54 +0200
commit1e95aa0c4920b9f780e27da6933052a3417646be (patch)
tree6b3cf050b2944a48389440a5ffe0780c4f8f2834 /src
parent26089ba0a2d9dab8381ccb0d7b99e704bc5cb3ed (diff)
downloadrust-1e95aa0c4920b9f780e27da6933052a3417646be.tar.gz
rust-1e95aa0c4920b9f780e27da6933052a3417646be.zip
interpret: make sure we accept transparent newtypes as ABI-compatible
also we were missing the case for Vector arguments, so handle those as well
Diffstat (limited to 'src')
-rw-r--r--src/tools/miri/tests/pass/function_calls/abi_compat.rs24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/tools/miri/tests/pass/function_calls/abi_compat.rs b/src/tools/miri/tests/pass/function_calls/abi_compat.rs
index 67b87b46bd9..1be29992f25 100644
--- a/src/tools/miri/tests/pass/function_calls/abi_compat.rs
+++ b/src/tools/miri/tests/pass/function_calls/abi_compat.rs
@@ -1,5 +1,7 @@
+#![feature(portable_simd)]
 use std::num;
 use std::mem;
+use std::simd;
 
 fn test_abi_compat<T, U>(t: T, u: U) {
     fn id<T>(x: T) -> T { x }
@@ -15,6 +17,20 @@ fn test_abi_compat<T, U>(t: T, u: U) {
     drop(f(t));
 }
 
+/// Ensure that `T` is compatible with various repr(transparent) wrappers around `T`.
+fn test_abi_newtype<T: Copy>(t: T) {
+    #[repr(transparent)]
+    struct Wrapper1<T>(T);
+    #[repr(transparent)]
+    struct Wrapper2<T>(T, ());
+    #[repr(transparent)]
+    struct Wrapper3<T>(T, [u8; 0]);
+
+    test_abi_compat(t, Wrapper1(t));
+    test_abi_compat(t, Wrapper2(t, ()));
+    test_abi_compat(t, Wrapper3(t, []));
+}
+
 fn main() {
     test_abi_compat(0u32, 'x');
     test_abi_compat(&0u32, &([true; 4], [0u32; 0]));
@@ -22,6 +38,12 @@ fn main() {
     test_abi_compat(42u32, num::NonZeroU32::new(1).unwrap());
     test_abi_compat(0u32, Some(num::NonZeroU32::new(1).unwrap()));
     test_abi_compat(0u32, 0i32);
-    // Note that `bool` and `u8` are *not* compatible!
+    test_abi_compat(simd::u32x8::splat(1), simd::i32x8::splat(1));
+    // Note that `bool` and `u8` are *not* compatible, at least on x86-64!
     // One of them has `arg_ext: Zext`, the other does not.
+
+    test_abi_newtype(0u32);
+    test_abi_newtype(0f32);
+    test_abi_newtype((0u32, 1u32, 2u32));
+    test_abi_newtype([0u32, 1u32, 2u32]);
 }