]> git.lizzy.rs Git - rust.git/blob - src/test/codegen/function-arguments.rs
rustdoc: Early doc link resolution fixes and refactorings
[rust.git] / src / test / codegen / function-arguments.rs
1 // compile-flags: -O -C no-prepopulate-passes
2
3 #![crate_type = "lib"]
4 #![feature(rustc_attrs)]
5
6 use std::mem::MaybeUninit;
7 use std::num::NonZeroU64;
8
9 pub struct S {
10   _field: [i32; 8],
11 }
12
13 pub struct UnsafeInner {
14   _field: std::cell::UnsafeCell<i16>,
15 }
16
17 pub enum MyBool {
18   True,
19   False,
20 }
21
22 // CHECK: noundef zeroext i1 @boolean(i1 noundef zeroext %x)
23 #[no_mangle]
24 pub fn boolean(x: bool) -> bool {
25   x
26 }
27
28 // CHECK: i8 @maybeuninit_boolean(i8 %x)
29 #[no_mangle]
30 pub fn maybeuninit_boolean(x: MaybeUninit<bool>) -> MaybeUninit<bool> {
31   x
32 }
33
34 // CHECK: noundef zeroext i1 @enum_bool(i1 noundef zeroext %x)
35 #[no_mangle]
36 pub fn enum_bool(x: MyBool) -> MyBool {
37   x
38 }
39
40 // CHECK: i8 @maybeuninit_enum_bool(i8 %x)
41 #[no_mangle]
42 pub fn maybeuninit_enum_bool(x: MaybeUninit<MyBool>) -> MaybeUninit<MyBool> {
43   x
44 }
45
46 // CHECK: noundef i32 @char(i32 noundef %x)
47 #[no_mangle]
48 pub fn char(x: char) -> char {
49   x
50 }
51
52 // CHECK: i32 @maybeuninit_char(i32 %x)
53 #[no_mangle]
54 pub fn maybeuninit_char(x: MaybeUninit<char>) -> MaybeUninit<char> {
55   x
56 }
57
58 // CHECK: i64 @int(i64 %x)
59 #[no_mangle]
60 pub fn int(x: u64) -> u64 {
61   x
62 }
63
64 // CHECK: noundef i64 @nonzero_int(i64 noundef %x)
65 #[no_mangle]
66 pub fn nonzero_int(x: NonZeroU64) -> NonZeroU64 {
67   x
68 }
69
70 // CHECK: i64 @option_nonzero_int(i64 %x)
71 #[no_mangle]
72 pub fn option_nonzero_int(x: Option<NonZeroU64>) -> Option<NonZeroU64> {
73   x
74 }
75
76 // CHECK: @readonly_borrow(i32* noalias noundef readonly align 4 dereferenceable(4) %_1)
77 // FIXME #25759 This should also have `nocapture`
78 #[no_mangle]
79 pub fn readonly_borrow(_: &i32) {
80 }
81
82 // CHECK: @static_borrow(i32* noalias noundef readonly align 4 dereferenceable(4) %_1)
83 // static borrow may be captured
84 #[no_mangle]
85 pub fn static_borrow(_: &'static i32) {
86 }
87
88 // CHECK: @named_borrow(i32* noalias noundef readonly align 4 dereferenceable(4) %_1)
89 // borrow with named lifetime may be captured
90 #[no_mangle]
91 pub fn named_borrow<'r>(_: &'r i32) {
92 }
93
94 // CHECK: @unsafe_borrow(i16* noundef align 2 dereferenceable(2) %_1)
95 // unsafe interior means this isn't actually readonly and there may be aliases ...
96 #[no_mangle]
97 pub fn unsafe_borrow(_: &UnsafeInner) {
98 }
99
100 // CHECK: @mutable_unsafe_borrow(i16* noalias noundef align 2 dereferenceable(2) %_1)
101 // ... unless this is a mutable borrow, those never alias
102 #[no_mangle]
103 pub fn mutable_unsafe_borrow(_: &mut UnsafeInner) {
104 }
105
106 // CHECK: @mutable_borrow(i32* noalias noundef align 4 dereferenceable(4) %_1)
107 // FIXME #25759 This should also have `nocapture`
108 #[no_mangle]
109 pub fn mutable_borrow(_: &mut i32) {
110 }
111
112 // CHECK: @indirect_struct(%S* noalias nocapture noundef dereferenceable(32) %_1)
113 #[no_mangle]
114 pub fn indirect_struct(_: S) {
115 }
116
117 // CHECK: @borrowed_struct(%S* noalias noundef readonly align 4 dereferenceable(32) %_1)
118 // FIXME #25759 This should also have `nocapture`
119 #[no_mangle]
120 pub fn borrowed_struct(_: &S) {
121 }
122
123 // CHECK: @raw_struct(%S* %_1)
124 #[no_mangle]
125 pub fn raw_struct(_: *const S) {
126 }
127
128 // `Box` can get deallocated during execution of the function, so it should
129 // not get `dereferenceable`.
130 // CHECK: noalias noundef nonnull align 4 i32* @_box(i32* noalias noundef nonnull align 4 %x)
131 #[no_mangle]
132 pub fn _box(x: Box<i32>) -> Box<i32> {
133   x
134 }
135
136 // CHECK: @struct_return(%S* noalias nocapture noundef sret(%S) dereferenceable(32){{( %0)?}})
137 #[no_mangle]
138 pub fn struct_return() -> S {
139   S {
140     _field: [0, 0, 0, 0, 0, 0, 0, 0]
141   }
142 }
143
144 // Hack to get the correct size for the length part in slices
145 // CHECK: @helper([[USIZE:i[0-9]+]] %_1)
146 #[no_mangle]
147 pub fn helper(_: usize) {
148 }
149
150 // CHECK: @slice([0 x i8]* noalias noundef nonnull readonly align 1 %_1.0, [[USIZE]] %_1.1)
151 // FIXME #25759 This should also have `nocapture`
152 #[no_mangle]
153 pub fn slice(_: &[u8]) {
154 }
155
156 // CHECK: @mutable_slice([0 x i8]* noalias noundef nonnull align 1 %_1.0, [[USIZE]] %_1.1)
157 // FIXME #25759 This should also have `nocapture`
158 #[no_mangle]
159 pub fn mutable_slice(_: &mut [u8]) {
160 }
161
162 // CHECK: @unsafe_slice([0 x i16]* noundef nonnull align 2 %_1.0, [[USIZE]] %_1.1)
163 // unsafe interior means this isn't actually readonly and there may be aliases ...
164 #[no_mangle]
165 pub fn unsafe_slice(_: &[UnsafeInner]) {
166 }
167
168 // CHECK: @raw_slice([0 x i8]* %_1.0, [[USIZE]] %_1.1)
169 #[no_mangle]
170 pub fn raw_slice(_: *const [u8]) {
171 }
172
173 // CHECK: @str([0 x i8]* noalias noundef nonnull readonly align 1 %_1.0, [[USIZE]] %_1.1)
174 // FIXME #25759 This should also have `nocapture`
175 #[no_mangle]
176 pub fn str(_: &[u8]) {
177 }
178
179 // CHECK: @trait_borrow({}* noundef nonnull align 1 %_1.0, [3 x [[USIZE]]]* noalias noundef readonly align {{.*}} dereferenceable({{.*}}) %_1.1)
180 // FIXME #25759 This should also have `nocapture`
181 #[no_mangle]
182 pub fn trait_borrow(_: &Drop) {
183 }
184
185 // CHECK: @trait_raw({}* %_1.0, [3 x [[USIZE]]]* noalias noundef readonly align {{.*}} dereferenceable({{.*}}) %_1.1)
186 #[no_mangle]
187 pub fn trait_raw(_: *const Drop) {
188 }
189
190 // CHECK: @trait_box({}* noalias noundef nonnull align 1{{( %0)?}}, [3 x [[USIZE]]]* noalias noundef readonly align {{.*}} dereferenceable({{.*}}){{( %1)?}})
191 #[no_mangle]
192 pub fn trait_box(_: Box<Drop>) {
193 }
194
195 // CHECK: { i8*, i8* } @trait_option(i8* noalias noundef align 1 %x.0, i8* %x.1)
196 #[no_mangle]
197 pub fn trait_option(x: Option<Box<Drop>>) -> Option<Box<Drop>> {
198   x
199 }
200
201 // CHECK: { [0 x i16]*, [[USIZE]] } @return_slice([0 x i16]* noalias noundef nonnull readonly align 2 %x.0, [[USIZE]] %x.1)
202 #[no_mangle]
203 pub fn return_slice(x: &[u16]) -> &[u16] {
204   x
205 }
206
207 // CHECK: { i16, i16 } @enum_id_1(i16 noundef %x.0, i16 %x.1)
208 #[no_mangle]
209 pub fn enum_id_1(x: Option<Result<u16, u16>>) -> Option<Result<u16, u16>> {
210   x
211 }
212
213 // CHECK: { i8, i8 } @enum_id_2(i1 noundef zeroext %x.0, i8 %x.1)
214 #[no_mangle]
215 pub fn enum_id_2(x: Option<u8>) -> Option<u8> {
216   x
217 }
218
219 // CHECK: noalias i8* @allocator()
220 #[no_mangle]
221 #[rustc_allocator]
222 pub fn allocator() -> *const i8 {
223   std::ptr::null()
224 }