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