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