diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:59:35 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:59:35 +0000 |
commit | d1b2d29528b7794b41e66fc2136e395a02f8529b (patch) | |
tree | a4a17504b260206dec3cf55b2dca82929a348ac2 /tests/codegen/naked-fn | |
parent | Releasing progress-linux version 1.72.1+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.tar.xz rustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.zip |
Merging upstream version 1.73.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/codegen/naked-fn')
-rw-r--r-- | tests/codegen/naked-fn/naked-functions.rs | 32 | ||||
-rw-r--r-- | tests/codegen/naked-fn/naked-nocoverage.rs | 19 | ||||
-rw-r--r-- | tests/codegen/naked-fn/naked-noinline.rs | 31 |
3 files changed, 82 insertions, 0 deletions
diff --git a/tests/codegen/naked-fn/naked-functions.rs b/tests/codegen/naked-fn/naked-functions.rs new file mode 100644 index 000000000..e05bbc26e --- /dev/null +++ b/tests/codegen/naked-fn/naked-functions.rs @@ -0,0 +1,32 @@ +// compile-flags: -C no-prepopulate-passes -Copt-level=0 +// needs-asm-support +// only-x86_64 + +#![crate_type = "lib"] +#![feature(naked_functions)] +use std::arch::asm; + +// CHECK: Function Attrs: naked +// CHECK-NEXT: define{{.*}}void @naked_empty() +#[no_mangle] +#[naked] +pub unsafe extern "C" fn naked_empty() { + // CHECK-NEXT: {{.+}}: + // CHECK-NEXT: call void asm + // CHECK-NEXT: unreachable + asm!("ret", + options(noreturn)); +} + +// CHECK: Function Attrs: naked +// CHECK-NEXT: define{{.*}}i{{[0-9]+}} @naked_with_args_and_return(i64 %a, i64 %b) +#[no_mangle] +#[naked] +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)); +} diff --git a/tests/codegen/naked-fn/naked-nocoverage.rs b/tests/codegen/naked-fn/naked-nocoverage.rs new file mode 100644 index 000000000..3c755e49c --- /dev/null +++ b/tests/codegen/naked-fn/naked-nocoverage.rs @@ -0,0 +1,19 @@ +// Checks that naked functions are not instrumented by -Cinstrument-coverage. +// Regression test for issue #105170. +// +// needs-asm-support +// needs-profiler-support +// compile-flags: -Cinstrument-coverage +#![crate_type = "lib"] +#![feature(naked_functions)] +use std::arch::asm; + +#[naked] +#[no_mangle] +pub unsafe extern "C" fn f() { + // CHECK: define {{(dso_local )?}}void @f() + // CHECK-NEXT: start: + // CHECK-NEXT: call void asm + // CHECK-NEXT: unreachable + asm!("", options(noreturn)); +} diff --git a/tests/codegen/naked-fn/naked-noinline.rs b/tests/codegen/naked-fn/naked-noinline.rs new file mode 100644 index 000000000..5cfb500c0 --- /dev/null +++ b/tests/codegen/naked-fn/naked-noinline.rs @@ -0,0 +1,31 @@ +// Checks that naked functions are never inlined. +// compile-flags: -O -Zmir-opt-level=3 +// needs-asm-support +// ignore-wasm32 +#![crate_type = "lib"] +#![feature(naked_functions)] + +use std::arch::asm; + +#[naked] +#[no_mangle] +pub unsafe extern "C" fn f() { + // Check that f has naked and noinline attributes. + // + // CHECK: define {{(dso_local )?}}void @f() unnamed_addr [[ATTR:#[0-9]+]] + // CHECK-NEXT: start: + // CHECK-NEXT: call void asm + asm!("", options(noreturn)); +} + +#[no_mangle] +pub unsafe fn g() { + // Check that call to f is not inlined. + // + // CHECK-LABEL: define {{(dso_local )?}}void @g() + // CHECK-NEXT: start: + // CHECK-NEXT: call void @f() + f(); +} + +// CHECK: attributes [[ATTR]] = { naked{{.*}}noinline{{.*}} } |