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