-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Check ABI target compatibility for function pointers #128784
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,6 +123,7 @@ declare_lint_pass! { | |
UNSTABLE_NAME_COLLISIONS, | ||
UNSTABLE_SYNTAX_PRE_EXPANSION, | ||
UNSUPPORTED_CALLING_CONVENTIONS, | ||
UNSUPPORTED_FN_PTR_CALLING_CONVENTIONS, | ||
UNUSED_ASSIGNMENTS, | ||
UNUSED_ASSOCIATED_TYPE_BOUNDS, | ||
UNUSED_ATTRIBUTES, | ||
|
@@ -3874,6 +3875,50 @@ declare_lint! { | |
}; | ||
} | ||
|
||
declare_lint! { | ||
/// The `unsupported_fn_ptr_calling_conventions` lint is output whenever there is a use of | ||
/// a target dependent calling convention on a target that does not support this calling | ||
/// convention on a function pointer. | ||
/// | ||
/// For example `stdcall` does not make much sense for a x86_64 or, more apparently, powerpc | ||
/// code, because this calling convention was never specified for those targets. | ||
/// | ||
/// ### Example | ||
/// | ||
/// ```rust,ignore (needs specific targets) | ||
/// fn stdcall_ptr(f: extern "stdcall" fn ()) { | ||
/// f() | ||
/// } | ||
/// ``` | ||
/// | ||
/// This will produce: | ||
/// | ||
/// ```text | ||
/// warning: use of calling convention not supported on this target on function pointer | ||
/// --> $DIR/unsupported.rs:34:15 | ||
/// | | ||
/// LL | fn stdcall_ptr(f: extern "stdcall" fn()) { | ||
/// | ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
/// | | ||
/// = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
/// = note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260> | ||
/// = note: `#[warn(unsupported_fn_ptr_calling_conventions)]` on by default | ||
/// ``` | ||
/// | ||
/// ### Explanation | ||
/// | ||
/// On most of the targets the behaviour of `stdcall` and similar calling conventions is not | ||
/// defined at all, but was previously accepted due to a bug in the implementation of the | ||
/// compiler. | ||
pub UNSUPPORTED_FN_PTR_CALLING_CONVENTIONS, | ||
Warn, | ||
"use of unsupported calling convention for function pointer", | ||
@future_incompatible = FutureIncompatibleInfo { | ||
reason: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe make this "ReportInDeps" immediately? Seems unlikely that it is very widely used, since one can't actually create a value of this function pointer type... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can also update this to |
||
reference: "issue #130260 <https://github.com/rust-lang/rust/issues/130260>", | ||
}; | ||
} | ||
|
||
declare_lint! { | ||
/// The `break_with_label_and_loop` lint detects labeled `break` expressions with | ||
/// an unlabeled loop as their value expression. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,209 @@ | ||
warning: use of calling convention not supported on this target on function pointer | ||
--> $DIR/unsupported.rs:35:15 | ||
| | ||
LL | fn ptx_ptr(f: extern "ptx-kernel" fn()) { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260> | ||
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` on by default | ||
|
||
error[E0570]: `"ptx-kernel"` is not a supported ABI for the current target | ||
--> $DIR/unsupported.rs:28:1 | ||
--> $DIR/unsupported.rs:40:1 | ||
| | ||
LL | extern "ptx-kernel" {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
warning: use of calling convention not supported on this target on function pointer | ||
--> $DIR/unsupported.rs:49:17 | ||
| | ||
LL | fn aapcs_ptr(f: extern "aapcs" fn()) { | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260> | ||
|
||
error[E0570]: `"aapcs"` is not a supported ABI for the current target | ||
--> $DIR/unsupported.rs:62:1 | ||
| | ||
LL | extern "aapcs" {} | ||
| ^^^^^^^^^^^^^^^^^ | ||
|
||
warning: use of calling convention not supported on this target on function pointer | ||
--> $DIR/unsupported.rs:71:18 | ||
| | ||
LL | fn msp430_ptr(f: extern "msp430-interrupt" fn()) { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260> | ||
|
||
error[E0570]: `"msp430-interrupt"` is not a supported ABI for the current target | ||
--> $DIR/unsupported.rs:76:1 | ||
| | ||
LL | extern "msp430-interrupt" {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
warning: use of calling convention not supported on this target on function pointer | ||
--> $DIR/unsupported.rs:81:15 | ||
| | ||
LL | fn avr_ptr(f: extern "avr-interrupt" fn()) { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260> | ||
|
||
error[E0570]: `"avr-interrupt"` is not a supported ABI for the current target | ||
--> $DIR/unsupported.rs:86:1 | ||
| | ||
LL | extern "avr-interrupt" {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
warning: use of calling convention not supported on this target on function pointer | ||
--> $DIR/unsupported.rs:94:17 | ||
| | ||
LL | fn riscv_ptr(f: extern "riscv-interrupt-m" fn()) { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260> | ||
|
||
error[E0570]: `"riscv-interrupt-m"` is not a supported ABI for the current target | ||
--> $DIR/unsupported.rs:105:1 | ||
| | ||
LL | extern "riscv-interrupt-m" {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
warning: use of calling convention not supported on this target on function pointer | ||
--> $DIR/unsupported.rs:116:15 | ||
| | ||
LL | fn x86_ptr(f: extern "x86-interrupt" fn()) { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260> | ||
|
||
error[E0570]: `"x86-interrupt"` is not a supported ABI for the current target | ||
--> $DIR/unsupported.rs:127:1 | ||
| | ||
LL | extern "x86-interrupt" {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
warning: use of calling convention not supported on this target on function pointer | ||
--> $DIR/unsupported.rs:139:20 | ||
| | ||
LL | fn thiscall_ptr(f: extern "thiscall" fn()) { | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260> | ||
|
||
error[E0570]: `"thiscall"` is not a supported ABI for the current target | ||
--> $DIR/unsupported.rs:152:1 | ||
| | ||
LL | extern "thiscall" {} | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
|
||
warning: use of calling convention not supported on this target on function pointer | ||
--> $DIR/unsupported.rs:170:19 | ||
| | ||
LL | fn stdcall_ptr(f: extern "stdcall" fn()) { | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260> | ||
|
||
warning: use of calling convention not supported on this target | ||
--> $DIR/unsupported.rs:183:1 | ||
| | ||
LL | extern "stdcall" {} | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #87678 <https://github.com/rust-lang/rust/issues/87678> | ||
= note: `#[warn(unsupported_calling_conventions)]` on by default | ||
|
||
warning: use of calling convention not supported on this target on function pointer | ||
--> $DIR/unsupported.rs:195:21 | ||
| | ||
LL | fn cmse_call_ptr(f: extern "C-cmse-nonsecure-call" fn()) { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260> | ||
|
||
warning: use of calling convention not supported on this target on function pointer | ||
--> $DIR/unsupported.rs:203:22 | ||
| | ||
LL | fn cmse_entry_ptr(f: extern "C-cmse-nonsecure-entry" fn()) { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260> | ||
|
||
error[E0570]: `"C-cmse-nonsecure-entry"` is not a supported ABI for the current target | ||
--> $DIR/unsupported.rs:208:1 | ||
| | ||
LL | extern "C-cmse-nonsecure-entry" {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0570]: `"ptx-kernel"` is not a supported ABI for the current target | ||
--> $DIR/unsupported.rs:33:1 | ||
| | ||
LL | extern "ptx-kernel" fn ptx() {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0570]: `"aapcs"` is not a supported ABI for the current target | ||
--> $DIR/unsupported.rs:30:1 | ||
--> $DIR/unsupported.rs:43:1 | ||
| | ||
LL | extern "aapcs" fn aapcs() {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0570]: `"msp430-interrupt"` is not a supported ABI for the current target | ||
--> $DIR/unsupported.rs:36:1 | ||
--> $DIR/unsupported.rs:69:1 | ||
| | ||
LL | extern "msp430-interrupt" fn msp430() {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0570]: `"avr-interrupt"` is not a supported ABI for the current target | ||
--> $DIR/unsupported.rs:38:1 | ||
--> $DIR/unsupported.rs:79:1 | ||
| | ||
LL | extern "avr-interrupt" fn avr() {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0570]: `"riscv-interrupt-m"` is not a supported ABI for the current target | ||
--> $DIR/unsupported.rs:40:1 | ||
--> $DIR/unsupported.rs:89:1 | ||
| | ||
LL | extern "riscv-interrupt-m" fn riscv() {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0570]: `"x86-interrupt"` is not a supported ABI for the current target | ||
--> $DIR/unsupported.rs:45:1 | ||
--> $DIR/unsupported.rs:111:1 | ||
| | ||
LL | extern "x86-interrupt" fn x86() {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0570]: `"thiscall"` is not a supported ABI for the current target | ||
--> $DIR/unsupported.rs:50:1 | ||
--> $DIR/unsupported.rs:133:1 | ||
| | ||
LL | extern "thiscall" fn thiscall() {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
warning: use of calling convention not supported on this target | ||
--> $DIR/unsupported.rs:56:1 | ||
--> $DIR/unsupported.rs:159:1 | ||
| | ||
LL | extern "stdcall" fn stdcall() {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #87678 <https://github.com/rust-lang/rust/issues/87678> | ||
= note: `#[warn(unsupported_calling_conventions)]` on by default | ||
|
||
error: aborting due to 7 previous errors; 1 warning emitted | ||
error[E0570]: `"C-cmse-nonsecure-entry"` is not a supported ABI for the current target | ||
--> $DIR/unsupported.rs:201:1 | ||
| | ||
LL | extern "C-cmse-nonsecure-entry" fn cmse_entry() {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 16 previous errors; 12 warnings emitted | ||
|
||
For more information about this error, try `rustc --explain E0570`. |
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.
This diagnostic is a bit awkward. Perhaps change it to:
"the calling convention
{}
is not supported on this target"I think mentioning fn ptrs is also unnecessary, since it's also a warning for items (and soon an error).