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