-
Notifications
You must be signed in to change notification settings - Fork 14k
error when ABI does not support guaranteed tail calls #148878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
folkertdev
wants to merge
1
commit into
rust-lang:main
Choose a base branch
from
folkertdev:tail-call-unsupported-abi
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+163
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
tests/ui/explicit-tail-calls/unsupported-abi/cmse-nonsecure-call.rs
folkertdev marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| //@ add-minicore | ||
| //@ ignore-backends: gcc | ||
| //@ compile-flags: --target thumbv8m.main-none-eabi --crate-type lib | ||
| //@ needs-llvm-components: arm | ||
| #![expect(incomplete_features)] | ||
| #![feature(no_core, explicit_tail_calls, abi_cmse_nonsecure_call)] | ||
| #![no_core] | ||
|
|
||
| extern crate minicore; | ||
| use minicore::*; | ||
|
|
||
| unsafe extern "C" { | ||
| safe fn magic() -> extern "cmse-nonsecure-call" fn(u32, u32) -> u32; | ||
| } | ||
|
|
||
| // The `cmse-nonsecure-call` ABI can only occur on function pointers: | ||
| // | ||
| // - a `cmse-nonsecure-call` definition throws an error | ||
| // - a `cmse-nonsecure-call` become in a definition with any other ABI is an ABI mismatch | ||
| #[no_mangle] | ||
| extern "cmse-nonsecure-call" fn become_nonsecure_call_1(x: u32, y: u32) -> u32 { | ||
| //~^ ERROR the `"cmse-nonsecure-call"` ABI is only allowed on function pointers | ||
| unsafe { | ||
| let f = magic(); | ||
| become f(1, 2) | ||
| //~^ ERROR ABI does not support guaranteed tail calls | ||
| } | ||
| } | ||
|
|
||
| #[no_mangle] | ||
| extern "C" fn become_nonsecure_call_2(x: u32, y: u32) -> u32 { | ||
| unsafe { | ||
| let f = magic(); | ||
| become f(1, 2) | ||
| //~^ ERROR mismatched function ABIs | ||
| //~| ERROR ABI does not support guaranteed tail calls | ||
| } | ||
| } |
34 changes: 34 additions & 0 deletions
34
tests/ui/explicit-tail-calls/unsupported-abi/cmse-nonsecure-call.stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| error[E0781]: the `"cmse-nonsecure-call"` ABI is only allowed on function pointers | ||
| --> $DIR/cmse-nonsecure-call.rs:21:1 | ||
| | | ||
| LL | extern "cmse-nonsecure-call" fn become_nonsecure_call_1(x: u32, y: u32) -> u32 { | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| error: ABI does not support guaranteed tail calls | ||
| --> $DIR/cmse-nonsecure-call.rs:25:9 | ||
| | | ||
| LL | become f(1, 2) | ||
| | ^^^^^^^^^^^^^^ | ||
| | | ||
| = note: `become` is not supported for `extern "cmse-nonsecure-call"` functions | ||
|
|
||
| error: mismatched function ABIs | ||
| --> $DIR/cmse-nonsecure-call.rs:34:9 | ||
| | | ||
| LL | become f(1, 2) | ||
| | ^^^^^^^^^^^^^^ | ||
| | | ||
| = note: `become` requires caller and callee to have the same ABI | ||
| = note: caller ABI is `"C"`, while callee ABI is `"cmse-nonsecure-call"` | ||
|
|
||
| error: ABI does not support guaranteed tail calls | ||
| --> $DIR/cmse-nonsecure-call.rs:34:9 | ||
| | | ||
| LL | become f(1, 2) | ||
| | ^^^^^^^^^^^^^^ | ||
| | | ||
| = note: `become` is not supported for `extern "cmse-nonsecure-call"` functions | ||
|
|
||
| error: aborting due to 4 previous errors | ||
|
|
||
| For more information about this error, try `rustc --explain E0781`. |
22 changes: 22 additions & 0 deletions
22
tests/ui/explicit-tail-calls/unsupported-abi/cmse-nonsecure-entry.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| //@ add-minicore | ||
| //@ ignore-backends: gcc | ||
| //@ compile-flags: --target thumbv8m.main-none-eabi --crate-type lib | ||
| //@ needs-llvm-components: arm | ||
| #![expect(incomplete_features)] | ||
| #![feature(no_core, explicit_tail_calls, cmse_nonsecure_entry)] | ||
| #![no_core] | ||
|
|
||
| extern crate minicore; | ||
| use minicore::*; | ||
|
|
||
| #[inline(never)] | ||
| extern "cmse-nonsecure-entry" fn entry(c: bool, x: u32, y: u32) -> u32 { | ||
| if c { x } else { y } | ||
| } | ||
|
|
||
| // A `cmse-nonsecure-entry` clears registers before returning, so a tail call cannot be guaranteed. | ||
| #[unsafe(no_mangle)] | ||
| extern "cmse-nonsecure-entry" fn become_nonsecure_entry(c: bool, x: u32, y: u32) -> u32 { | ||
| become entry(c, x, y) | ||
| //~^ ERROR ABI does not support guaranteed tail calls | ||
| } |
10 changes: 10 additions & 0 deletions
10
tests/ui/explicit-tail-calls/unsupported-abi/cmse-nonsecure-entry.stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| error: ABI does not support guaranteed tail calls | ||
| --> $DIR/cmse-nonsecure-entry.rs:20:5 | ||
| | | ||
| LL | become entry(c, x, y) | ||
| | ^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| = note: `become` is not supported for `extern "cmse-nonsecure-entry"` functions | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When stabilization comes closer, we might want to do something like what c-variadic does above and classify specifically for which ABIs tail calls are stabilized. Because I don't think we (at least currently) test all of these ABIs thoroughly.