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