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
13 #![crate_type = "lib"]
14 #![feature(custom_attribute)]
20 pub struct UnsafeInner {
21 _field: std::cell::UnsafeCell<i16>,
24 // CHECK: zeroext i1 @boolean(i1 zeroext)
26 pub fn boolean(x: bool) -> bool {
30 // CHECK: @readonly_borrow(i32* noalias readonly dereferenceable(4))
31 // FIXME #25759 This should also have `nocapture`
33 pub fn readonly_borrow(_: &i32) {
36 // CHECK: @static_borrow(i32* noalias readonly dereferenceable(4))
37 // static borrow may be captured
39 pub fn static_borrow(_: &'static i32) {
42 // CHECK: @named_borrow(i32* noalias readonly dereferenceable(4))
43 // borrow with named lifetime may be captured
45 pub fn named_borrow<'r>(_: &'r i32) {
48 // CHECK: @unsafe_borrow(%UnsafeInner* dereferenceable(2))
49 // unsafe interior means this isn't actually readonly and there may be aliases ...
51 pub fn unsafe_borrow(_: &UnsafeInner) {
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
58 pub fn mutable_unsafe_borrow(_: &mut UnsafeInner) {
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
65 pub fn mutable_borrow(_: &mut i32) {
68 // CHECK: @indirect_struct(%S* noalias nocapture dereferenceable(32))
70 pub fn indirect_struct(_: S) {
73 // CHECK: @borrowed_struct(%S* noalias readonly dereferenceable(32))
74 // FIXME #25759 This should also have `nocapture`
76 pub fn borrowed_struct(_: &S) {
79 // CHECK: noalias dereferenceable(4) i32* @_box(i32* noalias dereferenceable(4))
81 pub fn _box(x: Box<i32>) -> Box<i32> {
85 // CHECK: @struct_return(%S* noalias nocapture sret dereferenceable(32))
87 pub fn struct_return() -> S {
93 // Hack to get the correct size for the length part in slices
94 // CHECK: @helper([[USIZE:i[0-9]+]])
99 // CHECK: @slice(i8* noalias nonnull readonly, [[USIZE]])
100 // FIXME #25759 This should also have `nocapture`
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
109 fn mutable_slice(_: &mut [u8]) {
112 // CHECK: @unsafe_slice(%UnsafeInner* nonnull, [[USIZE]])
113 // unsafe interior means this isn't actually readonly and there may be aliases ...
115 pub fn unsafe_slice(_: &[UnsafeInner]) {
118 // CHECK: @str(i8* noalias nonnull readonly, [[USIZE]])
119 // FIXME #25759 This should also have `nocapture`
124 // CHECK: @trait_borrow({}* nonnull, {}* noalias nonnull readonly)
125 // FIXME #25759 This should also have `nocapture`
127 fn trait_borrow(_: &Drop) {
130 // CHECK: @trait_box({}* noalias nonnull, {}* noalias nonnull readonly)
132 fn trait_box(_: Box<Drop>) {
135 // CHECK: { i16*, [[USIZE]] } @return_slice(i16* noalias nonnull readonly, [[USIZE]])
137 fn return_slice(x: &[u16]) -> &[u16] {
141 // CHECK: noalias i8* @allocator()
144 pub fn allocator() -> *const i8 {