Skip to content

Commit 63a90f4

Browse files
committed
naked functions: test that unused naked functions are not emitted
1 parent 5413f7d commit 63a90f4

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//@ add-core-stubs
2+
//@ revisions: linux win_x86_msvc win_x86_gnu win_i686_gnu macos thumb
3+
//
4+
//@[linux] compile-flags: --target x86_64-unknown-linux-gnu
5+
//@[linux] needs-llvm-components: x86
6+
//@[win_x86_gnu] compile-flags: --target x86_64-pc-windows-gnu
7+
//@[win_x86_gnu] needs-llvm-components: x86
8+
//@[win_x86_msvc] compile-flags: --target x86_64-pc-windows-msvc
9+
//@[win_x86_msvc] needs-llvm-components: x86
10+
//@[win_i686_gnu] compile-flags: --target i686-pc-windows-gnu
11+
//@[win_i686_gnu] needs-llvm-components: x86
12+
//@[macos] compile-flags: --target aarch64-apple-darwin
13+
//@[macos] needs-llvm-components: aarch64
14+
//@[thumb] compile-flags: --target thumbv7em-none-eabi
15+
//@[thumb] needs-llvm-components: arm
16+
17+
#![crate_type = "lib"]
18+
#![feature(no_core, lang_items, rustc_attrs)]
19+
#![no_core]
20+
21+
// Test that unused naked functions are not emitted.
22+
23+
extern crate minicore;
24+
use minicore::*;
25+
26+
#[unsafe(naked)]
27+
extern "C" fn foo() {
28+
naked_asm!("ret")
29+
}
30+
31+
#[unsafe(naked)]
32+
extern "C" fn should_be_eliminated() {
33+
naked_asm!("ret")
34+
}
35+
36+
#[unsafe(no_mangle)]
37+
fn entry() {
38+
foo();
39+
}
40+
41+
// CHECK-NOT: should_be_eliminated
42+
// CHECK-LABEL: foo
43+
// CHECK-NOT: should_be_eliminated

0 commit comments

Comments
 (0)