]> git.lizzy.rs Git - rust.git/blob - src/test/codegen/naked-functions.rs
Enable emission of alignment attrs for pointer params
[rust.git] / src / test / codegen / naked-functions.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // ignore-tidy-linelength
12
13 // compile-flags: -C no-prepopulate-passes
14
15 #![crate_type = "lib"]
16 #![feature(naked_functions)]
17
18 // CHECK: Function Attrs: naked
19 // CHECK-NEXT: define void @naked_empty()
20 #[no_mangle]
21 #[naked]
22 pub fn naked_empty() {
23     // CHECK-NEXT: {{.+}}:
24     // CHECK-NEXT: ret void
25 }
26
27 // CHECK: Function Attrs: naked
28 #[no_mangle]
29 #[naked]
30 // CHECK-NEXT: define void @naked_with_args(i{{[0-9]+}})
31 pub fn naked_with_args(a: isize) {
32     // CHECK-NEXT: {{.+}}:
33     // CHECK-NEXT: %a = alloca i{{[0-9]+}}
34     &a; // keep variable in an alloca
35     // CHECK: ret void
36 }
37
38 // CHECK: Function Attrs: naked
39 // CHECK-NEXT: define i{{[0-9]+}} @naked_with_return()
40 #[no_mangle]
41 #[naked]
42 pub fn naked_with_return() -> isize {
43     // CHECK-NEXT: {{.+}}:
44     // CHECK-NEXT: ret i{{[0-9]+}} 0
45     0
46 }
47
48 // CHECK: Function Attrs: naked
49 // CHECK-NEXT: define i{{[0-9]+}} @naked_with_args_and_return(i{{[0-9]+}})
50 #[no_mangle]
51 #[naked]
52 pub fn naked_with_args_and_return(a: isize) -> isize {
53     // CHECK-NEXT: {{.+}}:
54     // CHECK-NEXT: %a = alloca i{{[0-9]+}}
55     &a; // keep variable in an alloca
56     // CHECK: ret i{{[0-9]+}} %{{[0-9]+}}
57     a
58 }
59
60 // CHECK: Function Attrs: naked
61 // CHECK-NEXT: define void @naked_recursive()
62 #[no_mangle]
63 #[naked]
64 pub fn naked_recursive() {
65     // CHECK-NEXT: {{.+}}:
66     // CHECK-NEXT: call void @naked_empty()
67
68     // FIXME(#39685) Avoid one block per call.
69     // CHECK-NEXT: br label %bb1
70     // CHECK: bb1:
71
72     naked_empty();
73
74     // CHECK-NEXT: %{{[0-9]+}} = call i{{[0-9]+}} @naked_with_return()
75
76     // FIXME(#39685) Avoid one block per call.
77     // CHECK-NEXT: br label %bb2
78     // CHECK: bb2:
79
80     // CHECK-NEXT: %{{[0-9]+}} = call i{{[0-9]+}} @naked_with_args_and_return(i{{[0-9]+}} %{{[0-9]+}})
81
82     // FIXME(#39685) Avoid one block per call.
83     // CHECK-NEXT: br label %bb3
84     // CHECK: bb3:
85
86     // CHECK-NEXT: call void @naked_with_args(i{{[0-9]+}} %{{[0-9]+}})
87
88     // FIXME(#39685) Avoid one block per call.
89     // CHECK-NEXT: br label %bb4
90     // CHECK: bb4:
91
92     naked_with_args(
93         naked_with_args_and_return(
94             naked_with_return()
95         )
96     );
97     // CHECK-NEXT: ret void
98 }