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
13 // min-llvm-version 6.0
15 #![crate_type = "lib"]
16 #![feature(custom_attribute)]
22 pub struct UnsafeInner {
23 _field: std::cell::UnsafeCell<i16>,
26 // CHECK: zeroext i1 @boolean(i1 zeroext %x)
28 pub fn boolean(x: bool) -> bool {
32 // CHECK: @readonly_borrow(i32* noalias readonly dereferenceable(4) %arg0)
33 // FIXME #25759 This should also have `nocapture`
35 pub fn readonly_borrow(_: &i32) {
38 // CHECK: @static_borrow(i32* noalias readonly dereferenceable(4) %arg0)
39 // static borrow may be captured
41 pub fn static_borrow(_: &'static i32) {
44 // CHECK: @named_borrow(i32* noalias readonly dereferenceable(4) %arg0)
45 // borrow with named lifetime may be captured
47 pub fn named_borrow<'r>(_: &'r i32) {
50 // CHECK: @unsafe_borrow(i16* dereferenceable(2) %arg0)
51 // unsafe interior means this isn't actually readonly and there may be aliases ...
53 pub fn unsafe_borrow(_: &UnsafeInner) {
56 // CHECK: @mutable_unsafe_borrow(i16* dereferenceable(2) %arg0)
57 // ... unless this is a mutable borrow, those never alias
59 pub fn mutable_unsafe_borrow(_: &mut UnsafeInner) {
62 // CHECK: @mutable_borrow(i32* dereferenceable(4) %arg0)
63 // FIXME #25759 This should also have `nocapture`
65 pub fn mutable_borrow(_: &mut i32) {
68 // CHECK: @indirect_struct(%S* noalias nocapture dereferenceable(32) %arg0)
70 pub fn indirect_struct(_: S) {
73 // CHECK: @borrowed_struct(%S* noalias readonly dereferenceable(32) %arg0)
74 // FIXME #25759 This should also have `nocapture`
76 pub fn borrowed_struct(_: &S) {
79 // CHECK: noalias align 4 dereferenceable(4) i32* @_box(i32* noalias dereferenceable(4) %x)
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 {
89 _field: [0, 0, 0, 0, 0, 0, 0, 0]
93 // Hack to get the correct size for the length part in slices
94 // CHECK: @helper([[USIZE:i[0-9]+]] %arg0)
96 pub fn helper(_: usize) {
99 // CHECK: @slice([0 x i8]* noalias nonnull readonly %arg0.0, [[USIZE]] %arg0.1)
100 // FIXME #25759 This should also have `nocapture`
102 pub fn slice(_: &[u8]) {
105 // CHECK: @mutable_slice([0 x i8]* nonnull %arg0.0, [[USIZE]] %arg0.1)
106 // FIXME #25759 This should also have `nocapture`
108 pub fn mutable_slice(_: &mut [u8]) {
111 // CHECK: @unsafe_slice([0 x i16]* nonnull %arg0.0, [[USIZE]] %arg0.1)
112 // unsafe interior means this isn't actually readonly and there may be aliases ...
114 pub fn unsafe_slice(_: &[UnsafeInner]) {
117 // CHECK: @str([0 x i8]* noalias nonnull readonly %arg0.0, [[USIZE]] %arg0.1)
118 // FIXME #25759 This should also have `nocapture`
120 pub fn str(_: &[u8]) {
123 // CHECK: @trait_borrow({}* nonnull %arg0.0, [3 x [[USIZE]]]* noalias readonly dereferenceable({{.*}}) %arg0.1)
124 // FIXME #25759 This should also have `nocapture`
126 pub fn trait_borrow(_: &Drop) {
129 // CHECK: @trait_box({}* noalias nonnull, [3 x [[USIZE]]]* noalias readonly dereferenceable({{.*}}))
131 pub fn trait_box(_: Box<Drop>) {
134 // CHECK: { i8*, i8* } @trait_option(i8* noalias %x.0, i8* %x.1)
136 pub fn trait_option(x: Option<Box<Drop>>) -> Option<Box<Drop>> {
140 // CHECK: { [0 x i16]*, [[USIZE]] } @return_slice([0 x i16]* noalias nonnull readonly %x.0, [[USIZE]] %x.1)
142 pub fn return_slice(x: &[u16]) -> &[u16] {
146 // CHECK: { i16, i16 } @enum_id_1(i16 %x.0, i16 %x.1)
148 pub fn enum_id_1(x: Option<Result<u16, u16>>) -> Option<Result<u16, u16>> {
152 // CHECK: { i8, i8 } @enum_id_2(i1 zeroext %x.0, i8 %x.1)
154 pub fn enum_id_2(x: Option<u8>) -> Option<u8> {
158 // CHECK: noalias i8* @allocator()
161 pub fn allocator() -> *const i8 {