Auto merge of #86622 - FabianWolff:issue-83475, r=jonas-schievink
Check that `#[cmse_nonsecure_entry]` is applied to a function definition This PR fixes #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.
This commit is contained in:
commit
bca6d9baa9
3 changed files with 40 additions and 0 deletions
|
|
@ -97,6 +97,7 @@ impl CheckAttrVisitor<'tcx> {
|
|||
| sym::rustc_dirty
|
||||
| sym::rustc_if_this_changed
|
||||
| sym::rustc_then_this_would_need => self.check_rustc_dirty_clean(&attr),
|
||||
sym::cmse_nonsecure_entry => self.check_cmse_nonsecure_entry(attr, span, target),
|
||||
_ => true,
|
||||
};
|
||||
// lint-only checks
|
||||
|
|
@ -234,6 +235,25 @@ impl CheckAttrVisitor<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Checks if `#[cmse_nonsecure_entry]` is applied to a function definition.
|
||||
fn check_cmse_nonsecure_entry(&self, attr: &Attribute, span: &Span, target: Target) -> bool {
|
||||
match target {
|
||||
Target::Fn
|
||||
| Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent) => true,
|
||||
_ => {
|
||||
self.tcx
|
||||
.sess
|
||||
.struct_span_err(
|
||||
attr.span,
|
||||
"attribute should be applied to a function definition",
|
||||
)
|
||||
.span_label(*span, "not a function definition")
|
||||
.emit();
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks if a `#[track_caller]` is applied to a non-naked function. Returns `true` if valid.
|
||||
fn check_track_caller(
|
||||
&self,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
// Regression test for the ICE described in #83475.
|
||||
|
||||
#![crate_type="lib"]
|
||||
|
||||
#![feature(cmse_nonsecure_entry)]
|
||||
#[cmse_nonsecure_entry]
|
||||
//~^ ERROR: attribute should be applied to a function definition
|
||||
struct XEmpty2;
|
||||
//~^ NOTE: not a function definition
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
error: attribute should be applied to a function definition
|
||||
--> $DIR/issue-83475.rs:6:1
|
||||
|
|
||||
LL | #[cmse_nonsecure_entry]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL |
|
||||
LL | struct XEmpty2;
|
||||
| --------------- not a function definition
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue