about summary refs log tree commit diff
path: root/tests/ui/asm
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-09-11 13:47:26 +0000
committerbors <bors@rust-lang.org>2024-09-11 13:47:26 +0000
commitf7f8bdf2e03918cc3742db3bb37b7cfe9994dbec (patch)
treee928fc05f3524c60ed2637d2202e75f3e848a28d /tests/ui/asm
parent16beabe1e17fa1f35a1964609ee589b999386690 (diff)
parent6ca5ec7b4ef0466a1cdf3fbce9212cabc171d21a (diff)
downloadrust-f7f8bdf2e03918cc3742db3bb37b7cfe9994dbec.tar.gz
rust-f7f8bdf2e03918cc3742db3bb37b7cfe9994dbec.zip
Auto merge of #130195 - folkertdev:naked-asm-outside-naked-fn, r=Amanieu
disallow `naked_asm!` outside of `#[naked]` functions

tracking issue: https://github.com/rust-lang/rust/issues/90957
parent PR: https://github.com/rust-lang/rust/pull/128651

I split this out from the parent PR because it's self-contained and because the analysis has to search through all functions and there might be performance regressions.

r? `@Amanieu`
Diffstat (limited to 'tests/ui/asm')
-rw-r--r--tests/ui/asm/naked-asm-outside-naked-fn.rs35
-rw-r--r--tests/ui/asm/naked-asm-outside-naked-fn.stderr20
2 files changed, 55 insertions, 0 deletions
diff --git a/tests/ui/asm/naked-asm-outside-naked-fn.rs b/tests/ui/asm/naked-asm-outside-naked-fn.rs
new file mode 100644
index 00000000000..1696008f339
--- /dev/null
+++ b/tests/ui/asm/naked-asm-outside-naked-fn.rs
@@ -0,0 +1,35 @@
+//@ edition: 2021
+//@ needs-asm-support
+//@ ignore-nvptx64
+//@ ignore-spirv
+
+#![feature(naked_functions)]
+#![crate_type = "lib"]
+
+use std::arch::naked_asm;
+
+fn main() {
+    test1();
+}
+
+#[naked]
+extern "C" fn test1() {
+    unsafe { naked_asm!("") }
+}
+
+extern "C" fn test2() {
+    unsafe { naked_asm!("") }
+    //~^ ERROR the `naked_asm!` macro can only be used in functions marked with `#[naked]`
+}
+
+extern "C" fn test3() {
+    unsafe { (|| naked_asm!(""))() }
+    //~^ ERROR the `naked_asm!` macro can only be used in functions marked with `#[naked]`
+}
+
+fn test4() {
+    async move {
+        unsafe {  naked_asm!("") } ;
+        //~^ ERROR the `naked_asm!` macro can only be used in functions marked with `#[naked]`
+    };
+}
diff --git a/tests/ui/asm/naked-asm-outside-naked-fn.stderr b/tests/ui/asm/naked-asm-outside-naked-fn.stderr
new file mode 100644
index 00000000000..6e91359669c
--- /dev/null
+++ b/tests/ui/asm/naked-asm-outside-naked-fn.stderr
@@ -0,0 +1,20 @@
+error: the `naked_asm!` macro can only be used in functions marked with `#[naked]`
+  --> $DIR/naked-asm-outside-naked-fn.rs:21:14
+   |
+LL |     unsafe { naked_asm!("") }
+   |              ^^^^^^^^^^^^^^
+
+error: the `naked_asm!` macro can only be used in functions marked with `#[naked]`
+  --> $DIR/naked-asm-outside-naked-fn.rs:26:18
+   |
+LL |     unsafe { (|| naked_asm!(""))() }
+   |                  ^^^^^^^^^^^^^^
+
+error: the `naked_asm!` macro can only be used in functions marked with `#[naked]`
+  --> $DIR/naked-asm-outside-naked-fn.rs:32:19
+   |
+LL |         unsafe {  naked_asm!("") } ;
+   |                   ^^^^^^^^^^^^^^
+
+error: aborting due to 3 previous errors
+