]> git.lizzy.rs Git - rust.git/blob - src/test/codegen/function-arguments.rs
Turn `#[allocator]` into a built-in attribute and rename it to `#[rustc_allocator]`
[rust.git] / src / test / codegen / function-arguments.rs
1 // compile-flags: -C no-prepopulate-passes
2 // ignore-tidy-linelength
3
4 #![crate_type = "lib"]
5 #![feature(rustc_attrs)]
6
7 pub struct S {
8   _field: [i32; 8],
9 }
10
11 pub struct UnsafeInner {
12   _field: std::cell::UnsafeCell<i16>,
13 }
14
15 // CHECK: zeroext i1 @boolean(i1 zeroext %x)
16 #[no_mangle]
17 pub fn boolean(x: bool) -> bool {
18   x
19 }
20
21 // CHECK: @readonly_borrow(i32* noalias readonly align 4 dereferenceable(4) %arg0)
22 // FIXME #25759 This should also have `nocapture`
23 #[no_mangle]
24 pub fn readonly_borrow(_: &i32) {
25 }
26
27 // CHECK: @static_borrow(i32* noalias readonly align 4 dereferenceable(4) %arg0)
28 // static borrow may be captured
29 #[no_mangle]
30 pub fn static_borrow(_: &'static i32) {
31 }
32
33 // CHECK: @named_borrow(i32* noalias readonly align 4 dereferenceable(4) %arg0)
34 // borrow with named lifetime may be captured
35 #[no_mangle]
36 pub fn named_borrow<'r>(_: &'r i32) {
37 }
38
39 // CHECK: @unsafe_borrow(i16* align 2 dereferenceable(2) %arg0)
40 // unsafe interior means this isn't actually readonly and there may be aliases ...
41 #[no_mangle]
42 pub fn unsafe_borrow(_: &UnsafeInner) {
43 }
44
45 // CHECK: @mutable_unsafe_borrow(i16* align 2 dereferenceable(2) %arg0)
46 // ... unless this is a mutable borrow, those never alias
47 #[no_mangle]
48 pub fn mutable_unsafe_borrow(_: &mut UnsafeInner) {
49 }
50
51 // CHECK: @mutable_borrow(i32* align 4 dereferenceable(4) %arg0)
52 // FIXME #25759 This should also have `nocapture`
53 #[no_mangle]
54 pub fn mutable_borrow(_: &mut i32) {
55 }
56
57 // CHECK: @indirect_struct(%S* noalias nocapture dereferenceable(32) %arg0)
58 #[no_mangle]
59 pub fn indirect_struct(_: S) {
60 }
61
62 // CHECK: @borrowed_struct(%S* noalias readonly align 4 dereferenceable(32) %arg0)
63 // FIXME #25759 This should also have `nocapture`
64 #[no_mangle]
65 pub fn borrowed_struct(_: &S) {
66 }
67
68 // CHECK: noalias align 4 dereferenceable(4) i32* @_box(i32* noalias align 4 dereferenceable(4) %x)
69 #[no_mangle]
70 pub fn _box(x: Box<i32>) -> Box<i32> {
71   x
72 }
73
74 // CHECK: @struct_return(%S* noalias nocapture sret dereferenceable(32))
75 #[no_mangle]
76 pub fn struct_return() -> S {
77   S {
78     _field: [0, 0, 0, 0, 0, 0, 0, 0]
79   }
80 }
81
82 // Hack to get the correct size for the length part in slices
83 // CHECK: @helper([[USIZE:i[0-9]+]] %arg0)
84 #[no_mangle]
85 pub fn helper(_: usize) {
86 }
87
88 // CHECK: @slice([0 x i8]* noalias nonnull readonly align 1 %arg0.0, [[USIZE]] %arg0.1)
89 // FIXME #25759 This should also have `nocapture`
90 #[no_mangle]
91 pub fn slice(_: &[u8]) {
92 }
93
94 // CHECK: @mutable_slice([0 x i8]* nonnull align 1 %arg0.0, [[USIZE]] %arg0.1)
95 // FIXME #25759 This should also have `nocapture`
96 #[no_mangle]
97 pub fn mutable_slice(_: &mut [u8]) {
98 }
99
100 // CHECK: @unsafe_slice([0 x i16]* nonnull align 2 %arg0.0, [[USIZE]] %arg0.1)
101 // unsafe interior means this isn't actually readonly and there may be aliases ...
102 #[no_mangle]
103 pub fn unsafe_slice(_: &[UnsafeInner]) {
104 }
105
106 // CHECK: @str([0 x i8]* noalias nonnull readonly align 1 %arg0.0, [[USIZE]] %arg0.1)
107 // FIXME #25759 This should also have `nocapture`
108 #[no_mangle]
109 pub fn str(_: &[u8]) {
110 }
111
112 // CHECK: @trait_borrow({}* nonnull align 1 %arg0.0, [3 x [[USIZE]]]* noalias readonly align {{.*}} dereferenceable({{.*}}) %arg0.1)
113 // FIXME #25759 This should also have `nocapture`
114 #[no_mangle]
115 pub fn trait_borrow(_: &Drop) {
116 }
117
118 // CHECK: @trait_box({}* noalias nonnull align 1, [3 x [[USIZE]]]* noalias readonly align {{.*}} dereferenceable({{.*}}))
119 #[no_mangle]
120 pub fn trait_box(_: Box<Drop>) {
121 }
122
123 // CHECK: { i8*, i8* } @trait_option(i8* noalias align 1 %x.0, i8* %x.1)
124 #[no_mangle]
125 pub fn trait_option(x: Option<Box<Drop>>) -> Option<Box<Drop>> {
126   x
127 }
128
129 // CHECK: { [0 x i16]*, [[USIZE]] } @return_slice([0 x i16]* noalias nonnull readonly align 2 %x.0, [[USIZE]] %x.1)
130 #[no_mangle]
131 pub fn return_slice(x: &[u16]) -> &[u16] {
132   x
133 }
134
135 // CHECK: { i16, i16 } @enum_id_1(i16 %x.0, i16 %x.1)
136 #[no_mangle]
137 pub fn enum_id_1(x: Option<Result<u16, u16>>) -> Option<Result<u16, u16>> {
138   x
139 }
140
141 // CHECK: { i8, i8 } @enum_id_2(i1 zeroext %x.0, i8 %x.1)
142 #[no_mangle]
143 pub fn enum_id_2(x: Option<u8>) -> Option<u8> {
144   x
145 }
146
147 // CHECK: noalias i8* @allocator()
148 #[no_mangle]
149 #[rustc_allocator]
150 pub fn allocator() -> *const i8 {
151   std::ptr::null()
152 }