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 align 4 dereferenceable(4) %arg0)
32 // FIXME #25759 This should also have `nocapture`
34 pub fn readonly_borrow(_: &i32) {
37 // CHECK: @static_borrow(i32* noalias readonly align 4 dereferenceable(4) %arg0)
38 // static borrow may be captured
40 pub fn static_borrow(_: &'static i32) {
43 // CHECK: @named_borrow(i32* noalias readonly align 4 dereferenceable(4) %arg0)
44 // borrow with named lifetime may be captured
46 pub fn named_borrow<'r>(_: &'r i32) {
49 // CHECK: @unsafe_borrow(i16* align 2 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* align 2 dereferenceable(2) %arg0)
56 // ... unless this is a mutable borrow, those never alias
58 pub fn mutable_unsafe_borrow(_: &mut UnsafeInner) {
61 // CHECK: @mutable_borrow(i32* align 4 dereferenceable(4) %arg0)
62 // FIXME #25759 This should also have `nocapture`
64 pub fn mutable_borrow(_: &mut i32) {
67 // CHECK: @indirect_struct(%S* noalias nocapture dereferenceable(32) %arg0)
69 pub fn indirect_struct(_: S) {
72 // CHECK: @borrowed_struct(%S* noalias readonly align 4 dereferenceable(32) %arg0)
73 // FIXME #25759 This should also have `nocapture`
75 pub fn borrowed_struct(_: &S) {
78 // CHECK: noalias align 4 dereferenceable(4) i32* @_box(i32* noalias align 4 dereferenceable(4) %x)
80 pub fn _box(x: Box<i32>) -> Box<i32> {
84 // CHECK: @struct_return(%S* noalias nocapture sret dereferenceable(32))
86 pub fn struct_return() -> S {
88 _field: [0, 0, 0, 0, 0, 0, 0, 0]
92 // Hack to get the correct size for the length part in slices
93 // CHECK: @helper([[USIZE:i[0-9]+]] %arg0)
95 pub fn helper(_: usize) {
98 // CHECK: @slice([0 x i8]* noalias nonnull readonly align 1 %arg0.0, [[USIZE]] %arg0.1)
99 // FIXME #25759 This should also have `nocapture`
101 pub fn slice(_: &[u8]) {
104 // CHECK: @mutable_slice([0 x i8]* nonnull align 1 %arg0.0, [[USIZE]] %arg0.1)
105 // FIXME #25759 This should also have `nocapture`
107 pub fn mutable_slice(_: &mut [u8]) {
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 ...
113 pub fn unsafe_slice(_: &[UnsafeInner]) {
116 // CHECK: @str([0 x i8]* noalias nonnull readonly align 1 %arg0.0, [[USIZE]] %arg0.1)
117 // FIXME #25759 This should also have `nocapture`
119 pub fn str(_: &[u8]) {
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`
125 pub fn trait_borrow(_: &Drop) {
128 // CHECK: @trait_box({}* noalias nonnull align 1, [3 x [[USIZE]]]* noalias readonly align {{.*}} dereferenceable({{.*}}))
130 pub fn trait_box(_: Box<Drop>) {
133 // CHECK: { i8*, i8* } @trait_option(i8* noalias align 1 %x.0, i8* %x.1)
135 pub fn trait_option(x: Option<Box<Drop>>) -> Option<Box<Drop>> {
139 // CHECK: { [0 x i16]*, [[USIZE]] } @return_slice([0 x i16]* noalias nonnull readonly align 2 %x.0, [[USIZE]] %x.1)
141 pub fn return_slice(x: &[u16]) -> &[u16] {
145 // CHECK: { i16, i16 } @enum_id_1(i16 %x.0, i16 %x.1)
147 pub fn enum_id_1(x: Option<Result<u16, u16>>) -> Option<Result<u16, u16>> {
151 // CHECK: { i8, i8 } @enum_id_2(i1 zeroext %x.0, i8 %x.1)
153 pub fn enum_id_2(x: Option<u8>) -> Option<u8> {
157 // CHECK: noalias i8* @allocator()
160 pub fn allocator() -> *const i8 {