-
Notifications
You must be signed in to change notification settings - Fork 13.5k
compiler: Allow extern "interrupt" fn() -> !
#143075
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
workingjubilee
wants to merge
4
commits into
rust-lang:master
Choose a base branch
from
workingjubilee:interrupts-may-return-nevermore
base: master
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.
+429
−3
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1045b70
tests: add test for invalid interrupt signatures
workingjubilee db33e98
compiler: fixup error message for x86-interrupt invalid returns
workingjubilee d6b3314
compiler: allow interrupts to return () or !
workingjubilee b5ab966
remember how to write never returns
workingjubilee 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
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,28 @@ | ||
error: invalid signature for `extern "avr-interrupt"` function | ||
--> $DIR/interrupt-invalid-signature.rs:44:35 | ||
| | ||
LL | extern "avr-interrupt" fn avr_arg(_byte: u8) {} | ||
| ^^^^^^^^^ | ||
| | ||
= note: functions with the "avr-interrupt" ABI cannot have any parameters or return type | ||
help: remove the parameters and return type | ||
| | ||
LL - extern "avr-interrupt" fn avr_arg(_byte: u8) {} | ||
LL + extern "avr-interrupt" fn avr_arg() {} | ||
| | ||
|
||
error: invalid signature for `extern "avr-interrupt"` function | ||
--> $DIR/interrupt-invalid-signature.rs:59:40 | ||
| | ||
LL | extern "avr-interrupt" fn avr_ret() -> u8 { | ||
| ^^ | ||
| | ||
= note: functions with the "avr-interrupt" ABI cannot have any parameters or return type | ||
help: remove the parameters and return type | ||
| | ||
LL - extern "avr-interrupt" fn avr_ret() -> u8 { | ||
LL + extern "avr-interrupt" fn avr_ret() { | ||
| | ||
|
||
error: aborting due to 2 previous errors | ||
|
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,15 @@ | ||
error: invalid signature for `extern "x86-interrupt"` function | ||
--> $DIR/interrupt-invalid-signature.rs:83:40 | ||
| | ||
LL | extern "x86-interrupt" fn x86_ret() -> u8 { | ||
| ^^ | ||
| | ||
= note: functions with the "x86-interrupt" ABI cannot have a return type | ||
help: remove the return type | ||
--> $DIR/interrupt-invalid-signature.rs:83:40 | ||
| | ||
LL | extern "x86-interrupt" fn x86_ret() -> u8 { | ||
| ^^ | ||
|
||
error: aborting due to 1 previous error | ||
|
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,28 @@ | ||
error: invalid signature for `extern "msp430-interrupt"` function | ||
--> $DIR/interrupt-invalid-signature.rs:40:41 | ||
| | ||
LL | extern "msp430-interrupt" fn msp430_arg(_byte: u8) {} | ||
| ^^^^^^^^^ | ||
| | ||
= note: functions with the "msp430-interrupt" ABI cannot have any parameters or return type | ||
help: remove the parameters and return type | ||
| | ||
LL - extern "msp430-interrupt" fn msp430_arg(_byte: u8) {} | ||
LL + extern "msp430-interrupt" fn msp430_arg() {} | ||
| | ||
|
||
error: invalid signature for `extern "msp430-interrupt"` function | ||
--> $DIR/interrupt-invalid-signature.rs:65:46 | ||
| | ||
LL | extern "msp430-interrupt" fn msp430_ret() -> u8 { | ||
| ^^ | ||
| | ||
= note: functions with the "msp430-interrupt" ABI cannot have any parameters or return type | ||
help: remove the parameters and return type | ||
| | ||
LL - extern "msp430-interrupt" fn msp430_ret() -> u8 { | ||
LL + extern "msp430-interrupt" fn msp430_ret() { | ||
| | ||
|
||
error: aborting due to 2 previous errors | ||
|
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,54 @@ | ||
error: invalid signature for `extern "riscv-interrupt-m"` function | ||
--> $DIR/interrupt-invalid-signature.rs:48:43 | ||
| | ||
LL | extern "riscv-interrupt-m" fn riscv_m_arg(_byte: u8) {} | ||
| ^^^^^^^^^ | ||
| | ||
= note: functions with the "riscv-interrupt-m" ABI cannot have any parameters or return type | ||
help: remove the parameters and return type | ||
| | ||
LL - extern "riscv-interrupt-m" fn riscv_m_arg(_byte: u8) {} | ||
LL + extern "riscv-interrupt-m" fn riscv_m_arg() {} | ||
| | ||
|
||
error: invalid signature for `extern "riscv-interrupt-s"` function | ||
--> $DIR/interrupt-invalid-signature.rs:52:43 | ||
| | ||
LL | extern "riscv-interrupt-s" fn riscv_s_arg(_byte: u8) {} | ||
| ^^^^^^^^^ | ||
| | ||
= note: functions with the "riscv-interrupt-s" ABI cannot have any parameters or return type | ||
help: remove the parameters and return type | ||
| | ||
LL - extern "riscv-interrupt-s" fn riscv_s_arg(_byte: u8) {} | ||
LL + extern "riscv-interrupt-s" fn riscv_s_arg() {} | ||
| | ||
|
||
error: invalid signature for `extern "riscv-interrupt-m"` function | ||
--> $DIR/interrupt-invalid-signature.rs:71:48 | ||
| | ||
LL | extern "riscv-interrupt-m" fn riscv_m_ret() -> u8 { | ||
| ^^ | ||
| | ||
= note: functions with the "riscv-interrupt-m" ABI cannot have any parameters or return type | ||
help: remove the parameters and return type | ||
| | ||
LL - extern "riscv-interrupt-m" fn riscv_m_ret() -> u8 { | ||
LL + extern "riscv-interrupt-m" fn riscv_m_ret() { | ||
| | ||
|
||
error: invalid signature for `extern "riscv-interrupt-s"` function | ||
--> $DIR/interrupt-invalid-signature.rs:77:48 | ||
| | ||
LL | extern "riscv-interrupt-s" fn riscv_s_ret() -> u8 { | ||
| ^^ | ||
| | ||
= note: functions with the "riscv-interrupt-s" ABI cannot have any parameters or return type | ||
help: remove the parameters and return type | ||
| | ||
LL - extern "riscv-interrupt-s" fn riscv_s_ret() -> u8 { | ||
LL + extern "riscv-interrupt-s" fn riscv_s_ret() { | ||
| | ||
|
||
error: aborting due to 4 previous errors | ||
|
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,54 @@ | ||
error: invalid signature for `extern "riscv-interrupt-m"` function | ||
--> $DIR/interrupt-invalid-signature.rs:48:43 | ||
| | ||
LL | extern "riscv-interrupt-m" fn riscv_m_arg(_byte: u8) {} | ||
| ^^^^^^^^^ | ||
| | ||
= note: functions with the "riscv-interrupt-m" ABI cannot have any parameters or return type | ||
help: remove the parameters and return type | ||
| | ||
LL - extern "riscv-interrupt-m" fn riscv_m_arg(_byte: u8) {} | ||
LL + extern "riscv-interrupt-m" fn riscv_m_arg() {} | ||
| | ||
|
||
error: invalid signature for `extern "riscv-interrupt-s"` function | ||
--> $DIR/interrupt-invalid-signature.rs:52:43 | ||
| | ||
LL | extern "riscv-interrupt-s" fn riscv_s_arg(_byte: u8) {} | ||
| ^^^^^^^^^ | ||
| | ||
= note: functions with the "riscv-interrupt-s" ABI cannot have any parameters or return type | ||
help: remove the parameters and return type | ||
| | ||
LL - extern "riscv-interrupt-s" fn riscv_s_arg(_byte: u8) {} | ||
LL + extern "riscv-interrupt-s" fn riscv_s_arg() {} | ||
| | ||
|
||
error: invalid signature for `extern "riscv-interrupt-m"` function | ||
--> $DIR/interrupt-invalid-signature.rs:71:48 | ||
| | ||
LL | extern "riscv-interrupt-m" fn riscv_m_ret() -> u8 { | ||
| ^^ | ||
| | ||
= note: functions with the "riscv-interrupt-m" ABI cannot have any parameters or return type | ||
help: remove the parameters and return type | ||
| | ||
LL - extern "riscv-interrupt-m" fn riscv_m_ret() -> u8 { | ||
LL + extern "riscv-interrupt-m" fn riscv_m_ret() { | ||
| | ||
|
||
error: invalid signature for `extern "riscv-interrupt-s"` function | ||
--> $DIR/interrupt-invalid-signature.rs:77:48 | ||
| | ||
LL | extern "riscv-interrupt-s" fn riscv_s_ret() -> u8 { | ||
| ^^ | ||
| | ||
= note: functions with the "riscv-interrupt-s" ABI cannot have any parameters or return type | ||
help: remove the parameters and return type | ||
| | ||
LL - extern "riscv-interrupt-s" fn riscv_s_ret() -> u8 { | ||
LL + extern "riscv-interrupt-s" fn riscv_s_ret() { | ||
| | ||
|
||
error: aborting due to 4 previous errors | ||
|
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,110 @@ | ||
/*! Tests interrupt ABIs have a constricted signature | ||
Most interrupt ABIs share a similar restriction in terms of not allowing most signatures. | ||
Specifically, they generally cannot have arguments or return types. | ||
So we test that they error in essentially all of the same places. | ||
A notable and interesting exception is x86. | ||
This test uses `cfg` because it is not testing whether these ABIs work on the platform. | ||
*/ | ||
//@ add-core-stubs | ||
//@ revisions: x64 i686 riscv32 riscv64 avr msp430 | ||
// | ||
//@ [x64] needs-llvm-components: x86 | ||
//@ [x64] compile-flags: --target=x86_64-unknown-linux-gnu --crate-type=rlib | ||
//@ [i686] needs-llvm-components: x86 | ||
//@ [i686] compile-flags: --target=i686-unknown-linux-gnu --crate-type=rlib | ||
//@ [riscv32] needs-llvm-components: riscv | ||
//@ [riscv32] compile-flags: --target=riscv32i-unknown-none-elf --crate-type=rlib | ||
//@ [riscv64] needs-llvm-components: riscv | ||
//@ [riscv64] compile-flags: --target=riscv64gc-unknown-none-elf --crate-type=rlib | ||
//@ [avr] needs-llvm-components: avr | ||
//@ [avr] compile-flags: --target=avr-none -C target-cpu=atmega328p --crate-type=rlib | ||
//@ [msp430] needs-llvm-components: msp430 | ||
//@ [msp430] compile-flags: --target=msp430-none-elf --crate-type=rlib | ||
#![no_core] | ||
#![feature( | ||
no_core, | ||
abi_msp430_interrupt, | ||
abi_avr_interrupt, | ||
abi_x86_interrupt, | ||
abi_riscv_interrupt | ||
)] | ||
|
||
extern crate minicore; | ||
use minicore::*; | ||
|
||
/* most extern "interrupt" definitions should not accept args */ | ||
|
||
#[cfg(msp430)] | ||
extern "msp430-interrupt" fn msp430_arg(_byte: u8) {} | ||
//[msp430]~^ ERROR invalid signature | ||
|
||
#[cfg(avr)] | ||
extern "avr-interrupt" fn avr_arg(_byte: u8) {} | ||
//[avr]~^ ERROR invalid signature | ||
|
||
#[cfg(any(riscv32,riscv64))] | ||
extern "riscv-interrupt-m" fn riscv_m_arg(_byte: u8) {} | ||
//[riscv32,riscv64]~^ ERROR invalid signature | ||
|
||
#[cfg(any(riscv32,riscv64))] | ||
extern "riscv-interrupt-s" fn riscv_s_arg(_byte: u8) {} | ||
//[riscv32,riscv64]~^ ERROR invalid signature | ||
|
||
|
||
/* all extern "interrupt" definitions should not return non-1ZST values */ | ||
|
||
#[cfg(avr)] | ||
extern "avr-interrupt" fn avr_ret() -> u8 { | ||
//[avr]~^ ERROR invalid signature | ||
1 | ||
} | ||
|
||
#[cfg(msp430)] | ||
extern "msp430-interrupt" fn msp430_ret() -> u8 { | ||
//[msp430]~^ ERROR invalid signature | ||
1 | ||
} | ||
|
||
#[cfg(any(riscv32,riscv64))] | ||
extern "riscv-interrupt-m" fn riscv_m_ret() -> u8 { | ||
//[riscv32,riscv64]~^ ERROR invalid signature | ||
1 | ||
} | ||
|
||
#[cfg(any(riscv32,riscv64))] | ||
extern "riscv-interrupt-s" fn riscv_s_ret() -> u8 { | ||
//[riscv32,riscv64]~^ ERROR invalid signature | ||
1 | ||
} | ||
|
||
#[cfg(any(x64,i686))] | ||
extern "x86-interrupt" fn x86_ret() -> u8 { | ||
//[x64,i686]~^ ERROR invalid signature | ||
1 | ||
} | ||
|
||
|
||
|
||
/* extern "interrupt" fnptrs with invalid signatures */ | ||
|
||
#[cfg(avr)] | ||
fn avr_ptr(_f: extern "avr-interrupt" fn(u8) -> u8) { | ||
} | ||
|
||
#[cfg(msp430)] | ||
fn msp430_ptr(_f: extern "msp430-interrupt" fn(u8) -> u8) { | ||
} | ||
|
||
#[cfg(any(riscv32,riscv64))] | ||
fn riscv_m_ptr(_f: extern "riscv-interrupt-m" fn(u8) -> u8) { | ||
} | ||
|
||
#[cfg(any(riscv32,riscv64))] | ||
fn riscv_s_ptr(_f: extern "riscv-interrupt-s" fn(u8) -> u8) { | ||
} | ||
|
||
#[cfg(any(x64,i686))] | ||
fn x86_ptr(_f: extern "x86-interrupt" fn() -> u8) { | ||
} |
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,15 @@ | ||
error: invalid signature for `extern "x86-interrupt"` function | ||
--> $DIR/interrupt-invalid-signature.rs:83:40 | ||
| | ||
LL | extern "x86-interrupt" fn x86_ret() -> u8 { | ||
| ^^ | ||
| | ||
= note: functions with the "x86-interrupt" ABI cannot have a return type | ||
help: remove the return type | ||
--> $DIR/interrupt-invalid-signature.rs:83:40 | ||
| | ||
LL | extern "x86-interrupt" fn x86_ret() -> u8 { | ||
| ^^ | ||
|
||
error: aborting due to 1 previous error | ||
|
Oops, something went wrong.
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.
Actually, @folkertdev, I think the biggest logic with moving this to
hir_typeck
is I'm not actually sure if that's the right place for an ad-hoc validation check on the HIR. And I don't know if I should trust the previous places we put ABI checks. 😵💫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.
I just know that it's where we now perform the checks for
extern "custom"
and for naked functions there. They were previously inrustc_passes
but moving them intohir_typeck
was both shorter and faster.