]> git.lizzy.rs Git - rust.git/blob - src/test/codegen/function-arguments.rs
Rollup merge of #69106 - RReverser:wasi-fs-copy, r=KodrAus
[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) %_1)
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) %_1)
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) %_1)
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) %_1)
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) %_1)
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) %_1)
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) %_1)
58 #[no_mangle]
59 pub fn indirect_struct(_: S) {
60 }
61
62 // CHECK: @borrowed_struct(%S* noalias readonly align 4 dereferenceable(32) %_1)
63 // FIXME #25759 This should also have `nocapture`
64 #[no_mangle]
65 pub fn borrowed_struct(_: &S) {
66 }
67
68 // `Box` can get deallocated during execution of the function, so it should
69 // not get `dereferenceable`.
70 // CHECK: noalias nonnull align 4 i32* @_box(i32* noalias nonnull align 4 %x)
71 #[no_mangle]
72 pub fn _box(x: Box<i32>) -> Box<i32> {
73   x
74 }
75
76 // CHECK: @struct_return(%S* noalias nocapture sret dereferenceable(32){{( %0)?}})
77 #[no_mangle]
78 pub fn struct_return() -> S {
79   S {
80     _field: [0, 0, 0, 0, 0, 0, 0, 0]
81   }
82 }
83
84 // Hack to get the correct size for the length part in slices
85 // CHECK: @helper([[USIZE:i[0-9]+]] %_1)
86 #[no_mangle]
87 pub fn helper(_: usize) {
88 }
89
90 // CHECK: @slice([0 x i8]* noalias nonnull readonly align 1 %_1.0, [[USIZE]] %_1.1)
91 // FIXME #25759 This should also have `nocapture`
92 #[no_mangle]
93 pub fn slice(_: &[u8]) {
94 }
95
96 // CHECK: @mutable_slice([0 x i8]* nonnull align 1 %_1.0, [[USIZE]] %_1.1)
97 // FIXME #25759 This should also have `nocapture`
98 #[no_mangle]
99 pub fn mutable_slice(_: &mut [u8]) {
100 }
101
102 // CHECK: @unsafe_slice([0 x i16]* nonnull align 2 %_1.0, [[USIZE]] %_1.1)
103 // unsafe interior means this isn't actually readonly and there may be aliases ...
104 #[no_mangle]
105 pub fn unsafe_slice(_: &[UnsafeInner]) {
106 }
107
108 // CHECK: @str([0 x i8]* noalias nonnull readonly align 1 %_1.0, [[USIZE]] %_1.1)
109 // FIXME #25759 This should also have `nocapture`
110 #[no_mangle]
111 pub fn str(_: &[u8]) {
112 }
113
114 // CHECK: @trait_borrow({}* nonnull align 1 %_1.0, [3 x [[USIZE]]]* noalias readonly align {{.*}} dereferenceable({{.*}}) %_1.1)
115 // FIXME #25759 This should also have `nocapture`
116 #[no_mangle]
117 pub fn trait_borrow(_: &Drop) {
118 }
119
120 // CHECK: @trait_box({}* noalias nonnull align 1{{( %0)?}}, [3 x [[USIZE]]]* noalias readonly align {{.*}} dereferenceable({{.*}}){{( %1)?}})
121 #[no_mangle]
122 pub fn trait_box(_: Box<Drop>) {
123 }
124
125 // CHECK: { i8*, i8* } @trait_option(i8* noalias align 1 %x.0, i8* %x.1)
126 #[no_mangle]
127 pub fn trait_option(x: Option<Box<Drop>>) -> Option<Box<Drop>> {
128   x
129 }
130
131 // CHECK: { [0 x i16]*, [[USIZE]] } @return_slice([0 x i16]* noalias nonnull readonly align 2 %x.0, [[USIZE]] %x.1)
132 #[no_mangle]
133 pub fn return_slice(x: &[u16]) -> &[u16] {
134   x
135 }
136
137 // CHECK: { i16, i16 } @enum_id_1(i16 %x.0, i16 %x.1)
138 #[no_mangle]
139 pub fn enum_id_1(x: Option<Result<u16, u16>>) -> Option<Result<u16, u16>> {
140   x
141 }
142
143 // CHECK: { i8, i8 } @enum_id_2(i1 zeroext %x.0, i8 %x.1)
144 #[no_mangle]
145 pub fn enum_id_2(x: Option<u8>) -> Option<u8> {
146   x
147 }
148
149 // CHECK: noalias i8* @allocator()
150 #[no_mangle]
151 #[rustc_allocator]
152 pub fn allocator() -> *const i8 {
153   std::ptr::null()
154 }