Skip to content

Commit 62768a7

Browse files
committed
add codegen tests for 4 interesting platforms
1 parent 631f4cf commit 62768a7

File tree

2 files changed

+131
-43
lines changed

2 files changed

+131
-43
lines changed
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
//@ revisions: linux windows macos thumb
2+
//
3+
//@[linux] compile-flags: --target x86_64-unknown-linux-gnu
4+
//@[linux] needs-llvm-components: x86
5+
//@[windows] compile-flags: --target x86_64-pc-windows-gnu
6+
//@[windows] needs-llvm-components: x86
7+
//@[macos] compile-flags: --target aarch64-apple-darwin
8+
//@[macos] needs-llvm-components: arm
9+
//@[thumb] compile-flags: --target thumbv7em-none-eabi
10+
//@[thumb] needs-llvm-components: arm
11+
12+
#![crate_type = "lib"]
13+
#![feature(no_core, lang_items, rustc_attrs, naked_functions)]
14+
#![no_core]
15+
16+
#[rustc_builtin_macro]
17+
macro_rules! asm {
18+
() => {};
19+
}
20+
21+
#[lang = "sized"]
22+
trait Sized {}
23+
#[lang = "copy"]
24+
trait Copy {}
25+
26+
// linux,windows: .intel_syntax
27+
//
28+
// linux: .pushsection .text.naked_empty,\22ax\22, @progbits
29+
// macos: .pushsection __TEXT,__text,regular,pure_instructions
30+
// windows: .pushsection .text.naked_empty,\22xr\22
31+
// thumb: .pushsection .text.naked_empty,\22ax\22, %progbits
32+
//
33+
// CHECK: .balign 4
34+
//
35+
// linux,windows,thumb: .globl naked_empty
36+
// macos: .globl _naked_empty
37+
//
38+
// CHECK-NOT: .private_extern
39+
// CHECK-NOT: .hidden
40+
//
41+
// linux: .type naked_empty, @function
42+
//
43+
// windows: .def naked_empty
44+
// windows: .scl 2
45+
// windows: .type 32
46+
// windows: .endef naked_empty
47+
//
48+
// thumb: .type naked_empty, %function
49+
// thumb: .thumb
50+
// thumb: .thumb_func
51+
//
52+
// CHECK-LABEL: naked_empty:
53+
//
54+
// linux,macos,windows: ret
55+
// thumb: bx lr
56+
//
57+
// CHECK: .popsection
58+
//
59+
// thumb: .thumb
60+
//
61+
// linux,windows: .att_syntax
62+
63+
#[no_mangle]
64+
#[naked]
65+
pub unsafe extern "C" fn naked_empty() {
66+
#[cfg(not(all(target_arch = "arm", target_feature = "thumb-mode")))]
67+
asm!("ret", options(noreturn));
68+
69+
#[cfg(all(target_arch = "arm", target_feature = "thumb-mode"))]
70+
asm!("bx lr", options(noreturn));
71+
}
72+
73+
// linux,windows: .intel_syntax
74+
//
75+
// linux: .pushsection .text.naked_with_args_and_return,\22ax\22, @progbits
76+
// macos: .pushsection __TEXT,__text,regular,pure_instructions
77+
// windows: .pushsection .text.naked_with_args_and_return,\22xr\22
78+
// thumb: .pushsection .text.naked_with_args_and_return,\22ax\22, %progbits
79+
//
80+
// CHECK: .balign 4
81+
//
82+
// linux,windows,thumb: .globl naked_with_args_and_return
83+
// macos: .globl _naked_with_args_and_return
84+
//
85+
// CHECK-NOT: .private_extern
86+
// CHECK-NOT: .hidden
87+
//
88+
// linux: .type naked_with_args_and_return, @function
89+
//
90+
// windows: .def naked_with_args_and_return
91+
// windows: .scl 2
92+
// windows: .type 32
93+
// windows: .endef naked_with_args_and_return
94+
//
95+
// thumb: .type naked_with_args_and_return, %function
96+
// thumb: .thumb
97+
// thumb: .thumb_func
98+
//
99+
// CHECK-LABEL: naked_with_args_and_return:
100+
//
101+
// linux, windows: lea rax, [rdi + rsi]
102+
// macos: add x0, x0, x1
103+
// thumb: adds r0, r0, r1
104+
//
105+
// linux,macos,windows: ret
106+
// thumb: bx lr
107+
//
108+
// CHECK: .popsection
109+
//
110+
// thumb: .thumb
111+
//
112+
// linux,windows: .att_syntax
113+
114+
#[no_mangle]
115+
#[naked]
116+
pub unsafe extern "C" fn naked_with_args_and_return(a: isize, b: isize) -> isize {
117+
#[cfg(any(target_os = "windows", target_os = "linux"))]
118+
{
119+
asm!("lea rax, [rdi + rsi]", "ret", options(noreturn))
120+
}
121+
122+
#[cfg(target_os = "macos")]
123+
{
124+
asm!("add x0, x0, x1", "ret", options(noreturn))
125+
}
126+
127+
#[cfg(all(target_arch = "arm", target_feature = "thumb-mode"))]
128+
{
129+
asm!("adds r0, r0, r1", "bx lr", options(noreturn))
130+
}
131+
}

tests/codegen/naked-fn/x86_64-linux.rs

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)