Skip to content

Commit 8fc9af3

Browse files
committed
fix issue with cmse-nonsecure-entry ABI being both async and c-variadic
1 parent 52618eb commit 8fc9af3

File tree

6 files changed

+99
-26
lines changed

6 files changed

+99
-26
lines changed

compiler/rustc_hir_analysis/src/hir_ty_lowering/cmse.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ pub(crate) fn validate_cmse_abi<'tcx>(
8585
return;
8686
};
8787

88+
// An `extern "cmse-nonsecure-entry"` function cannot be c-variadic. We run
89+
// into https://github.com/rust-lang/rust/issues/132142 if we don't explicitly bail.
90+
if decl.c_variadic {
91+
return;
92+
}
93+
8894
match is_valid_cmse_inputs(tcx, fn_sig) {
8995
Ok(Ok(())) => {}
9096
Ok(Err(index)) => {

tests/crashes/132142.rs

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
//@ add-core-stubs
2+
//@ edition: 2018
3+
//@ compile-flags: --target thumbv8m.main-none-eabi --crate-type lib
4+
//@ needs-llvm-components: arm
5+
#![feature(cmse_nonsecure_entry, c_variadic, no_core, lang_items)]
6+
#![no_core]
7+
8+
extern crate minicore;
9+
use minicore::*;
10+
11+
#[lang = "va_list"]
12+
struct VaList(*mut u8);
13+
14+
unsafe extern "cmse-nonsecure-entry" fn c_variadic(_: u32, _: ...) {
15+
//~^ ERROR `...` is not supported for `extern "cmse-nonsecure-entry"` functions
16+
}
17+
18+
// A regression test for https://github.com/rust-lang/rust/issues/132142
19+
async unsafe extern "cmse-nonsecure-entry" fn async_and_c_variadic(_: ...) {
20+
//~^ ERROR `...` is not supported for `extern "cmse-nonsecure-entry"` functions
21+
//~| ERROR functions cannot be both `async` and C-variadic
22+
}
23+
24+
#[lang = "ResumeTy"]
25+
pub struct ResumeTy(*mut u8);
26+
27+
#[lang = "future_trait"]
28+
pub trait Future {
29+
/// The type of value produced on completion.
30+
#[lang = "future_output"]
31+
type Output;
32+
}
33+
34+
#[lang = "async_drop"]
35+
pub trait AsyncDrop {}
36+
37+
#[lang = "Poll"]
38+
pub enum Poll<T> {
39+
/// Represents that a value is immediately ready.
40+
#[lang = "Ready"]
41+
Ready(T),
42+
43+
/// Represents that a value is not ready yet.
44+
///
45+
/// When a function returns `Pending`, the function *must* also
46+
/// ensure that the current task is scheduled to be awoken when
47+
/// progress can be made.
48+
#[lang = "Pending"]
49+
Pending,
50+
}
51+
52+
#[lang = "Context"]
53+
pub struct Context<'a> {
54+
_marker: PhantomData<fn(&'a ()) -> &'a ()>,
55+
}
56+
57+
#[lang = "get_context"]
58+
pub unsafe fn get_context<'a, 'b>(cx: ResumeTy) -> &'a mut Context<'b> {
59+
loop {}
60+
}
61+
62+
#[lang = "pin"]
63+
pub struct Pin<T>(T);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
error: `...` is not supported for `extern "cmse-nonsecure-entry"` functions
2+
--> $DIR/c-variadic.rs:14:60
3+
|
4+
LL | unsafe extern "cmse-nonsecure-entry" fn c_variadic(_: u32, _: ...) {
5+
| ----------------------------- ^^^^^^
6+
| |
7+
| `extern "cmse-nonsecure-entry"` because of this
8+
|
9+
= help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
10+
11+
error: functions cannot be both `async` and C-variadic
12+
--> $DIR/c-variadic.rs:19:1
13+
|
14+
LL | async unsafe extern "cmse-nonsecure-entry" fn async_and_c_variadic(_: ...) {
15+
| ^^^^^ `async` because of this ^^^^^^ C-variadic because of this
16+
17+
error: `...` is not supported for `extern "cmse-nonsecure-entry"` functions
18+
--> $DIR/c-variadic.rs:19:68
19+
|
20+
LL | async unsafe extern "cmse-nonsecure-entry" fn async_and_c_variadic(_: ...) {
21+
| ----------------------------- ^^^^^^
22+
| |
23+
| `extern "cmse-nonsecure-entry"` because of this
24+
|
25+
= help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
26+
27+
error: aborting due to 3 previous errors
28+

tests/ui/cmse-nonsecure/cmse-nonsecure-entry/generics.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@ add-core-stubs
22
//@ compile-flags: --target thumbv8m.main-none-eabi --crate-type lib
33
//@ needs-llvm-components: arm
4-
#![feature(cmse_nonsecure_entry, c_variadic, no_core, lang_items)]
4+
#![feature(cmse_nonsecure_entry, no_core, lang_items)]
55
#![no_core]
66

77
extern crate minicore;
@@ -65,8 +65,3 @@ extern "cmse-nonsecure-entry" fn wrapped_trait_object(x: WrapperTransparent) ->
6565
//~^ ERROR return value of `"cmse-nonsecure-entry"` function too large to pass via registers [E0798]
6666
x
6767
}
68-
69-
unsafe extern "cmse-nonsecure-entry" fn c_variadic(_: u32, _: ...) {
70-
//~^ ERROR `...` is not supported for `extern "cmse-nonsecure-entry"` functions
71-
//~| ERROR requires `va_list` lang_item
72-
}

tests/ui/cmse-nonsecure/cmse-nonsecure-entry/generics.stderr

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
error: `...` is not supported for `extern "cmse-nonsecure-entry"` functions
2-
--> $DIR/generics.rs:69:60
3-
|
4-
LL | unsafe extern "cmse-nonsecure-entry" fn c_variadic(_: u32, _: ...) {
5-
| ----------------------------- ^^^^^^
6-
| |
7-
| `extern "cmse-nonsecure-entry"` because of this
8-
|
9-
= help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
10-
111
error[E0798]: functions with the `"cmse-nonsecure-entry"` ABI cannot contain generics in their type
122
--> $DIR/generics.rs:30:1
133
|
@@ -71,12 +61,6 @@ LL | extern "cmse-nonsecure-entry" fn wrapped_trait_object(x: WrapperTransparent
7161
= note: functions with the `"cmse-nonsecure-entry"` ABI must pass their result via the available return registers
7262
= note: the result must either be a (transparently wrapped) i64, u64 or f64, or be at most 4 bytes in size
7363

74-
error: requires `va_list` lang_item
75-
--> $DIR/generics.rs:69:60
76-
|
77-
LL | unsafe extern "cmse-nonsecure-entry" fn c_variadic(_: u32, _: ...) {
78-
| ^^^^^^
79-
80-
error: aborting due to 9 previous errors
64+
error: aborting due to 7 previous errors
8165

8266
For more information about this error, try `rustc --explain E0798`.

0 commit comments

Comments
 (0)