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
+ use std:: mem:: ManuallyDrop ;
5
6
use std:: num:: NonZeroI32 ;
6
7
use std:: ptr:: NonNull ;
7
- 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
15
+ // arm, aarch64: https://github.com/rust-lang/rust/issues/115664
8
16
9
17
macro_rules! assert_abi_compatible {
10
18
( $name: ident, $t1: ty, $t2: ty) => {
@@ -74,6 +82,7 @@ test_abi_compatible!(fn_fn, fn(), fn(i32) -> i32);
74
82
75
83
// Some further guarantees we will likely (have to) make.
76
84
test_abi_compatible ! ( zst_unit, Zst , ( ) ) ;
85
+ #[ cfg( not( any( target_arch = "sparc64" ) ) ) ]
77
86
test_abi_compatible ! ( zst_array, Zst , [ u8 ; 0 ] ) ;
78
87
test_abi_compatible ! ( nonzero_int, NonZeroI32 , i32 ) ;
79
88
@@ -97,6 +106,7 @@ macro_rules! test_transparent {
97
106
test_abi_compatible!( wrap1, $t, Wrapper1 <$t>) ;
98
107
test_abi_compatible!( wrap2, $t, Wrapper2 <$t>) ;
99
108
test_abi_compatible!( wrap3, $t, Wrapper3 <$t>) ;
109
+ #[ cfg( not( any( target_arch = "riscv64" , target_arch = "loongarch64" ) ) ) ]
100
110
test_abi_compatible!( wrap4, $t, WrapperUnion <$t>) ;
101
111
}
102
112
} ;
@@ -106,23 +116,39 @@ test_transparent!(simple, i32);
106
116
test_transparent ! ( reference, & ' static i32 ) ;
107
117
test_transparent ! ( zst, Zst ) ;
108
118
test_transparent ! ( unit, ( ) ) ;
109
- test_transparent ! ( pair, ( i32 , f32 ) ) ; // mixing in some floats since they often get special treatment
110
- test_transparent ! ( triple, ( i8 , i16 , f32 ) ) ; // chosen to fit into 64bit
111
- test_transparent ! ( tuple, ( i32 , f32 , i64 , f64 ) ) ;
112
- test_transparent ! ( empty_array, [ u32 ; 0 ] ) ;
113
- test_transparent ! ( empty_1zst_array, [ u8 ; 0 ] ) ;
114
- test_transparent ! ( small_array, [ i32 ; 2 ] ) ; // chosen to fit into 64bit
115
- test_transparent ! ( large_array, [ i32 ; 16 ] ) ;
116
119
test_transparent ! ( enum_, Option <i32 >) ;
117
120
test_transparent ! ( enum_niched, Option <& ' static i32 >) ;
121
+ #[ cfg( not( any( target_arch = "mips64" , target_arch = "sparc64" ) ) ) ]
122
+ mod problematic_tuples1 {
123
+ use super :: * ;
124
+ // mixing in some floats since they often get special treatment
125
+ test_transparent ! ( pair, ( i32 , f32 ) ) ;
126
+ // chosen to fit into 64bit
127
+ test_transparent ! ( triple, ( i8 , i16 , f32 ) ) ;
128
+ // and also something that's larger than 2 pointers
129
+ test_transparent ! ( tuple, ( i32 , f32 , i64 , f64 ) ) ;
130
+ }
118
131
// Pure-float types that are not ScalarPair seem to be tricky.
119
- // FIXME: <https://github.com/rust-lang/rust/issues/115664>
120
- #[ cfg( not( any( target_arch = "arm" , target_arch = "aarch64" ) ) ) ]
121
- mod tricky {
132
+ #[ cfg( not( any(
133
+ target_arch = "arm" ,
134
+ target_arch = "aarch64" ,
135
+ target_arch = "mips64" ,
136
+ target_arch = "sparc64"
137
+ ) ) ) ]
138
+ mod problematic_tuples2 {
122
139
use super :: * ;
123
140
test_transparent ! ( triple_f32, ( f32 , f32 , f32 ) ) ;
124
141
test_transparent ! ( triple_f64, ( f64 , f64 , f64 ) ) ;
125
142
}
143
+ // Some targets have special rules for arrays.
144
+ #[ cfg( not( any( target_arch = "mips64" , target_arch = "sparc64" ) ) ) ]
145
+ mod arrays {
146
+ use super :: * ;
147
+ test_transparent ! ( empty_array, [ u32 ; 0 ] ) ;
148
+ test_transparent ! ( empty_1zst_array, [ u8 ; 0 ] ) ;
149
+ test_transparent ! ( small_array, [ i32 ; 2 ] ) ; // chosen to fit into 64bit
150
+ test_transparent ! ( large_array, [ i32 ; 16 ] ) ;
151
+ }
126
152
127
153
// Some tests with unsized types (not all wrappers are compatible with that).
128
154
macro_rules! test_transparent_unsized {
@@ -137,9 +163,13 @@ macro_rules! test_transparent_unsized {
137
163
} ;
138
164
}
139
165
140
- test_transparent_unsized ! ( str_, str ) ;
141
- test_transparent_unsized ! ( slice, [ u8 ] ) ;
142
- test_transparent_unsized ! ( dyn_trait, dyn std:: any:: Any ) ;
166
+ #[ cfg( not( any( target_arch = "mips64" , target_arch = "sparc64" ) ) ) ]
167
+ mod unsized_ {
168
+ use super :: * ;
169
+ test_transparent_unsized ! ( str_, str ) ;
170
+ test_transparent_unsized ! ( slice, [ u8 ] ) ;
171
+ test_transparent_unsized ! ( dyn_trait, dyn std:: any:: Any ) ;
172
+ }
143
173
144
174
// RFC 3391 <https://rust-lang.github.io/rfcs/3391-result_ffi_guarantees.html>.
145
175
macro_rules! test_nonnull {
0 commit comments