Skip to content

Commit 08984d5

Browse files
authored
Rollup merge of #145662 - GrigorenkoPV:x86-interrupt, r=compiler-errors
Enforce correct number of arguments for `"x86-interrupt"` functions Tracking issue: #40180 Partially fixes #132835 ``@rustbot`` label: +F-abi_x86_interrupt +A-LLVM +O-x86_64 +O-x86_32 +A-ABI
2 parents 0920986 + 2da0ec3 commit 08984d5

23 files changed

+197
-123
lines changed

compiler/rustc_ast_passes/messages.ftl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ ast_passes_abi_must_not_have_return_type=
2020
.note = functions with the {$abi} ABI cannot have a return type
2121
.help = remove the return type
2222
23+
ast_passes_abi_x86_interrupt =
24+
invalid signature for `extern "x86-interrupt"` function
25+
.note = functions with the "x86-interrupt" ABI must be have either 1 or 2 parameters (but found {$param_count})
26+
2327
ast_passes_assoc_const_without_body =
2428
associated constant in `impl` without body
2529
.suggestion = provide a definition for the constant

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,17 @@ impl<'a> AstValidator<'a> {
405405
if let InterruptKind::X86 = interrupt_kind {
406406
// "x86-interrupt" is special because it does have arguments.
407407
// FIXME(workingjubilee): properly lint on acceptable input types.
408+
let inputs = &sig.decl.inputs;
409+
let param_count = inputs.len();
410+
if !matches!(param_count, 1 | 2) {
411+
let mut spans: Vec<Span> =
412+
inputs.iter().map(|arg| arg.span).collect();
413+
if spans.is_empty() {
414+
spans = vec![sig.span];
415+
}
416+
self.dcx().emit_err(errors::AbiX86Interrupt { spans, param_count });
417+
}
418+
408419
if let FnRetTy::Ty(ref ret_ty) = sig.decl.output
409420
&& match &ret_ty.kind {
410421
TyKind::Never => false,

compiler/rustc_ast_passes/src/errors.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,3 +891,12 @@ pub(crate) struct AbiMustNotHaveReturnType {
891891
pub span: Span,
892892
pub abi: ExternAbi,
893893
}
894+
895+
#[derive(Diagnostic)]
896+
#[diag(ast_passes_abi_x86_interrupt)]
897+
#[note]
898+
pub(crate) struct AbiX86Interrupt {
899+
#[primary_span]
900+
pub spans: Vec<Span>,
901+
pub param_count: usize,
902+
}

tests/codegen-llvm/abi-x86-interrupt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ use minicore::*;
1515

1616
// CHECK: define x86_intrcc void @has_x86_interrupt_abi
1717
#[no_mangle]
18-
pub extern "x86-interrupt" fn has_x86_interrupt_abi() {}
18+
pub extern "x86-interrupt" fn has_x86_interrupt_abi(_p: *const u8) {}

tests/codegen-llvm/naked-asan.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ pub fn caller() {
1818
unsafe { asm!("call {}", sym page_fault_handler) }
1919
}
2020

21-
// CHECK: declare x86_intrcc void @page_fault_handler(){{.*}}#[[ATTRS:[0-9]+]]
21+
// CHECK: declare x86_intrcc void @page_fault_handler(ptr {{.*}}, i64{{.*}}){{.*}}#[[ATTRS:[0-9]+]]
2222
#[unsafe(naked)]
2323
#[no_mangle]
24-
pub extern "x86-interrupt" fn page_fault_handler() {
24+
pub extern "x86-interrupt" fn page_fault_handler(_: u64, _: u64) {
2525
naked_asm!("ud2")
2626
}
2727

tests/ui/abi/cannot-be-called.avr.stderr

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,53 +19,53 @@ LL | extern "riscv-interrupt-s" fn riscv_s() {}
1919
error[E0570]: "x86-interrupt" is not a supported ABI for the current target
2020
--> $DIR/cannot-be-called.rs:45:8
2121
|
22-
LL | extern "x86-interrupt" fn x86() {}
22+
LL | extern "x86-interrupt" fn x86(_x: *const u8) {}
2323
| ^^^^^^^^^^^^^^^
2424

2525
error[E0570]: "msp430-interrupt" is not a supported ABI for the current target
26-
--> $DIR/cannot-be-called.rs:70:25
26+
--> $DIR/cannot-be-called.rs:72:25
2727
|
2828
LL | fn msp430_ptr(f: extern "msp430-interrupt" fn()) {
2929
| ^^^^^^^^^^^^^^^^^^
3030

3131
error[E0570]: "riscv-interrupt-m" is not a supported ABI for the current target
32-
--> $DIR/cannot-be-called.rs:76:26
32+
--> $DIR/cannot-be-called.rs:78:26
3333
|
3434
LL | fn riscv_m_ptr(f: extern "riscv-interrupt-m" fn()) {
3535
| ^^^^^^^^^^^^^^^^^^^
3636

3737
error[E0570]: "riscv-interrupt-s" is not a supported ABI for the current target
38-
--> $DIR/cannot-be-called.rs:82:26
38+
--> $DIR/cannot-be-called.rs:84:26
3939
|
4040
LL | fn riscv_s_ptr(f: extern "riscv-interrupt-s" fn()) {
4141
| ^^^^^^^^^^^^^^^^^^^
4242

4343
error[E0570]: "x86-interrupt" is not a supported ABI for the current target
44-
--> $DIR/cannot-be-called.rs:88:22
44+
--> $DIR/cannot-be-called.rs:90:22
4545
|
4646
LL | fn x86_ptr(f: extern "x86-interrupt" fn()) {
4747
| ^^^^^^^^^^^^^^^
4848

4949
error: functions with the "avr-interrupt" ABI cannot be called
50-
--> $DIR/cannot-be-called.rs:50:5
50+
--> $DIR/cannot-be-called.rs:52:5
5151
|
5252
LL | avr();
5353
| ^^^^^
5454
|
5555
note: an `extern "avr-interrupt"` function can only be called using inline assembly
56-
--> $DIR/cannot-be-called.rs:50:5
56+
--> $DIR/cannot-be-called.rs:52:5
5757
|
5858
LL | avr();
5959
| ^^^^^
6060

6161
error: functions with the "avr-interrupt" ABI cannot be called
62-
--> $DIR/cannot-be-called.rs:66:5
62+
--> $DIR/cannot-be-called.rs:68:5
6363
|
6464
LL | f()
6565
| ^^^
6666
|
6767
note: an `extern "avr-interrupt"` function can only be called using inline assembly
68-
--> $DIR/cannot-be-called.rs:66:5
68+
--> $DIR/cannot-be-called.rs:68:5
6969
|
7070
LL | f()
7171
| ^^^

tests/ui/abi/cannot-be-called.i686.stderr

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,49 +23,49 @@ LL | extern "riscv-interrupt-s" fn riscv_s() {}
2323
| ^^^^^^^^^^^^^^^^^^^
2424

2525
error[E0570]: "avr-interrupt" is not a supported ABI for the current target
26-
--> $DIR/cannot-be-called.rs:64:22
26+
--> $DIR/cannot-be-called.rs:66:22
2727
|
2828
LL | fn avr_ptr(f: extern "avr-interrupt" fn()) {
2929
| ^^^^^^^^^^^^^^^
3030

3131
error[E0570]: "msp430-interrupt" is not a supported ABI for the current target
32-
--> $DIR/cannot-be-called.rs:70:25
32+
--> $DIR/cannot-be-called.rs:72:25
3333
|
3434
LL | fn msp430_ptr(f: extern "msp430-interrupt" fn()) {
3535
| ^^^^^^^^^^^^^^^^^^
3636

3737
error[E0570]: "riscv-interrupt-m" is not a supported ABI for the current target
38-
--> $DIR/cannot-be-called.rs:76:26
38+
--> $DIR/cannot-be-called.rs:78:26
3939
|
4040
LL | fn riscv_m_ptr(f: extern "riscv-interrupt-m" fn()) {
4141
| ^^^^^^^^^^^^^^^^^^^
4242

4343
error[E0570]: "riscv-interrupt-s" is not a supported ABI for the current target
44-
--> $DIR/cannot-be-called.rs:82:26
44+
--> $DIR/cannot-be-called.rs:84:26
4545
|
4646
LL | fn riscv_s_ptr(f: extern "riscv-interrupt-s" fn()) {
4747
| ^^^^^^^^^^^^^^^^^^^
4848

4949
error: functions with the "x86-interrupt" ABI cannot be called
50-
--> $DIR/cannot-be-called.rs:58:5
50+
--> $DIR/cannot-be-called.rs:60:5
5151
|
52-
LL | x86();
53-
| ^^^^^
52+
LL | x86(&raw const BYTE);
53+
| ^^^^^^^^^^^^^^^^^^^^
5454
|
5555
note: an `extern "x86-interrupt"` function can only be called using inline assembly
56-
--> $DIR/cannot-be-called.rs:58:5
56+
--> $DIR/cannot-be-called.rs:60:5
5757
|
58-
LL | x86();
59-
| ^^^^^
58+
LL | x86(&raw const BYTE);
59+
| ^^^^^^^^^^^^^^^^^^^^
6060

6161
error: functions with the "x86-interrupt" ABI cannot be called
62-
--> $DIR/cannot-be-called.rs:90:5
62+
--> $DIR/cannot-be-called.rs:92:5
6363
|
6464
LL | f()
6565
| ^^^
6666
|
6767
note: an `extern "x86-interrupt"` function can only be called using inline assembly
68-
--> $DIR/cannot-be-called.rs:90:5
68+
--> $DIR/cannot-be-called.rs:92:5
6969
|
7070
LL | f()
7171
| ^^^

tests/ui/abi/cannot-be-called.msp430.stderr

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,53 +19,53 @@ LL | extern "riscv-interrupt-s" fn riscv_s() {}
1919
error[E0570]: "x86-interrupt" is not a supported ABI for the current target
2020
--> $DIR/cannot-be-called.rs:45:8
2121
|
22-
LL | extern "x86-interrupt" fn x86() {}
22+
LL | extern "x86-interrupt" fn x86(_x: *const u8) {}
2323
| ^^^^^^^^^^^^^^^
2424

2525
error[E0570]: "avr-interrupt" is not a supported ABI for the current target
26-
--> $DIR/cannot-be-called.rs:64:22
26+
--> $DIR/cannot-be-called.rs:66:22
2727
|
2828
LL | fn avr_ptr(f: extern "avr-interrupt" fn()) {
2929
| ^^^^^^^^^^^^^^^
3030

3131
error[E0570]: "riscv-interrupt-m" is not a supported ABI for the current target
32-
--> $DIR/cannot-be-called.rs:76:26
32+
--> $DIR/cannot-be-called.rs:78:26
3333
|
3434
LL | fn riscv_m_ptr(f: extern "riscv-interrupt-m" fn()) {
3535
| ^^^^^^^^^^^^^^^^^^^
3636

3737
error[E0570]: "riscv-interrupt-s" is not a supported ABI for the current target
38-
--> $DIR/cannot-be-called.rs:82:26
38+
--> $DIR/cannot-be-called.rs:84:26
3939
|
4040
LL | fn riscv_s_ptr(f: extern "riscv-interrupt-s" fn()) {
4141
| ^^^^^^^^^^^^^^^^^^^
4242

4343
error[E0570]: "x86-interrupt" is not a supported ABI for the current target
44-
--> $DIR/cannot-be-called.rs:88:22
44+
--> $DIR/cannot-be-called.rs:90:22
4545
|
4646
LL | fn x86_ptr(f: extern "x86-interrupt" fn()) {
4747
| ^^^^^^^^^^^^^^^
4848

4949
error: functions with the "msp430-interrupt" ABI cannot be called
50-
--> $DIR/cannot-be-called.rs:52:5
50+
--> $DIR/cannot-be-called.rs:54:5
5151
|
5252
LL | msp430();
5353
| ^^^^^^^^
5454
|
5555
note: an `extern "msp430-interrupt"` function can only be called using inline assembly
56-
--> $DIR/cannot-be-called.rs:52:5
56+
--> $DIR/cannot-be-called.rs:54:5
5757
|
5858
LL | msp430();
5959
| ^^^^^^^^
6060

6161
error: functions with the "msp430-interrupt" ABI cannot be called
62-
--> $DIR/cannot-be-called.rs:72:5
62+
--> $DIR/cannot-be-called.rs:74:5
6363
|
6464
LL | f()
6565
| ^^^
6666
|
6767
note: an `extern "msp430-interrupt"` function can only be called using inline assembly
68-
--> $DIR/cannot-be-called.rs:72:5
68+
--> $DIR/cannot-be-called.rs:74:5
6969
|
7070
LL | f()
7171
| ^^^

tests/ui/abi/cannot-be-called.riscv32.stderr

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,71 +13,71 @@ LL | extern "avr-interrupt" fn avr() {}
1313
error[E0570]: "x86-interrupt" is not a supported ABI for the current target
1414
--> $DIR/cannot-be-called.rs:45:8
1515
|
16-
LL | extern "x86-interrupt" fn x86() {}
16+
LL | extern "x86-interrupt" fn x86(_x: *const u8) {}
1717
| ^^^^^^^^^^^^^^^
1818

1919
error[E0570]: "avr-interrupt" is not a supported ABI for the current target
20-
--> $DIR/cannot-be-called.rs:64:22
20+
--> $DIR/cannot-be-called.rs:66:22
2121
|
2222
LL | fn avr_ptr(f: extern "avr-interrupt" fn()) {
2323
| ^^^^^^^^^^^^^^^
2424

2525
error[E0570]: "msp430-interrupt" is not a supported ABI for the current target
26-
--> $DIR/cannot-be-called.rs:70:25
26+
--> $DIR/cannot-be-called.rs:72:25
2727
|
2828
LL | fn msp430_ptr(f: extern "msp430-interrupt" fn()) {
2929
| ^^^^^^^^^^^^^^^^^^
3030

3131
error[E0570]: "x86-interrupt" is not a supported ABI for the current target
32-
--> $DIR/cannot-be-called.rs:88:22
32+
--> $DIR/cannot-be-called.rs:90:22
3333
|
3434
LL | fn x86_ptr(f: extern "x86-interrupt" fn()) {
3535
| ^^^^^^^^^^^^^^^
3636

3737
error: functions with the "riscv-interrupt-m" ABI cannot be called
38-
--> $DIR/cannot-be-called.rs:54:5
38+
--> $DIR/cannot-be-called.rs:56:5
3939
|
4040
LL | riscv_m();
4141
| ^^^^^^^^^
4242
|
4343
note: an `extern "riscv-interrupt-m"` function can only be called using inline assembly
44-
--> $DIR/cannot-be-called.rs:54:5
44+
--> $DIR/cannot-be-called.rs:56:5
4545
|
4646
LL | riscv_m();
4747
| ^^^^^^^^^
4848

4949
error: functions with the "riscv-interrupt-s" ABI cannot be called
50-
--> $DIR/cannot-be-called.rs:56:5
50+
--> $DIR/cannot-be-called.rs:58:5
5151
|
5252
LL | riscv_s();
5353
| ^^^^^^^^^
5454
|
5555
note: an `extern "riscv-interrupt-s"` function can only be called using inline assembly
56-
--> $DIR/cannot-be-called.rs:56:5
56+
--> $DIR/cannot-be-called.rs:58:5
5757
|
5858
LL | riscv_s();
5959
| ^^^^^^^^^
6060

6161
error: functions with the "riscv-interrupt-m" ABI cannot be called
62-
--> $DIR/cannot-be-called.rs:78:5
62+
--> $DIR/cannot-be-called.rs:80:5
6363
|
6464
LL | f()
6565
| ^^^
6666
|
6767
note: an `extern "riscv-interrupt-m"` function can only be called using inline assembly
68-
--> $DIR/cannot-be-called.rs:78:5
68+
--> $DIR/cannot-be-called.rs:80:5
6969
|
7070
LL | f()
7171
| ^^^
7272

7373
error: functions with the "riscv-interrupt-s" ABI cannot be called
74-
--> $DIR/cannot-be-called.rs:84:5
74+
--> $DIR/cannot-be-called.rs:86:5
7575
|
7676
LL | f()
7777
| ^^^
7878
|
7979
note: an `extern "riscv-interrupt-s"` function can only be called using inline assembly
80-
--> $DIR/cannot-be-called.rs:84:5
80+
--> $DIR/cannot-be-called.rs:86:5
8181
|
8282
LL | f()
8383
| ^^^

0 commit comments

Comments
 (0)