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