about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFolkert <folkert@folkertdev.nl>2024-07-16 16:35:23 +0200
committerFolkert <folkert@folkertdev.nl>2024-07-16 17:18:33 +0200
commit1e8606408d14e2509f59c0a87c02788cb112b55a (patch)
tree40305938e2f9154ed94024ccb22e73fec0360155
parent50ba821e12f51903aba6902b2b404edbc94011d2 (diff)
downloadrust-1e8606408d14e2509f59c0a87c02788cb112b55a.tar.gz
rust-1e8606408d14e2509f59c0a87c02788cb112b55a.zip
add more tests for `cmse-nonsecure-call` stack spills
-rw-r--r--tests/ui/cmse-nonsecure/cmse-nonsecure-call/params-on-registers.rs24
-rw-r--r--tests/ui/cmse-nonsecure/cmse-nonsecure-call/params-on-stack.rs24
-rw-r--r--tests/ui/cmse-nonsecure/cmse-nonsecure-call/params-on-stack.stderr14
-rw-r--r--tests/ui/cmse-nonsecure/cmse-nonsecure-call/params-via-stack.rs29
-rw-r--r--tests/ui/cmse-nonsecure/cmse-nonsecure-call/params-via-stack.stderr58
-rw-r--r--tests/ui/cmse-nonsecure/cmse-nonsecure-call/return-via-stack.rs41
-rw-r--r--tests/ui/cmse-nonsecure/cmse-nonsecure-call/return-via-stack.stderr97
-rw-r--r--tests/ui/cmse-nonsecure/cmse-nonsecure-call/via-registers.rs55
8 files changed, 280 insertions, 62 deletions
diff --git a/tests/ui/cmse-nonsecure/cmse-nonsecure-call/params-on-registers.rs b/tests/ui/cmse-nonsecure/cmse-nonsecure-call/params-on-registers.rs
deleted file mode 100644
index 364d0858afb..00000000000
--- a/tests/ui/cmse-nonsecure/cmse-nonsecure-call/params-on-registers.rs
+++ /dev/null
@@ -1,24 +0,0 @@
-//@ build-pass
-//@ compile-flags: --target thumbv8m.main-none-eabi --crate-type lib
-//@ needs-llvm-components: arm
-#![feature(abi_c_cmse_nonsecure_call, no_core, lang_items, intrinsics)]
-#![no_core]
-#[lang="sized"]
-pub trait Sized { }
-#[lang="copy"]
-pub trait Copy { }
-impl Copy for u32 {}
-
-extern "rust-intrinsic" {
-    pub fn transmute<T, U>(e: T) -> U;
-}
-
-#[no_mangle]
-pub fn test(a: u32, b: u32, c: u32, d: u32) -> u32 {
-    let non_secure_function = unsafe {
-        transmute::<usize, extern "C-cmse-nonsecure-call" fn(u32, u32, u32, u32) -> u32>(
-            0x10000004,
-        )
-    };
-    non_secure_function(a, b, c, d)
-}
diff --git a/tests/ui/cmse-nonsecure/cmse-nonsecure-call/params-on-stack.rs b/tests/ui/cmse-nonsecure/cmse-nonsecure-call/params-on-stack.rs
deleted file mode 100644
index f13e81d0060..00000000000
--- a/tests/ui/cmse-nonsecure/cmse-nonsecure-call/params-on-stack.rs
+++ /dev/null
@@ -1,24 +0,0 @@
-//@ build-fail
-//@ compile-flags: --target thumbv8m.main-none-eabi --crate-type lib
-//@ needs-llvm-components: arm
-#![feature(abi_c_cmse_nonsecure_call, no_core, lang_items, intrinsics)]
-#![no_core]
-#[lang = "sized"]
-pub trait Sized {}
-#[lang = "copy"]
-pub trait Copy {}
-impl Copy for u32 {}
-
-extern "rust-intrinsic" {
-    pub fn transmute<T, U>(e: T) -> U;
-}
-
-#[no_mangle]
-pub fn test(a: u32, b: u32, c: u32, d: u32, e: u32) -> u32 {
-    let non_secure_function = unsafe {
-        transmute::<usize, extern "C-cmse-nonsecure-call" fn(u32, u32, u32, u32, u32) -> u32>(
-            0x10000004,
-        )
-    };
-    non_secure_function(a, b, c, d, e) //~ ERROR [E0798]
-}
diff --git a/tests/ui/cmse-nonsecure/cmse-nonsecure-call/params-on-stack.stderr b/tests/ui/cmse-nonsecure/cmse-nonsecure-call/params-on-stack.stderr
deleted file mode 100644
index ee4effa56d4..00000000000
--- a/tests/ui/cmse-nonsecure/cmse-nonsecure-call/params-on-stack.stderr
+++ /dev/null
@@ -1,14 +0,0 @@
-error[E0798]: arguments for `C-cmse-nonsecure-call` function too large to pass via registers
-  --> $DIR/params-on-stack.rs:23:5
-   |
-LL |     let non_secure_function = unsafe {
-   |         ------------------- this function uses the `C-cmse-nonsecure-call` ABI
-...
-LL |     non_secure_function(a, b, c, d, e)
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ but its arguments don't fit in the available registers
-   |
-   = note: functions with the `C-cmse-nonsecure-call` ABI must pass all their arguments via the 4 32-bit available argument registers
-
-error: aborting due to 1 previous error
-
-For more information about this error, try `rustc --explain E0798`.
diff --git a/tests/ui/cmse-nonsecure/cmse-nonsecure-call/params-via-stack.rs b/tests/ui/cmse-nonsecure/cmse-nonsecure-call/params-via-stack.rs
new file mode 100644
index 00000000000..a4cc74f716f
--- /dev/null
+++ b/tests/ui/cmse-nonsecure/cmse-nonsecure-call/params-via-stack.rs
@@ -0,0 +1,29 @@
+//@ build-fail
+//@ compile-flags: --target thumbv8m.main-none-eabi --crate-type lib
+//@ needs-llvm-components: arm
+#![feature(abi_c_cmse_nonsecure_call, no_core, lang_items, intrinsics)]
+#![no_core]
+#[lang = "sized"]
+pub trait Sized {}
+#[lang = "copy"]
+pub trait Copy {}
+impl Copy for u32 {}
+
+#[repr(C, align(16))]
+#[allow(unused)]
+pub struct AlignRelevant(u32);
+
+#[no_mangle]
+pub fn test(
+    f1: extern "C-cmse-nonsecure-call" fn(u32, u32, u32, u32, u32) -> u32,
+    f2: extern "C-cmse-nonsecure-call" fn(u32, u32, u32, u16, u16) -> u32,
+    f3: extern "C-cmse-nonsecure-call" fn(u32, u64, u32) -> u32,
+    f4: extern "C-cmse-nonsecure-call" fn(AlignRelevant, u32) -> u32,
+    f5: extern "C-cmse-nonsecure-call" fn([u32; 5]) -> u32,
+) {
+    f1(1, 2, 3, 4, 5); //~ ERROR [E0798]
+    f2(1, 2, 3, 4, 5); //~ ERROR [E0798]
+    f3(1, 2, 3); //~ ERROR [E0798]
+    f4(AlignRelevant(1), 2); //~ ERROR [E0798]
+    f5([0xAA; 5]); //~ ERROR [E0798]
+}
diff --git a/tests/ui/cmse-nonsecure/cmse-nonsecure-call/params-via-stack.stderr b/tests/ui/cmse-nonsecure/cmse-nonsecure-call/params-via-stack.stderr
new file mode 100644
index 00000000000..b161c90d01a
--- /dev/null
+++ b/tests/ui/cmse-nonsecure/cmse-nonsecure-call/params-via-stack.stderr
@@ -0,0 +1,58 @@
+error[E0798]: arguments for `C-cmse-nonsecure-call` function too large to pass via registers
+  --> $DIR/params-via-stack.rs:24:5
+   |
+LL |     f1: extern "C-cmse-nonsecure-call" fn(u32, u32, u32, u32, u32) -> u32,
+   |     -- this function uses the `C-cmse-nonsecure-call` ABI
+...
+LL |     f1(1, 2, 3, 4, 5);
+   |     ^^^^^^^^^^^^^^^^^ but its arguments don't fit in the available registers
+   |
+   = note: functions with the `C-cmse-nonsecure-call` ABI must pass all their arguments via the 4 32-bit available argument registers
+
+error[E0798]: arguments for `C-cmse-nonsecure-call` function too large to pass via registers
+  --> $DIR/params-via-stack.rs:25:5
+   |
+LL |     f2: extern "C-cmse-nonsecure-call" fn(u32, u32, u32, u16, u16) -> u32,
+   |     -- this function uses the `C-cmse-nonsecure-call` ABI
+...
+LL |     f2(1, 2, 3, 4, 5);
+   |     ^^^^^^^^^^^^^^^^^ but its arguments don't fit in the available registers
+   |
+   = note: functions with the `C-cmse-nonsecure-call` ABI must pass all their arguments via the 4 32-bit available argument registers
+
+error[E0798]: arguments for `C-cmse-nonsecure-call` function too large to pass via registers
+  --> $DIR/params-via-stack.rs:26:5
+   |
+LL |     f3: extern "C-cmse-nonsecure-call" fn(u32, u64, u32) -> u32,
+   |     -- this function uses the `C-cmse-nonsecure-call` ABI
+...
+LL |     f3(1, 2, 3);
+   |     ^^^^^^^^^^^ but its arguments don't fit in the available registers
+   |
+   = note: functions with the `C-cmse-nonsecure-call` ABI must pass all their arguments via the 4 32-bit available argument registers
+
+error[E0798]: arguments for `C-cmse-nonsecure-call` function too large to pass via registers
+  --> $DIR/params-via-stack.rs:27:5
+   |
+LL |     f4: extern "C-cmse-nonsecure-call" fn(AlignRelevant, u32) -> u32,
+   |     -- this function uses the `C-cmse-nonsecure-call` ABI
+...
+LL |     f4(AlignRelevant(1), 2);
+   |     ^^^^^^^^^^^^^^^^^^^^^^^ but its arguments don't fit in the available registers
+   |
+   = note: functions with the `C-cmse-nonsecure-call` ABI must pass all their arguments via the 4 32-bit available argument registers
+
+error[E0798]: arguments for `C-cmse-nonsecure-call` function too large to pass via registers
+  --> $DIR/params-via-stack.rs:28:5
+   |
+LL |     f5: extern "C-cmse-nonsecure-call" fn([u32; 5]) -> u32,
+   |     -- this function uses the `C-cmse-nonsecure-call` ABI
+...
+LL |     f5([0xAA; 5]);
+   |     ^^^^^^^^^^^^^ but its arguments don't fit in the available registers
+   |
+   = note: functions with the `C-cmse-nonsecure-call` ABI must pass all their arguments via the 4 32-bit available argument registers
+
+error: aborting due to 5 previous errors
+
+For more information about this error, try `rustc --explain E0798`.
diff --git a/tests/ui/cmse-nonsecure/cmse-nonsecure-call/return-via-stack.rs b/tests/ui/cmse-nonsecure/cmse-nonsecure-call/return-via-stack.rs
new file mode 100644
index 00000000000..c417dddac4f
--- /dev/null
+++ b/tests/ui/cmse-nonsecure/cmse-nonsecure-call/return-via-stack.rs
@@ -0,0 +1,41 @@
+//@ build-fail
+//@ compile-flags: --target thumbv8m.main-none-eabi --crate-type lib
+//@ needs-llvm-components: arm
+#![feature(abi_c_cmse_nonsecure_call, no_core, lang_items, intrinsics)]
+#![no_core]
+#[lang = "sized"]
+pub trait Sized {}
+#[lang = "copy"]
+pub trait Copy {}
+impl Copy for u32 {}
+
+#[repr(C)]
+pub struct ReprCU64(u64);
+
+#[repr(C)]
+pub struct ReprCBytes(u8, u8, u8, u8, u8);
+
+#[repr(C)]
+pub struct U64Compound(u32, u32);
+
+#[repr(C, align(16))]
+pub struct ReprCAlign16(u16);
+
+#[no_mangle]
+pub fn test(
+    f1: extern "C-cmse-nonsecure-call" fn() -> ReprCU64,
+    f2: extern "C-cmse-nonsecure-call" fn() -> ReprCBytes,
+    f3: extern "C-cmse-nonsecure-call" fn() -> U64Compound,
+    f4: extern "C-cmse-nonsecure-call" fn() -> ReprCAlign16,
+    f5: extern "C-cmse-nonsecure-call" fn() -> [u8; 5],
+    f6: extern "C-cmse-nonsecure-call" fn() -> u128, //~ WARNING [improper_ctypes_definitions]
+    f7: extern "C-cmse-nonsecure-call" fn() -> i128, //~ WARNING [improper_ctypes_definitions]
+) {
+    f1(); //~ ERROR [E0798]
+    f2(); //~ ERROR [E0798]
+    f3(); //~ ERROR [E0798]
+    f4(); //~ ERROR [E0798]
+    f5(); //~ ERROR [E0798]
+    f6(); //~ ERROR [E0798]
+    f7(); //~ ERROR [E0798]
+}
diff --git a/tests/ui/cmse-nonsecure/cmse-nonsecure-call/return-via-stack.stderr b/tests/ui/cmse-nonsecure/cmse-nonsecure-call/return-via-stack.stderr
new file mode 100644
index 00000000000..6dea0cf68a0
--- /dev/null
+++ b/tests/ui/cmse-nonsecure/cmse-nonsecure-call/return-via-stack.stderr
@@ -0,0 +1,97 @@
+warning: `extern` fn uses type `u128`, which is not FFI-safe
+  --> $DIR/return-via-stack.rs:31:9
+   |
+LL |     f6: extern "C-cmse-nonsecure-call" fn() -> u128,
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
+   |
+   = note: 128-bit integers don't currently have a known stable ABI
+   = note: `#[warn(improper_ctypes_definitions)]` on by default
+
+warning: `extern` fn uses type `i128`, which is not FFI-safe
+  --> $DIR/return-via-stack.rs:32:9
+   |
+LL |     f7: extern "C-cmse-nonsecure-call" fn() -> i128,
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
+   |
+   = note: 128-bit integers don't currently have a known stable ABI
+
+error[E0798]: return value of `C-cmse-nonsecure-call` function too large to pass via registers
+  --> $DIR/return-via-stack.rs:34:5
+   |
+LL |     f1: extern "C-cmse-nonsecure-call" fn() -> ReprCU64,
+   |     -- this function uses the `C-cmse-nonsecure-call` ABI
+...
+LL |     f1();
+   |     ^^^^ but its return value doesn't fit in the available registers
+   |
+   = note: functions with the `C-cmse-nonsecure-call` ABI must pass their result via the available return registers
+
+error[E0798]: return value of `C-cmse-nonsecure-call` function too large to pass via registers
+  --> $DIR/return-via-stack.rs:35:5
+   |
+LL |     f2: extern "C-cmse-nonsecure-call" fn() -> ReprCBytes,
+   |     -- this function uses the `C-cmse-nonsecure-call` ABI
+...
+LL |     f2();
+   |     ^^^^ but its return value doesn't fit in the available registers
+   |
+   = note: functions with the `C-cmse-nonsecure-call` ABI must pass their result via the available return registers
+
+error[E0798]: return value of `C-cmse-nonsecure-call` function too large to pass via registers
+  --> $DIR/return-via-stack.rs:36:5
+   |
+LL |     f3: extern "C-cmse-nonsecure-call" fn() -> U64Compound,
+   |     -- this function uses the `C-cmse-nonsecure-call` ABI
+...
+LL |     f3();
+   |     ^^^^ but its return value doesn't fit in the available registers
+   |
+   = note: functions with the `C-cmse-nonsecure-call` ABI must pass their result via the available return registers
+
+error[E0798]: return value of `C-cmse-nonsecure-call` function too large to pass via registers
+  --> $DIR/return-via-stack.rs:37:5
+   |
+LL |     f4: extern "C-cmse-nonsecure-call" fn() -> ReprCAlign16,
+   |     -- this function uses the `C-cmse-nonsecure-call` ABI
+...
+LL |     f4();
+   |     ^^^^ but its return value doesn't fit in the available registers
+   |
+   = note: functions with the `C-cmse-nonsecure-call` ABI must pass their result via the available return registers
+
+error[E0798]: return value of `C-cmse-nonsecure-call` function too large to pass via registers
+  --> $DIR/return-via-stack.rs:38:5
+   |
+LL |     f5: extern "C-cmse-nonsecure-call" fn() -> [u8; 5],
+   |     -- this function uses the `C-cmse-nonsecure-call` ABI
+...
+LL |     f5();
+   |     ^^^^ but its return value doesn't fit in the available registers
+   |
+   = note: functions with the `C-cmse-nonsecure-call` ABI must pass their result via the available return registers
+
+error[E0798]: return value of `C-cmse-nonsecure-call` function too large to pass via registers
+  --> $DIR/return-via-stack.rs:39:5
+   |
+LL |     f6: extern "C-cmse-nonsecure-call" fn() -> u128,
+   |     -- this function uses the `C-cmse-nonsecure-call` ABI
+...
+LL |     f6();
+   |     ^^^^ but its return value doesn't fit in the available registers
+   |
+   = note: functions with the `C-cmse-nonsecure-call` ABI must pass their result via the available return registers
+
+error[E0798]: return value of `C-cmse-nonsecure-call` function too large to pass via registers
+  --> $DIR/return-via-stack.rs:40:5
+   |
+LL |     f7: extern "C-cmse-nonsecure-call" fn() -> i128,
+   |     -- this function uses the `C-cmse-nonsecure-call` ABI
+...
+LL |     f7();
+   |     ^^^^ but its return value doesn't fit in the available registers
+   |
+   = note: functions with the `C-cmse-nonsecure-call` ABI must pass their result via the available return registers
+
+error: aborting due to 7 previous errors; 2 warnings emitted
+
+For more information about this error, try `rustc --explain E0798`.
diff --git a/tests/ui/cmse-nonsecure/cmse-nonsecure-call/via-registers.rs b/tests/ui/cmse-nonsecure/cmse-nonsecure-call/via-registers.rs
new file mode 100644
index 00000000000..72b405ef282
--- /dev/null
+++ b/tests/ui/cmse-nonsecure/cmse-nonsecure-call/via-registers.rs
@@ -0,0 +1,55 @@
+//@ build-pass
+//@ compile-flags: --target thumbv8m.main-none-eabi --crate-type lib
+//@ needs-llvm-components: arm
+#![feature(abi_c_cmse_nonsecure_call, no_core, lang_items, intrinsics)]
+#![no_core]
+#[lang = "sized"]
+pub trait Sized {}
+#[lang = "copy"]
+pub trait Copy {}
+impl Copy for u32 {}
+
+#[repr(transparent)]
+pub struct ReprTransparentU64(u64);
+
+#[repr(C)]
+pub struct U32Compound(u16, u16);
+
+#[no_mangle]
+#[allow(improper_ctypes_definitions)]
+pub fn params(
+    f1: extern "C-cmse-nonsecure-call" fn(),
+    f2: extern "C-cmse-nonsecure-call" fn(u32, u32, u32, u32),
+    f3: extern "C-cmse-nonsecure-call" fn(u64, u64),
+    f4: extern "C-cmse-nonsecure-call" fn(u128),
+    f5: extern "C-cmse-nonsecure-call" fn(f64, f32, f32),
+    f6: extern "C-cmse-nonsecure-call" fn(ReprTransparentU64, U32Compound),
+    f7: extern "C-cmse-nonsecure-call" fn([u32; 4]),
+) {
+    f1();
+    f2(1, 2, 3, 4);
+    f3(1, 2);
+    f4(1);
+    f5(1.0, 2.0, 3.0);
+    f6(ReprTransparentU64(1), U32Compound(2, 3));
+    f7([0xDEADBEEF; 4]);
+}
+
+#[no_mangle]
+pub fn returns(
+    f1: extern "C-cmse-nonsecure-call" fn() -> u32,
+    f2: extern "C-cmse-nonsecure-call" fn() -> u64,
+    f3: extern "C-cmse-nonsecure-call" fn() -> i64,
+    f4: extern "C-cmse-nonsecure-call" fn() -> f64,
+    f5: extern "C-cmse-nonsecure-call" fn() -> [u8; 4],
+    f6: extern "C-cmse-nonsecure-call" fn() -> ReprTransparentU64,
+    f7: extern "C-cmse-nonsecure-call" fn() -> U32Compound,
+) {
+    f1();
+    f2();
+    f3();
+    f4();
+    f5();
+    f6();
+    f7();
+}