Skip to content

Commit 1490fe6

Browse files
authored
Rollup merge of #130064 - folkertdev:fix-issue-129983, r=compiler-errors
fix ICE in CMSE type validation fixes #129983 tracking issue: #81391 r? ``@compiler-errors``
2 parents ee8fd33 + e186cc6 commit 1490fe6

File tree

3 files changed

+71
-11
lines changed

3 files changed

+71
-11
lines changed

compiler/rustc_hir_analysis/src/hir_ty_lowering/cmse.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,11 @@ fn is_valid_cmse_inputs<'tcx>(
7272
let mut span = None;
7373
let mut accum = 0u64;
7474

75-
for (index, arg_def) in fn_sig.inputs().iter().enumerate() {
76-
let layout = tcx.layout_of(ParamEnv::reveal_all().and(*arg_def.skip_binder()))?;
75+
// this type is only used for layout computation, which does not rely on regions
76+
let fn_sig = tcx.instantiate_bound_regions_with_erased(fn_sig);
77+
78+
for (index, ty) in fn_sig.inputs().iter().enumerate() {
79+
let layout = tcx.layout_of(ParamEnv::reveal_all().and(*ty))?;
7780

7881
let align = layout.layout.align().abi.bytes();
7982
let size = layout.layout.size().bytes();
@@ -98,7 +101,10 @@ fn is_valid_cmse_output<'tcx>(
98101
tcx: TyCtxt<'tcx>,
99102
fn_sig: ty::PolyFnSig<'tcx>,
100103
) -> Result<bool, &'tcx LayoutError<'tcx>> {
101-
let mut ret_ty = fn_sig.output().skip_binder();
104+
// this type is only used for layout computation, which does not rely on regions
105+
let fn_sig = tcx.instantiate_bound_regions_with_erased(fn_sig);
106+
107+
let mut ret_ty = fn_sig.output();
102108
let layout = tcx.layout_of(ParamEnv::reveal_all().and(ret_ty))?;
103109
let size = layout.layout.size().bytes();
104110

tests/ui/cmse-nonsecure/cmse-nonsecure-call/generics.rs

+23-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,31 @@ impl Copy for u32 {}
1212
struct Wrapper<T>(T);
1313

1414
struct Test<T: Copy> {
15-
f1: extern "C-cmse-nonsecure-call" fn<U: Copy>(U, u32, u32, u32) -> u64, //~ ERROR cannot find type `U` in this scope
16-
//~^ ERROR function pointer types may not have generic parameters
15+
f1: extern "C-cmse-nonsecure-call" fn<U: Copy>(U, u32, u32, u32) -> u64,
16+
//~^ ERROR cannot find type `U` in this scope
17+
//~| ERROR function pointer types may not have generic parameters
1718
f2: extern "C-cmse-nonsecure-call" fn(impl Copy, u32, u32, u32) -> u64,
1819
//~^ ERROR `impl Trait` is not allowed in `fn` pointer parameters
1920
f3: extern "C-cmse-nonsecure-call" fn(T, u32, u32, u32) -> u64, //~ ERROR [E0798]
2021
f4: extern "C-cmse-nonsecure-call" fn(Wrapper<T>, u32, u32, u32) -> u64, //~ ERROR [E0798]
2122
}
23+
24+
type WithReference = extern "C-cmse-nonsecure-call" fn(&usize);
25+
26+
trait Trait {}
27+
type WithTraitObject = extern "C-cmse-nonsecure-call" fn(&dyn Trait) -> &dyn Trait;
28+
//~^ ERROR return value of `"C-cmse-nonsecure-call"` function too large to pass via registers [E0798]
29+
30+
type WithStaticTraitObject =
31+
extern "C-cmse-nonsecure-call" fn(&'static dyn Trait) -> &'static dyn Trait;
32+
//~^ ERROR return value of `"C-cmse-nonsecure-call"` function too large to pass via registers [E0798]
33+
34+
#[repr(transparent)]
35+
struct WrapperTransparent<'a>(&'a dyn Trait);
36+
37+
type WithTransparentTraitObject =
38+
extern "C-cmse-nonsecure-call" fn(WrapperTransparent) -> WrapperTransparent;
39+
//~^ ERROR return value of `"C-cmse-nonsecure-call"` function too large to pass via registers [E0798]
40+
41+
type WithVarArgs = extern "C-cmse-nonsecure-call" fn(u32, ...);
42+
//~^ ERROR C-variadic function must have a compatible calling convention, like `C` or `cdecl` [E0045]

tests/ui/cmse-nonsecure/cmse-nonsecure-call/generics.stderr

+39-6
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,59 @@ LL | struct Test<T: Copy, U> {
2222
| +++
2323

2424
error[E0562]: `impl Trait` is not allowed in `fn` pointer parameters
25-
--> $DIR/generics.rs:17:43
25+
--> $DIR/generics.rs:18:43
2626
|
2727
LL | f2: extern "C-cmse-nonsecure-call" fn(impl Copy, u32, u32, u32) -> u64,
2828
| ^^^^^^^^^
2929
|
3030
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
3131

3232
error[E0798]: function pointers with the `"C-cmse-nonsecure-call"` ABI cannot contain generics in their type
33-
--> $DIR/generics.rs:19:9
33+
--> $DIR/generics.rs:20:9
3434
|
3535
LL | f3: extern "C-cmse-nonsecure-call" fn(T, u32, u32, u32) -> u64,
3636
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3737

3838
error[E0798]: function pointers with the `"C-cmse-nonsecure-call"` ABI cannot contain generics in their type
39-
--> $DIR/generics.rs:20:9
39+
--> $DIR/generics.rs:21:9
4040
|
4141
LL | f4: extern "C-cmse-nonsecure-call" fn(Wrapper<T>, u32, u32, u32) -> u64,
4242
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4343

44-
error: aborting due to 5 previous errors
44+
error[E0798]: return value of `"C-cmse-nonsecure-call"` function too large to pass via registers
45+
--> $DIR/generics.rs:27:73
46+
|
47+
LL | type WithTraitObject = extern "C-cmse-nonsecure-call" fn(&dyn Trait) -> &dyn Trait;
48+
| ^^^^^^^^^^ this type doesn't fit in the available registers
49+
|
50+
= note: functions with the `"C-cmse-nonsecure-call"` ABI must pass their result via the available return registers
51+
= note: the result must either be a (transparently wrapped) i64, u64 or f64, or be at most 4 bytes in size
52+
53+
error[E0798]: return value of `"C-cmse-nonsecure-call"` function too large to pass via registers
54+
--> $DIR/generics.rs:31:62
55+
|
56+
LL | extern "C-cmse-nonsecure-call" fn(&'static dyn Trait) -> &'static dyn Trait;
57+
| ^^^^^^^^^^^^^^^^^^ this type doesn't fit in the available registers
58+
|
59+
= note: functions with the `"C-cmse-nonsecure-call"` ABI must pass their result via the available return registers
60+
= note: the result must either be a (transparently wrapped) i64, u64 or f64, or be at most 4 bytes in size
61+
62+
error[E0798]: return value of `"C-cmse-nonsecure-call"` function too large to pass via registers
63+
--> $DIR/generics.rs:38:62
64+
|
65+
LL | extern "C-cmse-nonsecure-call" fn(WrapperTransparent) -> WrapperTransparent;
66+
| ^^^^^^^^^^^^^^^^^^ this type doesn't fit in the available registers
67+
|
68+
= note: functions with the `"C-cmse-nonsecure-call"` ABI must pass their result via the available return registers
69+
= note: the result must either be a (transparently wrapped) i64, u64 or f64, or be at most 4 bytes in size
70+
71+
error[E0045]: C-variadic function must have a compatible calling convention, like `C` or `cdecl`
72+
--> $DIR/generics.rs:41:20
73+
|
74+
LL | type WithVarArgs = extern "C-cmse-nonsecure-call" fn(u32, ...);
75+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C-variadic function must have a compatible calling convention
76+
77+
error: aborting due to 9 previous errors
4578

46-
Some errors have detailed explanations: E0412, E0562, E0798.
47-
For more information about an error, try `rustc --explain E0412`.
79+
Some errors have detailed explanations: E0045, E0412, E0562, E0798.
80+
For more information about an error, try `rustc --explain E0045`.

0 commit comments

Comments
 (0)