about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFabian Wolff <fabian.wolff@alumni.ethz.ch>2021-06-25 15:36:38 +0200
committerFabian Wolff <fabian.wolff@alumni.ethz.ch>2021-06-25 17:49:41 +0200
commit499afcdfcf1ad9e819b0fae35aac7f8e8730f045 (patch)
tree096ba5aff7a37f9066f9fa808069597b00b2ad27
parent117799b73ccf434f588528d97596392062535e3f (diff)
downloadrust-499afcdfcf1ad9e819b0fae35aac7f8e8730f045.tar.gz
rust-499afcdfcf1ad9e819b0fae35aac7f8e8730f045.zip
Check that `#[cmse_nonsecure_entry]` is applied to a function definition
-rw-r--r--compiler/rustc_passes/src/check_attr.rs20
-rw-r--r--src/test/ui/cmse-nonsecure/cmse-nonsecure-entry/issue-83475.rs9
-rw-r--r--src/test/ui/cmse-nonsecure/cmse-nonsecure-entry/issue-83475.stderr11
3 files changed, 40 insertions, 0 deletions
diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs
index e85392cf0bd..d0795841c53 100644
--- a/compiler/rustc_passes/src/check_attr.rs
+++ b/compiler/rustc_passes/src/check_attr.rs
@@ -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,
diff --git a/src/test/ui/cmse-nonsecure/cmse-nonsecure-entry/issue-83475.rs b/src/test/ui/cmse-nonsecure/cmse-nonsecure-entry/issue-83475.rs
new file mode 100644
index 00000000000..a839406cd0a
--- /dev/null
+++ b/src/test/ui/cmse-nonsecure/cmse-nonsecure-entry/issue-83475.rs
@@ -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
diff --git a/src/test/ui/cmse-nonsecure/cmse-nonsecure-entry/issue-83475.stderr b/src/test/ui/cmse-nonsecure/cmse-nonsecure-entry/issue-83475.stderr
new file mode 100644
index 00000000000..426d82d8d07
--- /dev/null
+++ b/src/test/ui/cmse-nonsecure/cmse-nonsecure-entry/issue-83475.stderr
@@ -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
+