Skip to content

Commit

Permalink
use naked_asm! in naked-function tests
Browse files Browse the repository at this point in the history
  • Loading branch information
folkertdev committed Aug 4, 2024
1 parent ddabf5f commit 863f235
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 48 deletions.
6 changes: 3 additions & 3 deletions tests/codegen/naked-fn/naked-functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#![crate_type = "lib"]
#![feature(naked_functions)]
use std::arch::asm;
use std::arch::naked_asm;

// CHECK: Function Attrs: naked
// CHECK-NEXT: define{{.*}}void @naked_empty()
Expand All @@ -14,7 +14,7 @@ pub unsafe extern "C" fn naked_empty() {
// CHECK-NEXT: {{.+}}:
// CHECK-NEXT: call void asm
// CHECK-NEXT: unreachable
asm!("ret", options(noreturn));
naked_asm!("ret", options(noreturn));
}

// CHECK: Function Attrs: naked
Expand All @@ -25,5 +25,5 @@ pub unsafe extern "C" fn naked_with_args_and_return(a: isize, b: isize) -> isize
// CHECK-NEXT: {{.+}}:
// CHECK-NEXT: call void asm
// CHECK-NEXT: unreachable
asm!("lea rax, [rdi + rsi]", "ret", options(noreturn));
naked_asm!("lea rax, [rdi + rsi]", "ret", options(noreturn));
}
4 changes: 2 additions & 2 deletions tests/ui/asm/naked-functions-ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
#![feature(naked_functions)]
#![crate_type = "lib"]

use std::arch::asm;
use std::arch::naked_asm;

#[naked]
pub extern "C" fn naked(p: char) -> u128 {
//~^ WARN uses type `char`
//~| WARN uses type `u128`
unsafe {
asm!("", options(noreturn));
naked_asm!("", options(noreturn));
}
}
12 changes: 6 additions & 6 deletions tests/ui/asm/naked-functions-inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,37 @@
#![feature(naked_functions)]
#![crate_type = "lib"]

use std::arch::asm;
use std::arch::naked_asm;

#[naked]
pub unsafe extern "C" fn inline_none() {
asm!("", options(noreturn));
naked_asm!("", options(noreturn));
}

#[naked]
#[inline]
//~^ ERROR [E0736]
pub unsafe extern "C" fn inline_hint() {
asm!("", options(noreturn));
naked_asm!("", options(noreturn));
}

#[naked]
#[inline(always)]
//~^ ERROR [E0736]
pub unsafe extern "C" fn inline_always() {
asm!("", options(noreturn));
naked_asm!("", options(noreturn));
}

#[naked]
#[inline(never)]
//~^ ERROR [E0736]
pub unsafe extern "C" fn inline_never() {
asm!("", options(noreturn));
naked_asm!("", options(noreturn));
}

#[naked]
#[cfg_attr(all(), inline(never))]
//~^ ERROR [E0736]
pub unsafe extern "C" fn conditional_inline_never() {
asm!("", options(noreturn));
naked_asm!("", options(noreturn));
}
6 changes: 3 additions & 3 deletions tests/ui/asm/naked-functions-instruction-set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#![no_core]

