more asm! -> naked_asm! in tests

This commit is contained in:
Folkert de Vries 2024-09-05 17:48:13 +02:00
parent 562ec5a6fb
commit bc0a9543a3
7 changed files with 22 additions and 23 deletions

View File

@ -5,7 +5,7 @@
#![crate_type = "lib"] #![crate_type = "lib"]
#![feature(naked_functions)] #![feature(naked_functions)]
use std::arch::asm; use std::arch::naked_asm;
// The problem at hand: Rust has adopted a fairly strict meaning for "naked functions", // The problem at hand: Rust has adopted a fairly strict meaning for "naked functions",
// meaning "no prologue whatsoever, no, really, not one instruction." // meaning "no prologue whatsoever, no, really, not one instruction."
@ -17,5 +17,5 @@
pub unsafe extern "C" fn _hlt() -> ! { pub unsafe extern "C" fn _hlt() -> ! {
// CHECK-NOT: hint #34 // CHECK-NOT: hint #34
// CHECK: hlt #0x1 // CHECK: hlt #0x1
asm!("hlt #1", options(noreturn)) naked_asm!("hlt #1")
} }

View File

@ -5,7 +5,7 @@
#![crate_type = "lib"] #![crate_type = "lib"]
#![feature(naked_functions)] #![feature(naked_functions)]
use std::arch::asm; use std::arch::naked_asm;
// The problem at hand: Rust has adopted a fairly strict meaning for "naked functions", // The problem at hand: Rust has adopted a fairly strict meaning for "naked functions",
// meaning "no prologue whatsoever, no, really, not one instruction." // meaning "no prologue whatsoever, no, really, not one instruction."
@ -17,7 +17,7 @@
pub unsafe extern "sysv64" fn will_halt() -> ! { pub unsafe extern "sysv64" fn will_halt() -> ! {
// CHECK-NOT: endbr{{32|64}} // CHECK-NOT: endbr{{32|64}}
// CHECK: hlt // CHECK: hlt
asm!("hlt", options(noreturn)) naked_asm!("hlt")
} }
// what about aarch64? // what about aarch64?

View File

@ -12,8 +12,7 @@
pub unsafe extern "C" fn c_variadic(_: usize, _: ...) { pub unsafe extern "C" fn c_variadic(_: usize, _: ...) {
// CHECK-NOT: va_start // CHECK-NOT: va_start
// CHECK-NOT: alloca // CHECK-NOT: alloca
core::arch::asm! { core::arch::naked_asm! {
"ret", "ret",
options(noreturn),
} }
} }

View File

@ -3,9 +3,9 @@
//@ only-x86_64 //@ only-x86_64
#![crate_type = "lib"] #![crate_type = "lib"]
#![feature(naked_functions)] #![feature(naked_functions)]
use std::arch::asm; use std::arch::naked_asm;
#[naked] #[naked]
pub unsafe extern "C" fn naked_with_args_and_return(a: isize, b: isize) -> isize { pub unsafe extern "C" fn naked_with_args_and_return(a: isize, b: isize) -> isize {
asm!("lea rax, [rdi + rsi]", "ret", options(noreturn)); naked_asm!("lea rax, [rdi + rsi]", "ret");
} }

View File

