about summary refs log tree commit diff
path: root/tests/codegen
diff options
context:
space:
mode:
authorFolkert de Vries <folkert@folkertdev.nl>2024-12-18 22:03:07 +0100
committerFolkert de Vries <folkert@folkertdev.nl>2025-01-10 22:53:54 +0100
commit47573bf61ec0807cee3cf2c5c1ca88bb7d5b89cd (patch)
treebe340fec403359a7cfcc5cb06b61f555e7b0788b /tests/codegen
parenta52085d9f6a6e596b0cbad4502cddf86bc878028 (diff)
downloadrust-47573bf61ec0807cee3cf2c5c1ca88bb7d5b89cd.tar.gz
rust-47573bf61ec0807cee3cf2c5c1ca88bb7d5b89cd.zip
add `-Zmin-function-alignment`
Diffstat (limited to 'tests/codegen')
-rw-r--r--tests/codegen/min-function-alignment.rs43
-rw-r--r--tests/codegen/naked-fn/min-function-alignment.rs44
2 files changed, 87 insertions, 0 deletions
diff --git a/tests/codegen/min-function-alignment.rs b/tests/codegen/min-function-alignment.rs
new file mode 100644
index 00000000000..7c0ad12402a
--- /dev/null
+++ b/tests/codegen/min-function-alignment.rs
@@ -0,0 +1,43 @@
+//@ revisions: align16 align1024
+//@ compile-flags: -C no-prepopulate-passes -Z mir-opt-level=0
+//@ [align16] compile-flags: -Zmin-function-alignment=16
+//@ [align1024] compile-flags: -Zmin-function-alignment=1024
+
+#![crate_type = "lib"]
+#![feature(fn_align)]
+
+// functions without explicit alignment use the global minimum
+//
+// CHECK-LABEL: @no_explicit_align
+// align16: align 16
+// align1024: align 1024
+#[no_mangle]
+pub fn no_explicit_align() {}
+
+// CHECK-LABEL: @lower_align
+// align16: align 16
+// align1024: align 1024
+#[no_mangle]
+#[repr(align(8))]
+pub fn lower_align() {}
+
+// the higher value of min-function-alignment and repr(align) wins out
+//
+// CHECK-LABEL: @higher_align
+// align16: align 32
+// align1024: align 1024
+#[no_mangle]
+#[repr(align(32))]
+pub fn higher_align() {}
+
+// 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-LABEL: @no_explicit_align_cold
+// align16: align 16
+// align1024: align 1024
+#[no_mangle]
+#[cold]
+pub fn no_explicit_align_cold() {}
diff --git a/tests/codegen/naked-fn/min-function-alignment.rs b/tests/codegen/naked-fn/min-function-alignment.rs
new file mode 100644
index 00000000000..1330d796d39
--- /dev/null
+++ b/tests/codegen/naked-fn/min-function-alignment.rs
@@ -0,0 +1,44 @@
+//@ 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]
+#[naked]
+pub unsafe extern "C" fn naked_no_explicit_align() {
+    core::arch::naked_asm!("ret")
+}
+
+// CHECK: .balign 16
+#[no_mangle]
+#[repr(align(8))]
+#[naked]
+pub unsafe extern "C" fn naked_lower_align() {
+    core::arch::naked_asm!("ret")
+}
+
+// CHECK: .balign 32
+#[no_mangle]
+#[repr(align(32))]
+#[naked]
+pub unsafe extern "C" fn naked_higher_align() {
+    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]
+#[naked]
+pub unsafe extern "C" fn no_explicit_align_cold() {
+    core::arch::naked_asm!("ret")
+}