Skip to content

Commit bca6d9b

Browse files
committed
Auto merge of rust-lang#86622 - FabianWolff:issue-83475, r=jonas-schievink
Check that `#[cmse_nonsecure_entry]` is applied to a function definition This PR fixes rust-lang#83475. The compiler currently neglects to check whether `#[cmse_nonsecure_entry]` is applied to a function (and not, say, a struct) definition, leading to an ICE later on when the type checker attempts to retrieve the function signature. I have fixed this problem by adding an appropriate check to the `check_attr` pass, so that an error is reported instead of an ICE.
2 parents dd1525a + 499afcd commit bca6d9b

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

compiler/rustc_passes/src/check_attr.rs

+20
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ impl CheckAttrVisitor<'tcx> {
9797
| sym::rustc_dirty
9898
| sym::rustc_if_this_changed
9999
| sym::rustc_then_this_would_need => self.check_rustc_dirty_clean(&attr),
100+
sym::cmse_nonsecure_entry => self.check_cmse_nonsecure_entry(attr, span, target),
100101
_ => true,
101102
};
102103
// lint-only checks
@@ -234,6 +235,25 @@ impl CheckAttrVisitor<'tcx> {
234235
}
235236
}
236237

238+
/// Checks if `#[cmse_nonsecure_entry]` is applied to a function definition.
239+
fn check_cmse_nonsecure_entry(&self, attr: &Attribute, span: &Span, target: Target) -> bool {
240+
match target {
241+
Target::Fn
242+
| Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent) => true,
243+
_ => {
244+
self.tcx
245+
.sess
246+
.struct_span_err(
247+
attr.span,
248+
"attribute should be applied to a function definition",
249+
)
250+
.span_label(*span, "not a function definition")
251+
.emit();
252+
false
253+
}
254+
}
255+
}
256+
237257
/// Checks if a `#[track_caller]` is applied to a non-naked function. Returns `true` if valid.
238258
fn check_track_caller(
239259
&self,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Regression test for the ICE described in #83475.
2+
3+
#![crate_type="lib"]
4+
5+
#![feature(cmse_nonsecure_entry)]
6+
#[cmse_nonsecure_entry]
7+
//~^ ERROR: attribute should be applied to a function definition
8+
struct XEmpty2;
9+
//~^ NOTE: not a function definition
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error: attribute should be applied to a function definition
2+
--> $DIR/issue-83475.rs:6:1
3+
|
4+
LL | #[cmse_nonsecure_entry]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^
6+
LL |
7+
LL | struct XEmpty2;
8+
| --------------- not a function definition
9+
10+
error: aborting due to previous error
11+

0 commit comments

Comments
 (0)