1
+ #![ feature( portable_simd) ]
1
2
use std:: num;
2
3
use std:: mem;
4
+ use std:: simd;
3
5
4
6
fn test_abi_compat < T , U > ( t : T , u : U ) {
5
7
fn id < T > ( x : T ) -> T { x }
@@ -15,13 +17,33 @@ fn test_abi_compat<T, U>(t: T, u: U) {
15
17
drop ( f ( t) ) ;
16
18
}
17
19
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
+
18
34
fn main ( ) {
19
35
test_abi_compat ( 0u32 , 'x' ) ;
20
36
test_abi_compat ( & 0u32 , & ( [ true ; 4 ] , [ 0u32 ; 0 ] ) ) ;
21
37
test_abi_compat ( 0u32 , mem:: MaybeUninit :: new ( 0u32 ) ) ;
22
38
test_abi_compat ( 42u32 , num:: NonZeroU32 :: new ( 1 ) . unwrap ( ) ) ;
23
39
test_abi_compat ( 0u32 , Some ( num:: NonZeroU32 :: new ( 1 ) . unwrap ( ) ) ) ;
24
40
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!
26
43
// 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 ] ) ;
27
49
}
0 commit comments