1
1
// check-pass
2
2
#![ feature( rustc_attrs, unsized_fn_params, transparent_unions) ]
3
- #![ allow( unused, improper_ctypes_definitions) ]
3
+ #![ allow( unused, improper_ctypes_definitions, internal_features ) ]
4
4
use std:: marker:: PhantomData ;
5
5
use std:: mem:: ManuallyDrop ;
6
6
use std:: num:: NonZeroI32 ;
7
7
use std:: ptr:: NonNull ;
8
- use std:: mem:: ManuallyDrop ;
8
+
9
+ // FIXME: a bunch of targets are broken in various ways.
10
+ // Hence there are `cfg` throughout this test to disable parts of it on those targets.
11
+ // sparc64: https://github.com/rust-lang/rust/issues/115336
12
+ // mips64: https://github.com/rust-lang/rust/issues/115404
13
+ // riscv64: https://github.com/rust-lang/rust/issues/115481
14
+ // loongarch64: https://github.com/rust-lang/rust/issues/115509
9
15
10
16
macro_rules! assert_abi_compatible {
11
17
( $name: ident, $t1: ty, $t2: ty) => {
@@ -75,6 +81,7 @@ test_abi_compatible!(fn_fn, fn(), fn(i32) -> i32);
75
81
76
82
// Some further guarantees we will likely (have to) make.
77
83
test_abi_compatible ! ( zst_unit, Zst , ( ) ) ;
84
+ #[ cfg( not( any( target_arch = "sparc64" ) ) ) ]
78
85
test_abi_compatible ! ( zst_array, Zst , [ u8 ; 0 ] ) ;
79
86
test_abi_compatible ! ( nonzero_int, NonZeroI32 , i32 ) ;
80
87
@@ -98,6 +105,7 @@ macro_rules! test_transparent {
98
105
test_abi_compatible!( wrap1, $t, Wrapper1 <$t>) ;
99
106
test_abi_compatible!( wrap2, $t, Wrapper2 <$t>) ;
100
107
test_abi_compatible!( wrap3, $t, Wrapper3 <$t>) ;
108
+ #[ cfg( not( any( target_arch = "riscv64" , target_arch = "loongarch64" ) ) ) ]
101
109
test_abi_compatible!( wrap4, $t, WrapperUnion <$t>) ;
102
110
}
103
111
} ;
@@ -107,17 +115,30 @@ test_transparent!(simple, i32);
107
115
test_transparent ! ( reference, & ' static i32 ) ;
108
116
test_transparent ! ( zst, Zst ) ;
109
117
test_transparent ! ( unit, ( ) ) ;
110
- test_transparent ! ( pair, ( i32 , f32 ) ) ; // mixing in some floats since they often get special treatment
111
- test_transparent ! ( triple, ( i8 , i16 , f32 ) ) ; // chosen to fit into 64bit
112
- test_transparent ! ( triple_f32, ( f32 , f32 , f32 ) ) ; // homogeneous case
113
- test_transparent ! ( triple_f64, ( f64 , f64 , f64 ) ) ;
114
- test_transparent ! ( tuple, ( i32 , f32 , i64 , f64 ) ) ;
115
- test_transparent ! ( empty_array, [ u32 ; 0 ] ) ;
116
- test_transparent ! ( empty_1zst_array, [ u8 ; 0 ] ) ;
117
- test_transparent ! ( small_array, [ i32 ; 2 ] ) ; // chosen to fit into 64bit
118
- test_transparent ! ( large_array, [ i32 ; 16 ] ) ;
119
118
test_transparent ! ( enum_, Option <i32 >) ;
120
119
test_transparent ! ( enum_niched, Option <& ' static i32 >) ;
120
+ #[ cfg( not( any( target_arch = "mips64" , target_arch = "sparc64" ) ) ) ]
121
+ mod tuples {
122
+ use super :: * ;
123
+ // mixing in some floats since they often get special treatment
124
+ test_transparent ! ( pair, ( i32 , f32 ) ) ;
125
+ // chosen to fit into 64bit
126
+ test_transparent ! ( triple, ( i8 , i16 , f32 ) ) ;
127
+ // Pure-float types that are not ScalarPair seem to be tricky.
128
+ test_transparent ! ( triple_f32, ( f32 , f32 , f32 ) ) ;
129
+ test_transparent ! ( triple_f64, ( f64 , f64 , f64 ) ) ;
130
+ // and also something that's larger than 2 pointers
131
+ test_transparent ! ( tuple, ( i32 , f32 , i64 , f64 ) ) ;
132
+ }
133
+ // Some targets have special rules for arrays.
134
+ #[ cfg( not( any( target_arch = "mips64" , target_arch = "sparc64" ) ) ) ]
135
+ mod arrays {
136
+ use super :: * ;
137
+ test_transparent ! ( empty_array, [ u32 ; 0 ] ) ;
138
+ test_transparent ! ( empty_1zst_array, [ u8 ; 0 ] ) ;
139
+ test_transparent ! ( small_array, [ i32 ; 2 ] ) ; // chosen to fit into 64bit
140
+ test_transparent ! ( large_array, [ i32 ; 16 ] ) ;
141
+ }
121
142
122
143
// Some tests with unsized types (not all wrappers are compatible with that).
123
144
macro_rules! test_transparent_unsized {
@@ -132,9 +153,13 @@ macro_rules! test_transparent_unsized {
132
153
} ;
133
154
}
134
155
135
- test_transparent_unsized ! ( str_, str ) ;
136
- test_transparent_unsized ! ( slice, [ u8 ] ) ;
137
- test_transparent_unsized ! ( dyn_trait, dyn std:: any:: Any ) ;
156
+ #[ cfg( not( any( target_arch = "mips64" , target_arch = "sparc64" ) ) ) ]
157
+ mod unsized_ {
158
+ use super :: * ;
159
+ test_transparent_unsized ! ( str_, str ) ;
160
+ test_transparent_unsized ! ( slice, [ u8 ] ) ;
161
+ test_transparent_unsized ! ( dyn_trait, dyn std:: any:: Any ) ;
162
+ }
138
163
139
164
// RFC 3391 <https://rust-lang.github.io/rfcs/3391-result_ffi_guarantees.html>.
140
165
macro_rules! test_nonnull {
0 commit comments