Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 26 additions & 23 deletions tests/codegen-llvm/naked-fn/naked-functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,14 @@ use minicore::*;
#[no_mangle]
#[unsafe(naked)]
pub extern "C" fn naked_empty() {
#[cfg(not(all(target_arch = "arm", target_feature = "thumb-mode")))]
naked_asm!("ret");

#[cfg(all(target_arch = "arm", target_feature = "thumb-mode"))]
naked_asm!("bx lr");
cfg_select! {
all(target_arch = "arm", target_feature = "thumb-mode") => {
naked_asm!("bx lr");
}
_ => {
naked_asm!("ret");
}
}
}

// linux,win: .intel_syntax
Expand Down Expand Up @@ -116,19 +119,16 @@ pub extern "C" fn naked_empty() {
#[no_mangle]
#[unsafe(naked)]
pub extern "C" fn naked_with_args_and_return(a: isize, b: isize) -> isize {
#[cfg(any(target_os = "windows", target_os = "linux"))]
{
naked_asm!("lea rax, [rdi + rsi]", "ret")
}

#[cfg(target_os = "macos")]
{
naked_asm!("add x0, x0, x1", "ret")
}

#[cfg(all(target_arch = "arm", target_feature = "thumb-mode"))]
{
naked_asm!("adds r0, r0, r1", "bx lr")
cfg_select! {
any(target_arch = "x86_64", target_arch = "x86") => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be any(target_os = "windows", target_os = "linux")?

Seems like the next clause is also the wrong one?

Copy link
Contributor Author

@folkertdev folkertdev Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did change the clause, but I believe that the change is correct. What assembly to use depends on the target architecture, not on the target operating system.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I guess in practice this worked before because we run this test with specific targets... so macOS really was always aarch64, while linux/win was x86_64/x86.

//@[linux] compile-flags: --target x86_64-unknown-linux-gnu
//@[linux] needs-llvm-components: x86
//@[win_x86] compile-flags: --target x86_64-pc-windows-gnu
//@[win_x86] needs-llvm-components: x86
//@[win_i686] compile-flags: --target i686-pc-windows-gnu
//@[win_i686] needs-llvm-components: x86
//@[macos] compile-flags: --target aarch64-apple-darwin
//@[macos] needs-llvm-components: aarch64

naked_asm!("lea rax, [rdi + rsi]", "ret")
}
target_arch = "aarch64" => {
naked_asm!("add x0, x0, x1", "ret")
}
all(target_arch = "arm", target_feature = "thumb-mode") => {
naked_asm!("adds r0, r0, r1", "bx lr")
}
}
}

Expand All @@ -141,11 +141,14 @@ pub extern "C" fn naked_with_args_and_return(a: isize, b: isize) -> isize {
#[unsafe(naked)]
#[link_section = ".text.some_different_name"]
pub extern "C" fn test_link_section() {
#[cfg(not(all(target_arch = "arm", target_feature = "thumb-mode")))]
naked_asm!("ret");

#[cfg(all(target_arch = "arm", target_feature = "thumb-mode"))]
naked_asm!("bx lr");
cfg_select! {
all(target_arch = "arm", target_feature = "thumb-mode") => {
naked_asm!("bx lr");
}
_ => {
naked_asm!("ret");
}
}
}

// win_x86: .def fastcall_cc
Expand Down
Loading