use naked_asm! in tests/ui/asm/naked-functions.rs

This commit is contained in:
Folkert 2024-08-04 16:43:12 +02:00 committed by Folkert de Vries
parent aa5bbf05f4
commit 0aec55504c
2 changed files with 122 additions and 144 deletions

View File

@ -6,7 +6,7 @@
#![feature(asm_unwind, linkage)] #![feature(asm_unwind, linkage)]
#![crate_type = "lib"] #![crate_type = "lib"]
use std::arch::asm; use std::arch::naked_asm;
#[repr(C)] #[repr(C)]
pub struct P { pub struct P {
@ -25,7 +25,7 @@ pub unsafe extern "C" fn patterns(
P { x, y }: P, P { x, y }: P,
//~^ ERROR patterns not allowed in naked function parameters //~^ ERROR patterns not allowed in naked function parameters
) { ) {
asm!("", options(noreturn)) naked_asm!("", options(noreturn))
} }
#[naked] #[naked]
@ -38,9 +38,8 @@ pub unsafe extern "C" fn inc(a: u32) -> u32 {
#[naked] #[naked]
#[allow(asm_sub_register)] #[allow(asm_sub_register)]
pub unsafe extern "C" fn inc_asm(a: u32) -> u32 { pub unsafe extern "C" fn inc_asm(a: u32) -> u32 {
asm!("/* {0} */", in(reg) a, options(noreturn)); naked_asm!("/* {0} */", in(reg) a, options(noreturn))
//~^ ERROR referencing function parameters is not allowed in naked functions //~^ ERROR the `in` operand cannot be used with `naked_asm!`
//~| ERROR only `const` and `sym` operands are supported in naked functions
} }
#[naked] #[naked]
@ -59,10 +58,9 @@ pub unsafe extern "C" fn unsupported_operands() {
let mut e = 0usize; let mut e = 0usize;
const F: usize = 0usize; const F: usize = 0usize;
static G: usize = 0usize; static G: usize = 0usize;
asm!("/* {0} {1} {2} {3} {4} {5} {6} */", naked_asm!("/* {0} {1} {2} {3} {4} {5} {6} */",
//~^ ERROR asm in naked functions must use `noreturn` option
in(reg) a, in(reg) a,
//~^ ERROR only `const` and `sym` operands are supported in naked functions //~^ ERROR the `in` operand cannot be used with `naked_asm!`
inlateout(reg) b, inlateout(reg) b,
inout(reg) c, inout(reg) c,
lateout(reg) d, lateout(reg) d,
@ -81,13 +79,13 @@ pub extern "C" fn missing_assembly() {
pub extern "C" fn too_many_asm_blocks() { pub extern "C" fn too_many_asm_blocks() {
//~^ ERROR naked functions must contain a single asm block //~^ ERROR naked functions must contain a single asm block
unsafe { unsafe {
asm!(""); naked_asm!("");
//~^ ERROR asm in naked functions must use `noreturn` option //~^ ERROR asm in naked functions must use `noreturn` option
asm!(""); naked_asm!("");
//~^ ERROR asm in naked functions must use `noreturn` option //~^ ERROR asm in naked functions must use `noreturn` option
asm!(""); naked_asm!("");
//~^ ERROR asm in naked functions must use `noreturn` option //~^ ERROR asm in naked functions must use `noreturn` option
asm!("", options(noreturn)); naked_asm!("", options(noreturn));
} }
} }
@ -103,40 +101,42 @@ pub fn outer(x: u32) -> extern "C" fn(usize) -> usize {
#[naked] #[naked]
unsafe extern "C" fn invalid_options() { unsafe extern "C" fn invalid_options() {
asm!("", options(nomem, preserves_flags, noreturn)); naked_asm!("", options(nomem, preserves_flags, noreturn));
//~^ ERROR asm options unsupported in naked functions: `nomem`, `preserves_flags` //~^ ERROR the `nomem` option cannot be used with `naked_asm!`
//~| ERROR the `preserves_flags` option cannot be used with `naked_asm!`
} }
#[naked] #[naked]
unsafe extern "C" fn invalid_options_continued() { unsafe extern "C" fn invalid_options_continued() {
asm!("", options(readonly, nostack), options(pure)); naked_asm!("", options(readonly, nostack), options(pure));
//~^ ERROR asm with the `pure` option must have at least one output //~^ ERROR the `readonly` option cannot be used with `naked_asm!`
//~| ERROR asm options unsupported in naked functions: `pure`, `readonly`, `nostack` //~| ERROR the `nostack` option cannot be used with `naked_asm!`
//~| ERROR the `pure` option cannot be used with `naked_asm!`
//~| ERROR asm in naked functions must use `noreturn` option //~| ERROR asm in naked functions must use `noreturn` option
} }
#[naked] #[naked]
unsafe extern "C" fn invalid_may_unwind() { unsafe extern "C" fn invalid_may_unwind() {
asm!("", options(noreturn, may_unwind)); naked_asm!("", options(noreturn, may_unwind));
//~^ ERROR asm options unsupported in naked functions: `may_unwind` //~^ ERROR the `may_unwind` option cannot be used with `naked_asm!`
} }
#[naked] #[naked]
pub unsafe fn default_abi() { pub unsafe fn default_abi() {
//~^ WARN Rust ABI is unsupported in naked functions //~^ WARN Rust ABI is unsupported in naked functions
asm!("", options(noreturn)); naked_asm!("", options(noreturn));
} }
#[naked] #[naked]
pub unsafe fn rust_abi() { pub unsafe fn rust_abi() {
//~^ WARN Rust ABI is unsupported in naked functions //~^ WARN Rust ABI is unsupported in naked functions
asm!("", options(noreturn)); naked_asm!("", options(noreturn));
} }
#[naked] #[naked]
pub extern "C" fn valid_a<T>() -> T { pub extern "C" fn valid_a<T>() -> T {
unsafe { unsafe {
asm!("", options(noreturn)); naked_asm!("", options(noreturn));
} }
} }
@ -145,7 +145,7 @@ pub extern "C" fn valid_b() {
unsafe { unsafe {
{ {
{ {
asm!("", options(noreturn)); naked_asm!("", options(noreturn));
}; };
}; };
} }
@ -153,13 +153,13 @@ pub extern "C" fn valid_b() {
#[naked] #[naked]
pub unsafe extern "C" fn valid_c() { pub unsafe extern "C" fn valid_c() {
asm!("", options(noreturn)); naked_asm!("", options(noreturn));
} }
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
#[naked] #[naked]
pub unsafe extern "C" fn valid_att_syntax() { pub unsafe extern "C" fn valid_att_syntax() {
asm!("", options(noreturn, att_syntax)); naked_asm!("", options(noreturn, att_syntax));
} }
#[naked] #[naked]
@ -173,12 +173,12 @@ pub unsafe extern "C" fn allow_compile_error(a: u32) -> u32 {
pub unsafe extern "C" fn allow_compile_error_and_asm(a: u32) -> u32 { pub unsafe extern "C" fn allow_compile_error_and_asm(a: u32) -> u32 {
compile_error!("this is a user specified error"); compile_error!("this is a user specified error");
//~^ ERROR this is a user specified error //~^ ERROR this is a user specified error
asm!("", options(noreturn)) naked_asm!("", options(noreturn))
} }
#[naked] #[naked]
pub unsafe extern "C" fn invalid_asm_syntax(a: u32) -> u32 { pub unsafe extern "C" fn invalid_asm_syntax(a: u32) -> u32 {
asm!(invalid_syntax) naked_asm!(invalid_syntax)
//~^ ERROR asm template must be a string literal //~^ ERROR asm template must be a string literal
} }
@ -186,7 +186,7 @@ pub unsafe extern "C" fn invalid_asm_syntax(a: u32) -> u32 {
#[cfg_attr(target_pointer_width = "64", no_mangle)] #[cfg_attr(target_pointer_width = "64", no_mangle)]
#[naked] #[naked]
pub unsafe extern "C" fn compatible_cfg_attributes() { pub unsafe extern "C" fn compatible_cfg_attributes() {
asm!("", options(noreturn, att_syntax)); naked_asm!("", options(noreturn, att_syntax));
} }
#[allow(dead_code)] #[allow(dead_code)]
@ -195,20 +195,20 @@ pub unsafe extern "C" fn compatible_cfg_attributes() {
#[forbid(dead_code)] #[forbid(dead_code)]
#[naked] #[naked]
pub unsafe extern "C" fn compatible_diagnostic_attributes() { pub unsafe extern "C" fn compatible_diagnostic_attributes() {
asm!("", options(noreturn, raw)); naked_asm!("", options(noreturn, raw));
} }
#[deprecated = "test"] #[deprecated = "test"]
#[naked] #[naked]
pub unsafe extern "C" fn compatible_deprecated_attributes() { pub unsafe extern "C" fn compatible_deprecated_attributes() {
asm!("", options(noreturn, raw)); naked_asm!("", options(noreturn, raw));
} }
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
#[must_use] #[must_use]
#[naked] #[naked]
pub unsafe extern "C" fn compatible_must_use_attributes() -> u64 { pub unsafe extern "C" fn compatible_must_use_attributes() -> u64 {
asm!( naked_asm!(
" "
mov rax, 42 mov rax, 42
ret ret
@ -222,20 +222,20 @@ pub unsafe extern "C" fn compatible_must_use_attributes() -> u64 {
#[no_mangle] #[no_mangle]
#[naked] #[naked]
pub unsafe extern "C" fn compatible_ffi_attributes_1() { pub unsafe extern "C" fn compatible_ffi_attributes_1() {
asm!("", options(noreturn, raw)); naked_asm!("", options(noreturn, raw));
} }
#[cold] #[cold]
#[naked] #[naked]
pub unsafe extern "C" fn compatible_codegen_attributes() { pub unsafe extern "C" fn compatible_codegen_attributes() {
asm!("", options(noreturn, raw)); naked_asm!("", options(noreturn, raw));
} }
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
#[target_feature(enable = "sse2")] #[target_feature(enable = "sse2")]
#[naked] #[naked]
pub unsafe extern "C" fn compatible_target_feature() { pub unsafe extern "C" fn compatible_target_feature() {
asm!("", options(noreturn)); naked_asm!("", options(noreturn));
} }
#[doc = "foo bar baz"] #[doc = "foo bar baz"]
@ -244,11 +244,11 @@ pub unsafe extern "C" fn compatible_target_feature() {
#[doc(alias = "ADocAlias")] #[doc(alias = "ADocAlias")]
#[naked] #[naked]
pub unsafe extern "C" fn compatible_doc_attributes() { pub unsafe extern "C" fn compatible_doc_attributes() {
asm!("", options(noreturn, raw)); naked_asm!("", options(noreturn, raw));
} }
#[linkage = "external"] #[linkage = "external"]
#[naked] #[naked]
pub unsafe extern "C" fn compatible_linkage() { pub unsafe extern "C" fn compatible_linkage() {
asm!("", options(noreturn, raw)); naked_asm!("", options(noreturn, raw));
} }

View File

@ -1,8 +1,50 @@
error: asm with the `pure` option must have at least one output error: the `in` operand cannot be used with `naked_asm!`
--> $DIR/naked-functions.rs:112:14 --> $DIR/naked-functions.rs:41:29
| |
LL | asm!("", options(readonly, nostack), options(pure)); LL | naked_asm!("/* {0} */", in(reg) a, options(noreturn))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^ | ^^ the `in` operand is not meaningful for global-scoped inline assembly, remove it
error: the `in` operand cannot be used with `naked_asm!`
--> $DIR/naked-functions.rs:62:10
|
LL | in(reg) a,
| ^^ the `in` operand is not meaningful for global-scoped inline assembly, remove it
error: the `nomem` option cannot be used with `naked_asm!`
--> $DIR/naked-functions.rs:104:28
|
LL | naked_asm!("", options(nomem, preserves_flags, noreturn));
| ^^^^^ the `nomem` option is not meaningful for global-scoped inline assembly
error: the `preserves_flags` option cannot be used with `naked_asm!`
--> $DIR/naked-functions.rs:104:35
|
LL | naked_asm!("", options(nomem, preserves_flags, noreturn));
| ^^^^^^^^^^^^^^^ the `preserves_flags` option is not meaningful for global-scoped inline assembly
error: the `readonly` option cannot be used with `naked_asm!`
--> $DIR/naked-functions.rs:111:28
|
LL | naked_asm!("", options(readonly, nostack), options(pure));
| ^^^^^^^^ the `readonly` option is not meaningful for global-scoped inline assembly
error: the `nostack` option cannot be used with `naked_asm!`
--> $DIR/naked-functions.rs:111:38
|
LL | naked_asm!("", options(readonly, nostack), options(pure));
| ^^^^^^^ the `nostack` option is not meaningful for global-scoped inline assembly
error: the `pure` option cannot be used with `naked_asm!`
--> $DIR/naked-functions.rs:111:56
|
LL | naked_asm!("", options(readonly, nostack), options(pure));
| ^^^^ the `pure` option is not meaningful for global-scoped inline assembly
error: the `may_unwind` option cannot be used with `naked_asm!`
--> $DIR/naked-functions.rs:120:38
|
LL | naked_asm!("", options(noreturn, may_unwind));
| ^^^^^^^^^^ the `may_unwind` option is not meaningful for global-scoped inline assembly
error: this is a user specified error error: this is a user specified error
--> $DIR/naked-functions.rs:168:5 --> $DIR/naked-functions.rs:168:5
@ -17,10 +59,10 @@ LL | compile_error!("this is a user specified error");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: asm template must be a string literal error: asm template must be a string literal
--> $DIR/naked-functions.rs:181:10 --> $DIR/naked-functions.rs:181:16
| |
LL | asm!(invalid_syntax) LL | naked_asm!(invalid_syntax)
| ^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^
error: patterns not allowed in naked function parameters error: patterns not allowed in naked function parameters
--> $DIR/naked-functions.rs:19:5 --> $DIR/naked-functions.rs:19:5
@ -63,22 +105,8 @@ LL |
LL | a + 1 LL | a + 1
| ----- non-asm is unsupported in naked functions | ----- non-asm is unsupported in naked functions
error: referencing function parameters is not allowed in naked functions
--> $DIR/naked-functions.rs:41:31
|
LL | asm!("/* {0} */", in(reg) a, options(noreturn));
| ^
|
= help: follow the calling convention in asm block to use parameters
error[E0787]: only `const` and `sym` operands are supported in naked functions
--> $DIR/naked-functions.rs:41:23
|
LL | asm!("/* {0} */", in(reg) a, options(noreturn));
| ^^^^^^^^^
error[E0787]: naked functions must contain a single asm block error[E0787]: naked functions must contain a single asm block
--> $DIR/naked-functions.rs:47:1 --> $DIR/naked-functions.rs:46:1
| |
LL | pub unsafe extern "C" fn inc_closure(a: u32) -> u32 { LL | pub unsafe extern "C" fn inc_closure(a: u32) -> u32 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -86,40 +114,8 @@ LL |
LL | (|| a + 1)() LL | (|| a + 1)()
| ------------ non-asm is unsupported in naked functions | ------------ non-asm is unsupported in naked functions
error[E0787]: only `const` and `sym` operands are supported in naked functions
--> $DIR/naked-functions.rs:64:10
|
LL | in(reg) a,
| ^^^^^^^^^
LL |
LL | inlateout(reg) b,
| ^^^^^^^^^^^^^^^^
LL | inout(reg) c,
| ^^^^^^^^^^^^
LL | lateout(reg) d,
| ^^^^^^^^^^^^^^
LL | out(reg) e,
| ^^^^^^^^^^
error[E0787]: asm in naked functions must use `noreturn` option
--> $DIR/naked-functions.rs:62:5
|
LL | / asm!("/* {0} {1} {2} {3} {4} {5} {6} */",
LL | |
LL | | in(reg) a,
LL | |
... |
LL | | sym G,
LL | | );
| |_____^
|
help: consider specifying that the asm block is responsible for returning from the function
|
LL | sym G, options(noreturn),
| +++++++++++++++++++
error[E0787]: naked functions must contain a single asm block error[E0787]: naked functions must contain a single asm block
--> $DIR/naked-functions.rs:53:1 --> $DIR/naked-functions.rs:52:1
| |
LL | pub unsafe extern "C" fn unsupported_operands() { LL | pub unsafe extern "C" fn unsupported_operands() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -136,61 +132,61 @@ LL | let mut e = 0usize;
| ------------------- non-asm is unsupported in naked functions | ------------------- non-asm is unsupported in naked functions
error[E0787]: naked functions must contain a single asm block error[E0787]: naked functions must contain a single asm block
--> $DIR/naked-functions.rs:76:1 --> $DIR/naked-functions.rs:74:1
| |
LL | pub extern "C" fn missing_assembly() { LL | pub extern "C" fn missing_assembly() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0787]: asm in naked functions must use `noreturn` option error[E0787]: asm in naked functions must use `noreturn` option
--> $DIR/naked-functions.rs:84:9 --> $DIR/naked-functions.rs:82:9
| |
LL | asm!(""); LL | naked_asm!("");
| ^^^^^^^^ | ^^^^^^^^^^^^^^
| |
help: consider specifying that the asm block is responsible for returning from the function help: consider specifying that the asm block is responsible for returning from the function
| |
LL | asm!("", options(noreturn)); LL | naked_asm!("", options(noreturn));
| +++++++++++++++++++ | +++++++++++++++++++
error[E0787]: asm in naked functions must use `noreturn` option
--> $DIR/naked-functions.rs:84:9
|
LL | naked_asm!("");
| ^^^^^^^^^^^^^^
|
help: consider specifying that the asm block is responsible for returning from the function
|
LL | naked_asm!("", options(noreturn));
| +++++++++++++++++++
error[E0787]: asm in naked functions must use `noreturn` option error[E0787]: asm in naked functions must use `noreturn` option
--> $DIR/naked-functions.rs:86:9 --> $DIR/naked-functions.rs:86:9
| |
LL | asm!(""); LL | naked_asm!("");
| ^^^^^^^^ | ^^^^^^^^^^^^^^
| |
help: consider specifying that the asm block is responsible for returning from the function help: consider specifying that the asm block is responsible for returning from the function
| |
LL | asm!("", options(noreturn)); LL | naked_asm!("", options(noreturn));
| +++++++++++++++++++ | +++++++++++++++++++
error[E0787]: asm in naked functions must use `noreturn` option
--> $DIR/naked-functions.rs:88:9
|
LL | asm!("");
| ^^^^^^^^
|
help: consider specifying that the asm block is responsible for returning from the function
|
LL | asm!("", options(noreturn));
| +++++++++++++++++++
error[E0787]: naked functions must contain a single asm block error[E0787]: naked functions must contain a single asm block
--> $DIR/naked-functions.rs:81:1 --> $DIR/naked-functions.rs:79:1
| |
LL | pub extern "C" fn too_many_asm_blocks() { LL | pub extern "C" fn too_many_asm_blocks() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
... ...
LL | asm!(""); LL | naked_asm!("");
| -------- multiple asm blocks are unsupported in naked functions | -------------- multiple asm blocks are unsupported in naked functions
LL | LL |
LL | asm!(""); LL | naked_asm!("");
| -------- multiple asm blocks are unsupported in naked functions | -------------- multiple asm blocks are unsupported in naked functions
LL | LL |
LL | asm!("", options(noreturn)); LL | naked_asm!("", options(noreturn));
| --------------------------- multiple asm blocks are unsupported in naked functions | --------------------------------- multiple asm blocks are unsupported in naked functions
error: referencing function parameters is not allowed in naked functions error: referencing function parameters is not allowed in naked functions
--> $DIR/naked-functions.rs:98:11 --> $DIR/naked-functions.rs:96:11
| |
LL | *&y LL | *&y
| ^ | ^
@ -198,7 +194,7 @@ LL | *&y
= help: follow the calling convention in asm block to use parameters = help: follow the calling convention in asm block to use parameters
error[E0787]: naked functions must contain a single asm block error[E0787]: naked functions must contain a single asm block
--> $DIR/naked-functions.rs:96:5 --> $DIR/naked-functions.rs:94:5
| |
LL | pub extern "C" fn inner(y: usize) -> usize { LL | pub extern "C" fn inner(y: usize) -> usize {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -206,34 +202,16 @@ LL |
LL | *&y LL | *&y
| --- non-asm is unsupported in naked functions | --- non-asm is unsupported in naked functions
error[E0787]: asm options unsupported in naked functions: `nomem`, `preserves_flags`
--> $DIR/naked-functions.rs:106:5
|
LL | asm!("", options(nomem, preserves_flags, noreturn));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0787]: asm options unsupported in naked functions: `pure`, `readonly`, `nostack`
--> $DIR/naked-functions.rs:112:5
|
LL | asm!("", options(readonly, nostack), options(pure));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0787]: asm in naked functions must use `noreturn` option error[E0787]: asm in naked functions must use `noreturn` option
--> $DIR/naked-functions.rs:112:5 --> $DIR/naked-functions.rs:111:5
| |
LL | asm!("", options(readonly, nostack), options(pure)); LL | naked_asm!("", options(readonly, nostack), options(pure));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
help: consider specifying that the asm block is responsible for returning from the function help: consider specifying that the asm block is responsible for returning from the function
| |
LL | asm!("", options(noreturn), options(readonly, nostack), options(pure)); LL | naked_asm!("", options(noreturn), options(readonly, nostack), options(pure));
| +++++++++++++++++++ | +++++++++++++++++++
error[E0787]: asm options unsupported in naked functions: `may_unwind`
--> $DIR/naked-functions.rs:120:5
|
LL | asm!("", options(noreturn, may_unwind));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: Rust ABI is unsupported in naked functions warning: Rust ABI is unsupported in naked functions
--> $DIR/naked-functions.rs:125:1 --> $DIR/naked-functions.rs:125:1