about summary refs log tree commit diff
path: root/tests/ui/cmse-nonsecure
diff options
context:
space:
mode:
authorFolkert de Vries <folkert@folkertdev.nl>2025-09-14 21:14:37 +0200
committerFolkert de Vries <folkert@folkertdev.nl>2025-09-16 10:23:07 +0200
commit8b752cb37d646118c46f7739ae965b8e9c9a9b03 (patch)
tree80d5a3e5f478d00d68ea96e87ded854bfa2a5b00 /tests/ui/cmse-nonsecure
parent8a1b39995e5b630c5872f5de5079f1f569bd5ac2 (diff)
downloadrust-8b752cb37d646118c46f7739ae965b8e9c9a9b03.tar.gz
rust-8b752cb37d646118c46f7739ae965b8e9c9a9b03.zip
fix issue with `cmse-nonsecure-entry` ABI being both async and c-variadic
Diffstat (limited to 'tests/ui/cmse-nonsecure')
-rw-r--r--tests/ui/cmse-nonsecure/cmse-nonsecure-entry/c-variadic.rs69
-rw-r--r--tests/ui/cmse-nonsecure/cmse-nonsecure-entry/c-variadic.stderr28
-rw-r--r--tests/ui/cmse-nonsecure/cmse-nonsecure-entry/generics.rs7
-rw-r--r--tests/ui/cmse-nonsecure/cmse-nonsecure-entry/generics.stderr18
4 files changed, 99 insertions, 23 deletions
diff --git a/tests/ui/cmse-nonsecure/cmse-nonsecure-entry/c-variadic.rs b/tests/ui/cmse-nonsecure/cmse-nonsecure-entry/c-variadic.rs
new file mode 100644
index 00000000000..9317ab5cd27
--- /dev/null
+++ b/tests/ui/cmse-nonsecure/cmse-nonsecure-entry/c-variadic.rs
@@ -0,0 +1,69 @@
+//@ add-core-stubs
+//@ edition: 2018
+//@ compile-flags: --target thumbv8m.main-none-eabi --crate-type lib
+//@ needs-llvm-components: arm
+#![feature(cmse_nonsecure_entry, c_variadic, no_core, lang_items)]
+#![no_core]
+
+extern crate minicore;
+use minicore::*;
+
+#[lang = "va_list"]
+struct VaList(*mut u8);
+
+unsafe extern "cmse-nonsecure-entry" fn c_variadic(_: u32, _: ...) {
+    //~^ ERROR `...` is not supported for `extern "cmse-nonsecure-entry"` functions
+}
+
+// A regression test for https://github.com/rust-lang/rust/issues/132142
+async unsafe extern "cmse-nonsecure-entry" fn async_and_c_variadic(_: ...) {
+    //~^ ERROR `...` is not supported for `extern "cmse-nonsecure-entry"` functions
+    //~| ERROR functions cannot be both `async` and C-variadic
+}
+
+// Below are the lang items that are required for a program that defines an `async` function.
+// Without them, the ICE that is tested for here is not reached for this target. For now they are in
+// this file, but they may be moved into `minicore` if/when other `#[no_core]` tests want to use
+// them.
+
+// NOTE: in `core` this type uses `NonNull`.
+#[lang = "ResumeTy"]
+pub struct ResumeTy(*mut Context<'static>);
+
+#[lang = "future_trait"]
+pub trait Future {
+    /// The type of value produced on completion.
+    #[lang = "future_output"]
+    type Output;
+
+    // NOTE: misses the `poll` method.
+}
+
+#[lang = "async_drop"]
+pub trait AsyncDrop {
+    // NOTE: misses the `drop` method.
+}
+
+#[lang = "Poll"]
+pub enum Poll<T> {
+    #[lang = "Ready"]
+    Ready(T),
+
+    #[lang = "Pending"]
+    Pending,
+}
+
+#[lang = "Context"]
+pub struct Context<'a> {
+    // NOTE: misses a bunch of fields.
+    _marker: PhantomData<fn(&'a ()) -> &'a ()>,
+}
+
+#[lang = "get_context"]
+pub unsafe fn get_context<'a, 'b>(cx: ResumeTy) -> &'a mut Context<'b> {
+    // NOTE: the actual implementation looks different.
+    mem::transmute(cx.0)
+}
+
+#[lang = "pin"]
+pub struct Pin<T>(T);
diff --git a/tests/ui/cmse-nonsecure/cmse-nonsecure-entry/c-variadic.stderr b/tests/ui/cmse-nonsecure/cmse-nonsecure-entry/c-variadic.stderr
new file mode 100644
index 00000000000..948f8f5747b
--- /dev/null
+++ b/tests/ui/cmse-nonsecure/cmse-nonsecure-entry/c-variadic.stderr
@@ -0,0 +1,28 @@
+error: `...` is not supported for `extern "cmse-nonsecure-entry"` functions
+  --> $DIR/c-variadic.rs:14:60
+   |
+LL | unsafe extern "cmse-nonsecure-entry" fn c_variadic(_: u32, _: ...) {
+   |        -----------------------------                       ^^^^^^
+   |        |
+   |        `extern "cmse-nonsecure-entry"` because of this
+   |
+   = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
+
+error: functions cannot be both `async` and C-variadic
+  --> $DIR/c-variadic.rs:19:1
+   |
+LL | async unsafe extern "cmse-nonsecure-entry" fn async_and_c_variadic(_: ...) {
+   | ^^^^^ `async` because of this                                      ^^^^^^ C-variadic because of this
+
+error: `...` is not supported for `extern "cmse-nonsecure-entry"` functions
+  --> $DIR/c-variadic.rs:19:68
+   |
+LL | async unsafe extern "cmse-nonsecure-entry" fn async_and_c_variadic(_: ...) {
+   |              -----------------------------                         ^^^^^^
+   |              |
+   |              `extern "cmse-nonsecure-entry"` because of this
+   |
+   = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
+
+error: aborting due to 3 previous errors
+
diff --git a/tests/ui/cmse-nonsecure/cmse-nonsecure-entry/generics.rs b/tests/ui/cmse-nonsecure/cmse-nonsecure-entry/generics.rs
index eb6f4a32365..aee01e25ddc 100644
--- a/tests/ui/cmse-nonsecure/cmse-nonsecure-entry/generics.rs
+++ b/tests/ui/cmse-nonsecure/cmse-nonsecure-entry/generics.rs
@@ -1,7 +1,7 @@
 //@ add-core-stubs
 //@ compile-flags: --target thumbv8m.main-none-eabi --crate-type lib
 //@ needs-llvm-components: arm
-#![feature(cmse_nonsecure_entry, c_variadic, no_core, lang_items)]
+#![feature(cmse_nonsecure_entry, no_core, lang_items)]
 #![no_core]
 
 extern crate minicore;
@@ -65,8 +65,3 @@ extern "cmse-nonsecure-entry" fn wrapped_trait_object(x: WrapperTransparent) ->
     //~^ ERROR return value of `"cmse-nonsecure-entry"` function too large to pass via registers [E0798]
     x
 }
-
-unsafe extern "cmse-nonsecure-entry" fn c_variadic(_: u32, _: ...) {
-    //~^ ERROR `...` is not supported for `extern "cmse-nonsecure-entry"` functions
-    //~| ERROR requires `va_list` lang_item
-}
diff --git a/tests/ui/cmse-nonsecure/cmse-nonsecure-entry/generics.stderr b/tests/ui/cmse-nonsecure/cmse-nonsecure-entry/generics.stderr
index 8937def9428..df1a9107043 100644
--- a/tests/ui/cmse-nonsecure/cmse-nonsecure-entry/generics.stderr
+++ b/tests/ui/cmse-nonsecure/cmse-nonsecure-entry/generics.stderr
@@ -1,13 +1,3 @@
-error: `...` is not supported for `extern "cmse-nonsecure-entry"` functions
-  --> $DIR/generics.rs:69:60
-   |
-LL | unsafe extern "cmse-nonsecure-entry" fn c_variadic(_: u32, _: ...) {
-   |        -----------------------------                       ^^^^^^
-   |        |
-   |        `extern "cmse-nonsecure-entry"` because of this
-   |
-   = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
-
 error[E0798]: functions with the `"cmse-nonsecure-entry"` ABI cannot contain generics in their type
   --> $DIR/generics.rs:30:1
    |
@@ -71,12 +61,6 @@ LL | extern "cmse-nonsecure-entry" fn wrapped_trait_object(x: WrapperTransparent
    = note: functions with the `"cmse-nonsecure-entry"` ABI must pass their result via the available return registers
    = note: the result must either be a (transparently wrapped) i64, u64 or f64, or be at most 4 bytes in size
 
-error: requires `va_list` lang_item
-  --> $DIR/generics.rs:69:60
-   |
-LL | unsafe extern "cmse-nonsecure-entry" fn c_variadic(_: u32, _: ...) {
-   |                                                            ^^^^^^
-
-error: aborting due to 9 previous errors
+error: aborting due to 7 previous errors
 
 For more information about this error, try `rustc --explain E0798`.