Skip to content

Commit 6055f07

Browse files
folkertdevbeetrees
authored andcommitted
additional tests for pass_indirectly_in_non_rustic_abis
also handle the attribute at any point in a transparent chain
1 parent 6a0bcd9 commit 6055f07

File tree

3 files changed

+227
-13
lines changed

3 files changed

+227
-13
lines changed

compiler/rustc_abi/src/layout/ty.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,17 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
286286
where
287287
Ty: TyAbiInterface<'a, C> + Copy,
288288
{
289-
while self.is_transparent()
290-
&& let Some((_, field)) = self.non_1zst_field(cx)
291-
{
292-
self = field;
289+
loop {
290+
if Ty::is_pass_indirectly_in_non_rustic_abis_flag_set(self) {
291+
return true;
292+
} else if self.is_transparent()
293+
&& let Some((_, field)) = self.non_1zst_field(cx)
294+
{
295+
self = field;
296+
} else {
297+
return false;
298+
}
293299
}
294-
Ty::is_pass_indirectly_in_non_rustic_abis_flag_set(self)
295300
}
296301

297302
/// Finds the one field that is not a 1-ZST.

tests/ui/abi/pass-indirectly-attr.rs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,28 @@
1010
pub struct Type(u8);
1111

1212
#[rustc_abi(debug)]
13-
pub extern "C" fn func(_: Type) {}
14-
//~^ ERROR fn_abi_of(func) = FnAbi {
15-
//~^^ ERROR mode: Indirect {
16-
//~^^^ ERROR on_stack: false,
13+
pub extern "C" fn extern_c(_: Type) {}
14+
//~^ ERROR fn_abi_of(extern_c) = FnAbi {
15+
//~| ERROR mode: Indirect
16+
//~| ERROR on_stack: false,
17+
//~| ERROR conv: C,
18+
19+
#[rustc_abi(debug)]
20+
pub extern "Rust" fn extern_rust(_: Type) {}
21+
//~^ ERROR fn_abi_of(extern_rust) = FnAbi {
22+
//~| ERROR mode: Cast
23+
//~| ERROR conv: Rust
24+
25+
#[repr(transparent)]
26+
struct Inner(u64);
27+
28+
#[rustc_pass_indirectly_in_non_rustic_abis]
29+
#[repr(transparent)]
30+
struct Wrapper(Inner);
31+
32+
#[rustc_abi(debug)]
33+
pub extern "C" fn wrapped_transparent(_: Wrapper) {}
34+
//~^ ERROR fn_abi_of(wrapped_transparent) = FnAbi {
35+
//~| ERROR mode: Indirect {
36+
//~| ERROR on_stack: false,
37+
//~| ERROR conv: C

tests/ui/abi/pass-indirectly-attr.stderr

Lines changed: 192 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: fn_abi_of(func) = FnAbi {
1+
error: fn_abi_of(extern_c) = FnAbi {
22
args: [
33
ArgAbi {
44
layout: TyAndLayout {
@@ -77,8 +77,196 @@ error: fn_abi_of(func) = FnAbi {
7777
}
7878
--> $DIR/pass-indirectly-attr.rs:13:1
7979
|
80-
LL | pub extern "C" fn func(_: Type) {}
81-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
80+
LL | pub extern "C" fn extern_c(_: Type) {}
81+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8282

83-
error: aborting due to 1 previous error
83+
error: fn_abi_of(extern_rust) = FnAbi {
84+
args: [
85+
ArgAbi {
86+
layout: TyAndLayout {
87+
ty: Type,
88+
layout: Layout {
89+
size: Size(1 bytes),
90+
align: AbiAlign {
91+
abi: Align(1 bytes),
92+
},
93+
backend_repr: Memory {
94+
sized: true,
95+
},
96+
fields: Arbitrary {
97+
offsets: [
98+
Size(0 bytes),
99+
],
100+
memory_index: [
101+
0,
102+
],
103+
},
104+
largest_niche: None,
105+
uninhabited: false,
106+
variants: Single {
107+
index: 0,
108+
},
109+
max_repr_align: None,
110+
unadjusted_abi_align: Align(1 bytes),
111+
randomization_seed: $SEED,
112+
},
113+
},
114+
mode: Cast {
115+
pad_i32: false,
116+
cast: CastTarget {
117+
prefix: [
118+
None,
119+
None,
120+
None,
121+
None,
122+
None,
123+
None,
124+
None,
125+
None,
126+
],
127+
rest_offset: None,
128+
rest: Uniform {
129+
unit: Reg {
130+
kind: Integer,
131+
size: Size(1 bytes),
132+
},
133+
total: Size(1 bytes),
134+
is_consecutive: false,
135+
},
136+
attrs: ArgAttributes {
137+
regular: ,
138+
arg_ext: None,
139+
pointee_size: Size(0 bytes),
140+
pointee_align: None,
141+
},
142+
},
143+
},
144+
},
145+
],
146+
ret: ArgAbi {
147+
layout: TyAndLayout {
148+
ty: (),
149+
layout: Layout {
150+
size: Size(0 bytes),
151+
align: AbiAlign {
152+
abi: Align(1 bytes),
153+
},
154+
backend_repr: Memory {
155+
sized: true,
156+
},
157+
fields: Arbitrary {
158+
offsets: [],
159+
memory_index: [],
160+
},
161+
largest_niche: None,
162+
uninhabited: false,
163+
variants: Single {
164+
index: 0,
165+
},
166+
max_repr_align: None,
167+
unadjusted_abi_align: Align(1 bytes),
168+
randomization_seed: $SEED,
169+
},
170+
},
171+
mode: Ignore,
172+
},
173+
c_variadic: false,
174+
fixed_count: 1,
175+
conv: Rust,
176+
can_unwind: true,
177+
}
178+
--> $DIR/pass-indirectly-attr.rs:20:1
179+
|
180+
LL | pub extern "Rust" fn extern_rust(_: Type) {}
181+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
182+
183+
error: fn_abi_of(wrapped_transparent) = FnAbi {
184+
args: [
185+
ArgAbi {
186+
layout: TyAndLayout {
187+
ty: Wrapper,
188+
layout: Layout {
189+
size: Size(8 bytes),
190+
align: AbiAlign {
191+
abi: Align(8 bytes),
192+
},
193+
backend_repr: Scalar(
194+
Initialized {
195+
value: Int(
196+
I64,
197+
false,
198+
),
199+
valid_range: 0..=18446744073709551615,
200+
},
201+
),
202+
fields: Arbitrary {
203+
offsets: [
204+
Size(0 bytes),
205+
],
206+
memory_index: [
207+
0,
208+
],
209+
},
210+
largest_niche: None,
211+
uninhabited: false,
212+
variants: Single {
213+
index: 0,
214+
},
215+
max_repr_align: None,
216+
unadjusted_abi_align: Align(8 bytes),
217+
randomization_seed: $SEED,
218+
},
219+
},
220+
mode: Indirect {
221+
attrs: ArgAttributes {
222+
regular: NoAlias | CapturesAddress | NonNull | NoUndef,
223+
arg_ext: None,
224+
pointee_size: Size(8 bytes),
225+
pointee_align: Some(
226+
Align(8 bytes),
227+
),
228+
},
229+
meta_attrs: None,
230+
on_stack: false,
231+
},
232+
},
233+
],
234+
ret: ArgAbi {
235+
layout: TyAndLayout {
236+
ty: (),
237+
layout: Layout {
238+
size: Size(0 bytes),
239+
align: AbiAlign {
240+
abi: Align(1 bytes),
241+
},
242+
backend_repr: Memory {
243+
sized: true,
244+
},
245+
fields: Arbitrary {
246+
offsets: [],
247+
memory_index: [],
248+
},
249+
largest_niche: None,
250+
uninhabited: false,
251+
variants: Single {
252+
index: 0,
253+
},
254+
max_repr_align: None,
255+
unadjusted_abi_align: Align(1 bytes),
256+
randomization_seed: $SEED,
257+
},
258+
},
259+
mode: Ignore,
260+
},
261+
c_variadic: false,
262+
fixed_count: 1,
263+
conv: C,
264+
can_unwind: false,
265+
}
266+
--> $DIR/pass-indirectly-attr.rs:33:1
267+
|
268+
LL | pub extern "C" fn wrapped_transparent(_: Wrapper) {}
269+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
270+
271+
error: aborting due to 3 previous errors
84272

0 commit comments

Comments
 (0)