#[rustc_builtin_macro]
macro_rules! asm {
macro_rules! naked_asm {
() => {};
}

Expand All @@ -19,12 +19,12 @@ trait Sized {}
#[naked]
#[instruction_set(arm::t32)]
unsafe extern "C" fn test_thumb() {
asm!("bx lr", options(noreturn));
naked_asm!("bx lr", options(noreturn));
}

#[no_mangle]
#[naked]
#[instruction_set(arm::t32)]
unsafe extern "C" fn test_arm() {
asm!("bx lr", options(noreturn));
naked_asm!("bx lr", options(noreturn));
}
10 changes: 5 additions & 5 deletions tests/ui/asm/naked-functions-testattrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,34 @@
#![feature(test)]
#![crate_type = "lib"]

use std::arch::asm;
use std::arch::naked_asm;

#[test]
#[naked]
//~^ ERROR [E0736]
fn test_naked() {
unsafe { asm!("", options(noreturn)) };
unsafe { naked_asm!("", options(noreturn)) };
}

#[should_panic]
#[test]
#[naked]
//~^ ERROR [E0736]
fn test_naked_should_panic() {
unsafe { asm!("", options(noreturn)) };
unsafe { naked_asm!("", options(noreturn)) };
}

#[ignore]
#[test]
#[naked]
//~^ ERROR [E0736]
fn test_naked_ignore() {
unsafe { asm!("", options(noreturn)) };
unsafe { naked_asm!("", options(noreturn)) };
}

#[bench]
#[naked]
//~^ ERROR [E0736]
fn bench_naked() {
unsafe { asm!("", options(noreturn)) };
unsafe { naked_asm!("", options(noreturn)) };
}
16 changes: 8 additions & 8 deletions tests/ui/asm/naked-functions-unused.aarch64.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -18,49 +18,49 @@ LL | pub extern "C" fn function(a: usize, b: usize) -> usize {
| ^ help: if this is intentional, prefix it with an underscore: `_b`

error: unused variable: `a`
--> $DIR/naked-functions-unused.rs:26:38
--> $DIR/naked-functions-unused.rs:28:38
|
LL | pub extern "C" fn associated(a: usize, b: usize) -> usize {
| ^ help: if this is intentional, prefix it with an underscore: `_a`

error: unused variable: `b`
--> $DIR/naked-functions-unused.rs:26:48
--> $DIR/naked-functions-unused.rs:28:48
|
LL | pub extern "C" fn associated(a: usize, b: usize) -> usize {
| ^ help: if this is intentional, prefix it with an underscore: `_b`

error: unused variable: `a`
--> $DIR/naked-functions-unused.rs:32:41
--> $DIR/naked-functions-unused.rs:36:41
|
LL | pub extern "C" fn method(&self, a: usize, b: usize) -> usize {
| ^ help: if this is intentional, prefix it with an underscore: `_a`

error: unused variable: `b`
--> $DIR/naked-functions-unused.rs:32:51
--> $DIR/naked-functions-unused.rs:36:51
|
LL | pub extern "C" fn method(&self, a: usize, b: usize) -> usize {
| ^ help: if this is intentional, prefix it with an underscore: `_b`

error: unused variable: `a`
--> $DIR/naked-functions-unused.rs:40:40
--> $DIR/naked-functions-unused.rs:46:40
|
LL | extern "C" fn trait_associated(a: usize, b: usize) -> usize {
| ^ help: if this is intentional, prefix it with an underscore: `_a`

error: unused variable: `b`
--> $DIR/naked-functions-unused.rs:40:50
--> $DIR/naked-functions-unused.rs:46:50
|
LL | extern "C" fn trait_associated(a: usize, b: usize) -> usize {
| ^ help: if this is intentional, prefix it with an underscore: `_b`

error: unused variable: `a`
--> $DIR/naked-functions-unused.rs:46:43
--> $DIR/naked-functions-unused.rs:54:43
|
LL | extern "C" fn trait_method(&self, a: usize, b: usize) -> usize {
| ^ help: if this is intentional, prefix it with an underscore: `_a`

error: unused variable: `b`
--> $DIR/naked-functions-unused.rs:46:53
--> $DIR/naked-functions-unused.rs:54:53
|
LL | extern "C" fn trait_method(&self, a: usize, b: usize) -> usize {
| ^ help: if this is intentional, prefix it with an underscore: `_b`
Expand Down
42 changes: 31 additions & 11 deletions tests/ui/asm/naked-functions-unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ pub mod normal {
pub extern "C" fn function(a: usize, b: usize) -> usize {
//~^ ERROR unused variable: `a`
//~| ERROR unused variable: `b`
unsafe { asm!("", options(noreturn)); }
unsafe {
asm!("", options(noreturn));
}
}

pub struct Normal;
Expand All @@ -26,62 +28,80 @@ pub mod normal {
pub extern "C" fn associated(a: usize, b: usize) -> usize {
//~^ ERROR unused variable: `a`
//~| ERROR unused variable: `b`
unsafe { asm!("", options(noreturn)); }
unsafe {
asm!("", options(noreturn));
}
}

pub extern "C" fn method(&self, a: usize, b: usize) -> usize {
//~^ ERROR unused variable: `a`
//~| ERROR unused variable: `b`
unsafe { asm!("", options(noreturn)); }
unsafe {
asm!("", options(noreturn));
}
}
}

impl super::Trait for Normal {
extern "C" fn trait_associated(a: usize, b: usize) -> usize {
//~^ ERROR unused variable: `a`
//~| ERROR unused variable: `b`
unsafe { asm!("", options(noreturn)); }
unsafe {
asm!("", options(noreturn));
}
}

extern "C" fn trait_method(&self, a: usize, b: usize) -> usize {
//~^ ERROR unused variable: `a`
//~| ERROR unused variable: `b`
unsafe { asm!("", options(noreturn)); }
unsafe {
asm!("", options(noreturn));
}
}
}
}

pub mod naked {
use std::arch::asm;
use std::arch::naked_asm;

#[naked]
pub extern "C" fn function(a: usize, b: usize) -> usize {
unsafe { asm!("", options(noreturn)); }
unsafe {
naked_asm!("", options(noreturn));
}
}

pub struct Naked;

impl Naked {
#[naked]
pub extern "C" fn associated(a: usize, b: usize) -> usize {
unsafe { asm!("", options(noreturn)); }
unsafe {
naked_asm!("", options(noreturn));
}
}

#[naked]
pub extern "C" fn method(&self, a: usize, b: usize) -> usize {
unsafe { asm!("", options(noreturn)); }
unsafe {
naked_asm!("", options(noreturn));
}
}
}

impl super::Trait for Naked {
#[naked]
extern "C" fn trait_associated(a: usize, b: usize) -> usize {
unsafe { asm!("", options(noreturn)); }
unsafe {
naked_asm!("", options(noreturn));
}
}

#[naked]
extern "C" fn trait_method(&self, a: usize, b: usize) -> usize {
unsafe { asm!("", options(noreturn)); }
unsafe {
naked_asm!("", options(noreturn));
}
}
}
}
16 changes: 8 additions & 8 deletions tests/ui/asm/naked-functions-unused.x86_64.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -18,49 +18,49 @@ LL | pub extern "C" fn function(a: usize, b: usize) -> usize {
| ^ help: if this is intentional, prefix it with an underscore: `_b`

error: unused variable: `a`
--> $DIR/naked-functions-unused.rs:26:38
--> $DIR/naked-functions-unused.rs:28:38
|
LL | pub extern "C" fn associated(a: usize, b: usize) -> usize {
| ^ help: if this is intentional, prefix it with an underscore: `_a`

error: unused variable: `b`
--> $DIR/naked-functions-unused.rs:26:48
--> $DIR/naked-functions-unused.rs:28:48
|
LL | pub extern "C" fn associated(a: usize, b: usize) -> usize {
| ^ help: if this is intentional, prefix it with an underscore: `_b`

error: unused variable: `a`
--> $DIR/naked-functions-unused.rs:32:41
--> $DIR/naked-functions-unused.rs:36:41
|
LL | pub extern "C" fn method(&self, a: usize, b: usize) -> usize {
| ^ help: if this is intentional, prefix it with an underscore: `_a`

error: unused variable: `b`
--> $DIR/naked-functions-unused.rs:32:51
--> $DIR/naked-functions-unused.rs:36:51
|
LL | pub extern "C" fn method(&self, a: usize, b: usize) -> usize {
| ^ help: if this is intentional, prefix it with an underscore: `_b`

error: unused variable: `a`
--> $DIR/naked-functions-unused.rs:40:40
--> $DIR/naked-functions-unused.rs:46:40
|
LL | extern "C" fn trait_associated(a: usize, b: usize) -> usize {
| ^ help: if this is intentional, prefix it with an underscore: `_a`

error: unused variable: `b`
--> $DIR/naked-functions-unused.rs:40:50
--> $DIR/naked-functions-unused.rs:46:50
|
LL | extern "C" fn trait_associated(a: usize, b: usize) -> usize {
| ^ help: if this is intentional, prefix it with an underscore: `_b`

error: unused variable: `a`
--> $DIR/naked-functions-unused.rs:46:43
--> $DIR/naked-functions-unused.rs:54:43
|
LL | extern "C" fn trait_method(&self, a: usize, b: usize) -> usize {
| ^ help: if this is intentional, prefix it with an underscore: `_a`

error: unused variable: `b`
--> $DIR/naked-functions-unused.rs:46:53
--> $DIR/naked-functions-unused.rs:54:53
|
LL | extern "C" fn trait_method(&self, a: usize, b: usize) -> usize {
| ^ help: if this is intentional, prefix it with an underscore: `_b`
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/feature-gates/feature-gate-naked_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ use std::arch::asm;
#[naked]
//~^ the `#[naked]` attribute is an experimental feature
extern "C" fn naked() {
asm!("", options(noreturn))
naked_asm!("", options(noreturn))
//~^ ERROR: requires unsafe
}

#[naked]
//~^ the `#[naked]` attribute is an experimental feature
extern "C" fn naked_2() -> isize {
asm!("", options(noreturn))
naked_asm!("", options(noreturn))
//~^ ERROR: requires unsafe
}

Expand Down

0 comments on commit 863f235

Please sign in to comment.