Skip to content

Commit ca46564

Browse files
committed
interpret: make sure we accept transparent newtypes as ABI-compatible
also we were missing the case for Vector arguments, so handle those as well
1 parent fff7516 commit ca46564

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

tests/pass/function_calls/abi_compat.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
#![feature(portable_simd)]
12
use std::num;
23
use std::mem;
4+
use std::simd;
35

46
fn test_abi_compat<T, U>(t: T, u: U) {
57
fn id<T>(x: T) -> T { x }
@@ -15,13 +17,33 @@ fn test_abi_compat<T, U>(t: T, u: U) {
1517
drop(f(t));
1618
}
1719

20+
/// Ensure that `T` is compatible with various repr(transparent) wrappers around `T`.
21+
fn test_abi_newtype<T: Copy>(t: T) {
22+
#[repr(transparent)]
23+
struct Wrapper1<T>(T);
24+
#[repr(transparent)]
25+
struct Wrapper2<T>(T, ());
26+
#[repr(transparent)]
27+
struct Wrapper3<T>(T, [u8; 0]);
28+
29+
test_abi_compat(t, Wrapper1(t));
30+
test_abi_compat(t, Wrapper2(t, ()));
31+
test_abi_compat(t, Wrapper3(t, []));
32+
}
33+
1834
fn main() {
1935
test_abi_compat(0u32, 'x');
2036
test_abi_compat(&0u32, &([true; 4], [0u32; 0]));
2137
test_abi_compat(0u32, mem::MaybeUninit::new(0u32));
2238
test_abi_compat(42u32, num::NonZeroU32::new(1).unwrap());
2339
test_abi_compat(0u32, Some(num::NonZeroU32::new(1).unwrap()));
2440
test_abi_compat(0u32, 0i32);
25-
// Note that `bool` and `u8` are *not* compatible!
41+
test_abi_compat(simd::u32x8::splat(1), simd::i32x8::splat(1));
42+
// Note that `bool` and `u8` are *not* compatible, at least on x86-64!
2643
// One of them has `arg_ext: Zext`, the other does not.
44+
45+
test_abi_newtype(0u32);
46+
test_abi_newtype(0f32);
47+
test_abi_newtype((0u32, 1u32, 2u32));
48+
test_abi_newtype([0u32, 1u32, 2u32]);
2749
}

0 commit comments

Comments
 (0)