Skip to content

Commit 7be6d6f

Browse files
committed
additional tests for pass_indirectly_in_non_rustic_abis
Also emit an error when `rustc_pass_indirectly_in_non_rustic_abis` is used in combination with `repr(transparent)`.
1 parent 1866b3a commit 7be6d6f

File tree

4 files changed

+154
-10
lines changed

4 files changed

+154
-10
lines changed

compiler/rustc_abi/src/layout/ty.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
291291
{
292292
self = field;
293293
}
294+
294295
Ty::is_pass_indirectly_in_non_rustic_abis_flag_set(self)
295296
}
296297

compiler/rustc_passes/src/check_attr.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,6 +1771,17 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
17711771
target: target.to_string(),
17721772
});
17731773
}
1774+
// Error on `#[repr(transparent)]` in combination with
1775+
// `#[rustc_pass_indirectly_in_non_rustic_abis]`
1776+
if is_transparent
1777+
&& let Some(&pass_indirectly_span) =
1778+
find_attr!(attrs, AttributeKind::RustcPassIndirectlyInNonRusticAbis(span) => span)
1779+
{
1780+
self.dcx().emit_err(errors::TransparentIncompatible {
1781+
hint_spans: vec![span, pass_indirectly_span],
1782+
target: target.to_string(),
1783+
});
1784+
}
17741785
if is_explicit_rust && (int_reprs > 0 || is_c || is_simd) {
17751786
let hint_spans = hint_spans.clone().collect();
17761787
self.dcx().emit_err(errors::ReprConflicting { hint_spans });
Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,38 @@
1+
//@ add-minicore
12
//@ check-fail
23
//@ normalize-stderr: "randomization_seed: \d+" -> "randomization_seed: $$SEED"
3-
//@ compile-flags: -O
4+
//@ ignore-backends: gcc
45

56
#![feature(rustc_attrs)]
67
#![crate_type = "lib"]
8+
#![feature(no_core)]
9+
#![no_std]
10+
#![no_core]
11+
12+
extern crate minicore;
13+
use minicore::*;
714

815
#[repr(C)]
916
#[rustc_pass_indirectly_in_non_rustic_abis]
1017
pub struct Type(u8);
1118

1219
#[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,
20+
pub extern "C" fn extern_c(_: Type) {}
21+
//~^ ERROR fn_abi_of(extern_c) = FnAbi {
22+
//~| ERROR mode: Indirect
23+
//~| ERROR on_stack: false,
24+
//~| ERROR conv: C,
25+
26+
#[rustc_abi(debug)]
27+
pub extern "Rust" fn extern_rust(_: Type) {}
28+
//~^ ERROR fn_abi_of(extern_rust) = FnAbi {
29+
//~| ERROR mode: Cast
30+
//~| ERROR conv: Rust
31+
32+
#[repr(transparent)]
33+
struct Inner(u64);
34+
35+
#[rustc_pass_indirectly_in_non_rustic_abis]
36+
//~^ ERROR transparent struct cannot have other repr hints
37+
#[repr(transparent)]
38+
struct Wrapper(Inner);

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

Lines changed: 115 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
error: fn_abi_of(func) = FnAbi {
1+
error[E0692]: transparent struct cannot have other repr hints
2+
--> $DIR/pass-indirectly-attr.rs:35:1
3+
|
4+
LL | #[rustc_pass_indirectly_in_non_rustic_abis]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
...
7+
LL | struct Wrapper(Inner);
8+
| ^^^^^^^^^^^^^^^^^^^^^^
9+
10+
error: fn_abi_of(extern_c) = FnAbi {
211
args: [
312
ArgAbi {
413
layout: TyAndLayout {
@@ -75,10 +84,111 @@ error: fn_abi_of(func) = FnAbi {
7584
conv: C,
7685
can_unwind: false,
7786
}
78-
--> $DIR/pass-indirectly-attr.rs:13:1
87+
--> $DIR/pass-indirectly-attr.rs:20:1
88+
|
89+
LL | pub extern "C" fn extern_c(_: Type) {}
90+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
91+
92+
error: fn_abi_of(extern_rust) = FnAbi {
93+
args: [
94+
ArgAbi {
95+
layout: TyAndLayout {
96+
ty: Type,
97+
layout: Layout {
98+
size: Size(1 bytes),
99+
align: AbiAlign {
100+
abi: Align(1 bytes),
101+
},
102+
backend_repr: Memory {
103+
sized: true,
104+
},
105+
fields: Arbitrary {
106+
offsets: [
107+
Size(0 bytes),
108+
],
109+
memory_index: [
110+
0,
111+
],
112+
},
113+
largest_niche: None,
114+
uninhabited: false,
115+
variants: Single {
116+
index: 0,
117+
},
118+
max_repr_align: None,
119+
unadjusted_abi_align: Align(1 bytes),
120+
randomization_seed: $SEED,
121+
},
122+
},
123+
mode: Cast {
124+
pad_i32: false,
125+
cast: CastTarget {
126+
prefix: [
127+
None,
128+
None,
129+
None,
130+
None,
131+
None,
132+
None,
133+
None,
134+
None,
135+
],
136+
rest_offset: None,
137+
rest: Uniform {
138+
unit: Reg {
139+
kind: Integer,
140+
size: Size(1 bytes),
141+
},
142+
total: Size(1 bytes),
143+
is_consecutive: false,
144+
},
145+
attrs: ArgAttributes {
146+
regular: ,
147+
arg_ext: None,
148+
pointee_size: Size(0 bytes),
149+
pointee_align: None,
150+
},
151+
},
152+
},
153+
},
154+
],
155+
ret: ArgAbi {
156+
layout: TyAndLayout {
157+
ty: (),
158+
layout: Layout {
159+
size: Size(0 bytes),
160+
align: AbiAlign {
161+
abi: Align(1 bytes),
162+
},
163+
backend_repr: Memory {
164+
sized: true,
165+
},
166+
fields: Arbitrary {
167+
offsets: [],
168+
memory_index: [],
169+
},
170+
largest_niche: None,
171+
uninhabited: false,
172+
variants: Single {
173+
index: 0,
174+
},
175+
max_repr_align: None,
176+
unadjusted_abi_align: Align(1 bytes),
177+
randomization_seed: $SEED,
178+
},
179+
},
180+
mode: Ignore,
181+
},
182+
c_variadic: false,
183+
fixed_count: 1,
184+
conv: Rust,
185+
can_unwind: false,
186+
}
187+
--> $DIR/pass-indirectly-attr.rs:27:1
79188
|
80-
LL | pub extern "C" fn func(_: Type) {}
81-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
189+
LL | pub extern "Rust" fn extern_rust(_: Type) {}
190+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
82191

83-
error: aborting due to 1 previous error
192+
error: aborting due to 3 previous errors
84193

194+
For more information about this error, try `rustc --explain E0692`.

0 commit comments

Comments
 (0)