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.
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.
11 // compile-flags: -C no-prepopulate-passes
12 // ignore-tidy-linelength
14 #![crate_type = "lib"]
15 #![feature(custom_attribute)]
21 pub struct UnsafeInner {
22 _field: std::cell::UnsafeCell<i16>,
25 // CHECK: zeroext i1 @boolean(i1 zeroext %x)
27 pub fn boolean(x: bool) -> bool {
31 // CHECK: @readonly_borrow(i32* noalias readonly dereferenceable(4) %arg0)
32 // FIXME #25759 This should also have `nocapture`
34 pub fn readonly_borrow(_: &i32) {
37 // CHECK: @static_borrow(i32* noalias readonly dereferenceable(4) %arg0)
38 // static borrow may be captured
40 pub fn static_borrow(_: &'static i32) {
43 // CHECK: @named_borrow(i32* noalias readonly dereferenceable(4) %arg0)
44 // borrow with named lifetime may be captured
46 pub fn named_borrow<'r>(_: &'r i32) {
49 // CHECK: @unsafe_borrow(i16* dereferenceable(2) %arg0)
50 // unsafe interior means this isn't actually readonly and there may be aliases ...
52 pub fn unsafe_borrow(_: &UnsafeInner) {
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
59 pub fn mutable_unsafe_borrow(_: &mut UnsafeInner) {
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
66 pub fn mutable_borrow(_: &mut i32) {
69 // CHECK: @indirect_struct(%S* noalias nocapture dereferenceable(32) %arg0)
71 pub fn indirect_struct(_: S) {
74 // CHECK: @borrowed_struct(%S* noalias readonly dereferenceable(32) %arg0)
75 // FIXME #25759 This should also have `nocapture`
77 pub fn borrowed_struct(_: &S) {
80 // CHECK: noalias align 4 dereferenceable(4) i32* @_box(i32* noalias dereferenceable(4) %x)
82 pub fn _box(x: Box<i32>) -> Box<i32> {
86 // CHECK: @struct_return(%S* noalias nocapture sret dereferenceable(32))
88 pub fn struct_return() -> S {
90 _field: [0, 0, 0, 0, 0, 0, 0, 0]
94 // Hack to get the correct size for the length part in slices
95 // CHECK: @helper([[USIZE:i[0-9]+]] %arg0)
97 pub fn helper(_: usize) {
100 // CHECK: @slice([0 x i8]* noalias nonnull readonly %arg0.0, [[USIZE]] %arg0.1)
101 // FIXME #25759 This should also have `nocapture`
103 pub fn slice(_: &[u8]) {
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
110 pub fn mutable_slice(_: &mut [u8]) {
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 ...
116 pub fn unsafe_slice(_: &[UnsafeInner]) {
119 // CHECK: @str([0 x i8]* noalias nonnull readonly %arg0.0, [[USIZE]] %arg0.1)
120 // FIXME #25759 This should also have `nocapture`
122 pub fn str(_: &[u8]) {
125 // CHECK: @trait_borrow({}* nonnull %arg0.0, {}* noalias nonnull readonly %arg0.1)
126 // FIXME #25759 This should also have `nocapture`
128 pub fn trait_borrow(_: &Drop) {
131 // CHECK: @trait_box({}* noalias nonnull, {}* noalias nonnull readonly)
133 pub fn trait_box(_: Box<Drop>) {
136 // CHECK: { [0 x i16]*, [[USIZE]] } @return_slice([0 x i16]* noalias nonnull readonly %x.0, [[USIZE]] %x.1)
138 pub fn return_slice(x: &[u16]) -> &[u16] {
142 // CHECK: noalias i8* @allocator()
145 pub fn allocator() -> *const i8 {