rust/tests/codegen/naked-fn/min-function-alignment.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

45 lines
1 KiB
Rust
Raw Normal View History

2024-12-18 22:03:07 +01:00
//@ compile-flags: -C no-prepopulate-passes -Copt-level=0 -Zmin-function-alignment=16
//@ needs-asm-support
//@ ignore-arm no "ret" mnemonic
#![feature(naked_functions, fn_align)]
#![crate_type = "lib"]
// functions without explicit alignment use the global minimum
//
// CHECK: .balign 16
#[no_mangle]
2025-03-29 17:30:11 +01:00
#[unsafe(naked)]
pub extern "C" fn naked_no_explicit_align() {
2024-12-18 22:03:07 +01:00
core::arch::naked_asm!("ret")
}
// CHECK: .balign 16
#[no_mangle]
#[repr(align(8))]
2025-03-29 17:30:11 +01:00
#[unsafe(naked)]
pub extern "C" fn naked_lower_align() {
2024-12-18 22:03:07 +01:00
core::arch::naked_asm!("ret")
}
// CHECK: .balign 32
#[no_mangle]
#[repr(align(32))]
2025-03-29 17:30:11 +01:00
#[unsafe(naked)]
pub extern "C" fn naked_higher_align() {
2024-12-18 22:03:07 +01:00
core::arch::naked_asm!("ret")
}
// cold functions follow the same rules as other functions
//
// in GCC, the `-falign-functions` does not apply to cold functions, but
// `-Zmin-function-alignment` applies to all functions.
//
// CHECK: .balign 16
#[no_mangle]
#[cold]
2025-03-29 17:30:11 +01:00
#[unsafe(naked)]
pub extern "C" fn no_explicit_align_cold() {
2024-12-18 22:03:07 +01:00
core::arch::naked_asm!("ret")
}