@ -1,7 +1,7 @@
#![feature(naked_functions, asm_const, linkage)] #![feature(naked_functions, asm_const, linkage)]
#![crate_type = "dylib"] #![crate_type = "dylib"]
use std::arch::asm; use std::arch::naked_asm;
pub trait TraitWithConst { pub trait TraitWithConst {
const COUNT: u32; const COUNT: u32;
@ -28,7 +28,7 @@ extern "C" fn private_vanilla() -> u32 {
#[naked] #[naked]
extern "C" fn private_naked() -> u32 { extern "C" fn private_naked() -> u32 {
unsafe { asm!("mov rax, 42", "ret", options(noreturn)) } unsafe { naked_asm!("mov rax, 42", "ret") }
} }
#[no_mangle] #[no_mangle]
@ -39,7 +39,7 @@ pub extern "C" fn public_vanilla() -> u32 {
#[naked] #[naked]
#[no_mangle] #[no_mangle]
pub extern "C" fn public_naked() -> u32 { pub extern "C" fn public_naked() -> u32 {
unsafe { asm!("mov rax, 42", "ret", options(noreturn)) } unsafe { naked_asm!("mov rax, 42", "ret") }
} }
pub extern "C" fn public_vanilla_generic<T: TraitWithConst>() -> u32 { pub extern "C" fn public_vanilla_generic<T: TraitWithConst>() -> u32 {
@ -48,7 +48,7 @@ pub extern "C" fn public_vanilla_generic<T: TraitWithConst>() -> u32 {
#[naked] #[naked]
pub extern "C" fn public_naked_generic<T: TraitWithConst>() -> u32 { pub extern "C" fn public_naked_generic<T: TraitWithConst>() -> u32 {
unsafe { asm!("mov rax, {}", "ret", const T::COUNT, options(noreturn)) } unsafe { naked_asm!("mov rax, {}", "ret", const T::COUNT) }
} }
#[linkage = "external"] #[linkage = "external"]
@ -59,7 +59,7 @@ extern "C" fn vanilla_external_linkage() -> u32 {
#[naked] #[naked]
#[linkage = "external"] #[linkage = "external"]
extern "C" fn naked_external_linkage() -> u32 { extern "C" fn naked_external_linkage() -> u32 {
unsafe { asm!("mov rax, 42", "ret", options(noreturn)) } unsafe { naked_asm!("mov rax, 42", "ret") }
} }
#[cfg(not(windows))] #[cfg(not(windows))]
@ -72,7 +72,7 @@ extern "C" fn vanilla_weak_linkage() -> u32 {
#[cfg(not(windows))] #[cfg(not(windows))]
#[linkage = "weak"] #[linkage = "weak"]
extern "C" fn naked_weak_linkage() -> u32 { extern "C" fn naked_weak_linkage() -> u32 {
unsafe { asm!("mov rax, 42", "ret", options(noreturn)) } unsafe { naked_asm!("mov rax, 42", "ret", options(noreturn)) }
} }
// functions that are declared in an `extern "C"` block are currently not exported // functions that are declared in an `extern "C"` block are currently not exported

View File

@ -1,7 +1,7 @@
error[E0658]: use of unstable library feature 'naked_functions' error[E0658]: use of unstable library feature 'naked_functions'
--> $DIR/feature-gate-naked_functions.rs:9:5 --> $DIR/feature-gate-naked_functions.rs:9:5
| |
LL | naked_asm!("", options(noreturn)) LL | naked_asm!("")
| ^^^^^^^^^ | ^^^^^^^^^
| |
= note: see issue #90957 <https://github.com/rust-lang/rust/issues/90957> for more information = note: see issue #90957 <https://github.com/rust-lang/rust/issues/90957> for more information
@ -11,7 +11,7 @@ LL | naked_asm!("", options(noreturn))
error[E0658]: use of unstable library feature 'naked_functions' error[E0658]: use of unstable library feature 'naked_functions'
--> $DIR/feature-gate-naked_functions.rs:17:5 --> $DIR/feature-gate-naked_functions.rs:17:5
| |
LL | naked_asm!("", options(noreturn)) LL | naked_asm!("")
| ^^^^^^^^^ | ^^^^^^^^^
| |
= note: see issue #90957 <https://github.com/rust-lang/rust/issues/90957> for more information = note: see issue #90957 <https://github.com/rust-lang/rust/issues/90957> for more information
@ -51,16 +51,16 @@ LL | use std::arch::naked_asm;
error[E0133]: use of inline assembly is unsafe and requires unsafe function or block error[E0133]: use of inline assembly is unsafe and requires unsafe function or block
--> $DIR/feature-gate-naked_functions.rs:9:5 --> $DIR/feature-gate-naked_functions.rs:9:5
| |
LL | naked_asm!("", options(noreturn)) LL | naked_asm!("")
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use of inline assembly | ^^^^^^^^^^^^^^ use of inline assembly
| |
= note: inline assembly is entirely unchecked and can cause undefined behavior = note: inline assembly is entirely unchecked and can cause undefined behavior
error[E0133]: use of inline assembly is unsafe and requires unsafe function or block error[E0133]: use of inline assembly is unsafe and requires unsafe function or block
--> $DIR/feature-gate-naked_functions.rs:17:5 --> $DIR/feature-gate-naked_functions.rs:17:5
| |
LL | naked_asm!("", options(noreturn)) LL | naked_asm!("")
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use of inline assembly | ^^^^^^^^^^^^^^ use of inline assembly
| |
= note: inline assembly is entirely unchecked and can cause undefined behavior = note: inline assembly is entirely unchecked and can cause undefined behavior

View File

@ -1,14 +1,14 @@
//@ needs-asm-support //@ needs-asm-support
#![feature(naked_functions)] #![feature(naked_functions)]
use std::arch::asm; use std::arch::naked_asm;
#[track_caller] //~ ERROR [E0736] #[track_caller] //~ ERROR [E0736]
//~^ ERROR `#[track_caller]` requires Rust ABI //~^ ERROR `#[track_caller]` requires Rust ABI
#[naked] #[naked]
extern "C" fn f() { extern "C" fn f() {
unsafe { unsafe {
asm!("", options(noreturn)); naked_asm!("");
} }
} }
@ -20,7 +20,7 @@ impl S {
#[naked] #[naked]
extern "C" fn g() { extern "C" fn g() {
unsafe { unsafe {
asm!("", options(noreturn)); naked_asm!("");
} }
} }
} }