Skip to content

Commit 6333a8b

Browse files
authored
Rollup merge of #146551 - folkertdev:cmse-entry-c-variadic, r=workingjubilee
fix issue with `cmse-nonsecure-entry` ABI being both async and c-variadic tracking issue: #75835 fixes #132142 An `extern "cmse-nonsecure-entry"` function cannot be c-variadic (or, in any case, clang/LLVM does not support it, see https://godbolt.org/z/MaPjzGcE1). So just stop looking at the type if we know it'll be invalid anyway. I'm not entirely sure how to test this. The ICE is only possible on the `thumbv8m.main-none-eabi` and some related targets. I think using `minicore` is the most convenient, but use of `async` requires quite a long list of lang items to be present. Maybe we want that anyway though? On the other hand, it's extra `minicore` surface that might go out of date. An alternative is `run-make`, that should work, but is much less convenient. See also [#t-compiler/help > `async fn` and `minicore`](https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/.60async.20fn.60.20and.20.60minicore.60/with/539427262). r? `@ghost`
2 parents b0c55c8 + 8b752cb commit 6333a8b

File tree

6 files changed

+105
-26
lines changed

6 files changed

+105
-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: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
// Below are the lang items that are required for a program that defines an `async` function.
25+
// Without them, the ICE that is tested for here is not reached for this target. For now they are in
26+
// this file, but they may be moved into `minicore` if/when other `#[no_core]` tests want to use
27+
// them.
28+
29+
// NOTE: in `core` this type uses `NonNull`.
30+
#[lang = "ResumeTy"]
31+
pub struct ResumeTy(*mut Context<'static>);
32+
33+
#[lang = "future_trait"]
34+
pub trait Future {
35+
/// The type of value produced on completion.
36+
#[lang = "future_output"]
37+
type Output;
38+
39+
// NOTE: misses the `poll` method.
40+
}
41+
42+
#[lang = "async_drop"]
43+
pub trait AsyncDrop {
44+
// NOTE: misses the `drop` method.
45+
}
46+
47+
#[lang = "Poll"]
48+
pub enum Poll<T> {
49+
#[lang = "Ready"]
50+
Ready(T),
51+
52+
#[lang = "Pending"]
53+
Pending,
54+
}
55+
56+
#[lang = "Context"]
57+
pub struct Context<'a> {
58+
// NOTE: misses a bunch of fields.
59+
_marker: PhantomData<fn(&'a ()) -> &'a ()>,
60+
}
61+
62+
#[lang = "get_context"]
63+
pub unsafe fn get_context<'a, 'b>(cx: ResumeTy) -> &'a mut Context<'b> {
64+
// NOTE: the actual implementation looks different.
65+
mem::transmute(cx.0)
66+
}
67+
68+
#[lang = "pin"]
69+
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)