Skip to content

Commit 5a6ac8c

Browse files
authored
Rollup merge of rust-lang#146649 - folkertdev:cmse-call-erase-regions, r=lcnr
cmse: fix 'region variables should not be hashed' tracking issue: rust-lang#81391 fixes rust-lang#131639 Some background: the `cmse-nonsecure-call` calling convention is used for a call from "secure" to "non-secure" code. To make sure that "non-secure" cannot read any secrets, restrictions are put on the signatures of functions with this calling convention: they can only use 4 arguments for passing arguments, and one register for passing a result. No arguments are passed via the stack, and all other registers are cleared before the call. We check during `hir_ty_lowering` that the signature follows these rules. We do that by determining and then inspecting the layout of the type. That works well overall, but can run into asserts when the type itself is ill-formed. This PR fixes one such case. I believe that the fix here, just erasing the regions, is the right shape, but there may be some nuance that I'm missing. r? types
2 parents 1aa426b + 401857a commit 5a6ac8c

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

compiler/rustc_hir_analysis/src/hir_ty_lowering/cmse.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ fn is_valid_cmse_inputs<'tcx>(
134134

135135
// this type is only used for layout computation, which does not rely on regions
136136
let fn_sig = tcx.instantiate_bound_regions_with_erased(fn_sig);
137+
let fn_sig = tcx.erase_and_anonymize_regions(fn_sig);
137138

138139
for (index, ty) in fn_sig.inputs().iter().enumerate() {
139140
let layout = tcx.layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(*ty))?;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//@ add-core-stubs
2+
//@ compile-flags: --target thumbv8m.main-none-eabi --crate-type lib -Cincremental=true
3+
//@ needs-llvm-components: arm
4+
#![feature(abi_cmse_nonsecure_call, no_core)]
5+
#![no_core]
6+
7+
extern crate minicore;
8+
use minicore::*;
9+
10+
// A regression test for https://github.com/rust-lang/rust/issues/131639.
11+
// NOTE: -Cincremental=true was required for triggering the bug.
12+
13+
fn foo() {
14+
id::<extern "cmse-nonsecure-call" fn(&'a ())>(PhantomData);
15+
//~^ ERROR use of undeclared lifetime name `'a`
16+
}
17+
18+
fn id<T>(x: PhantomData<T>) -> PhantomData<T> {
19+
x
20+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0261]: use of undeclared lifetime name `'a`
2+
--> $DIR/undeclared-lifetime.rs:14:43
3+
|
4+
LL | id::<extern "cmse-nonsecure-call" fn(&'a ())>(PhantomData);
5+
| ^^ undeclared lifetime
6+
|
7+
= note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
8+
help: consider making the type lifetime-generic with a new `'a` lifetime
9+
|
10+
LL | id::<for<'a> extern "cmse-nonsecure-call" fn(&'a ())>(PhantomData);
11+
| +++++++
12+
help: consider introducing lifetime `'a` here
13+
|
14+
LL | fn foo<'a>() {
15+
| ++++
16+
17+
error: aborting due to 1 previous error
18+
19+
For more information about this error, try `rustc --explain E0261`.

0 commit comments

Comments
 (0)