1 // compile-flags: -O -C no-prepopulate-passes
4 #![feature(rustc_attrs)]
10 pub struct UnsafeInner {
11 _field: std::cell::UnsafeCell<i16>,
14 // CHECK: zeroext i1 @boolean(i1 zeroext %x)
16 pub fn boolean(x: bool) -> bool {
20 // CHECK: @readonly_borrow(i32* noalias readonly align 4 dereferenceable(4) %_1)
21 // FIXME #25759 This should also have `nocapture`
23 pub fn readonly_borrow(_: &i32) {
26 // CHECK: @static_borrow(i32* noalias readonly align 4 dereferenceable(4) %_1)
27 // static borrow may be captured
29 pub fn static_borrow(_: &'static i32) {
32 // CHECK: @named_borrow(i32* noalias readonly align 4 dereferenceable(4) %_1)
33 // borrow with named lifetime may be captured
35 pub fn named_borrow<'r>(_: &'r i32) {
38 // CHECK: @unsafe_borrow(i16* align 2 dereferenceable(2) %_1)
39 // unsafe interior means this isn't actually readonly and there may be aliases ...
41 pub fn unsafe_borrow(_: &UnsafeInner) {
44 // CHECK: @mutable_unsafe_borrow(i16* noalias align 2 dereferenceable(2) %_1)
45 // ... unless this is a mutable borrow, those never alias
47 pub fn mutable_unsafe_borrow(_: &mut UnsafeInner) {
50 // CHECK: @mutable_borrow(i32* noalias align 4 dereferenceable(4) %_1)
51 // FIXME #25759 This should also have `nocapture`
53 pub fn mutable_borrow(_: &mut i32) {
56 // CHECK: @indirect_struct(%S* noalias nocapture dereferenceable(32) %_1)
58 pub fn indirect_struct(_: S) {
61 // CHECK: @borrowed_struct(%S* noalias readonly align 4 dereferenceable(32) %_1)
62 // FIXME #25759 This should also have `nocapture`
64 pub fn borrowed_struct(_: &S) {
67 // `Box` can get deallocated during execution of the function, so it should
68 // not get `dereferenceable`.
69 // CHECK: noalias nonnull align 4 i32* @_box(i32* noalias nonnull align 4 %x)
71 pub fn _box(x: Box<i32>) -> Box<i32> {
75 // CHECK: @struct_return(%S* noalias nocapture sret(%S) dereferenceable(32){{( %0)?}})
77 pub fn struct_return() -> S {
79 _field: [0, 0, 0, 0, 0, 0, 0, 0]
83 // Hack to get the correct size for the length part in slices
84 // CHECK: @helper([[USIZE:i[0-9]+]] %_1)
86 pub fn helper(_: usize) {
89 // CHECK: @slice([0 x i8]* noalias nonnull readonly align 1 %_1.0, [[USIZE]] %_1.1)
90 // FIXME #25759 This should also have `nocapture`
92 pub fn slice(_: &[u8]) {
95 // CHECK: @mutable_slice([0 x i8]* noalias nonnull align 1 %_1.0, [[USIZE]] %_1.1)
96 // FIXME #25759 This should also have `nocapture`
98 pub fn mutable_slice(_: &mut [u8]) {
101 // CHECK: @unsafe_slice([0 x i16]* nonnull align 2 %_1.0, [[USIZE]] %_1.1)
102 // unsafe interior means this isn't actually readonly and there may be aliases ...
104 pub fn unsafe_slice(_: &[UnsafeInner]) {
107 // CHECK: @str([0 x i8]* noalias nonnull readonly align 1 %_1.0, [[USIZE]] %_1.1)
108 // FIXME #25759 This should also have `nocapture`
110 pub fn str(_: &[u8]) {
113 // CHECK: @trait_borrow({}* nonnull align 1 %_1.0, [3 x [[USIZE]]]* noalias readonly align {{.*}} dereferenceable({{.*}}) %_1.1)
114 // FIXME #25759 This should also have `nocapture`
116 pub fn trait_borrow(_: &Drop) {
119 // CHECK: @trait_box({}* noalias nonnull align 1{{( %0)?}}, [3 x [[USIZE]]]* noalias readonly align {{.*}} dereferenceable({{.*}}){{( %1)?}})
121 pub fn trait_box(_: Box<Drop>) {
124 // CHECK: { i8*, i8* } @trait_option(i8* noalias align 1 %x.0, i8* %x.1)
126 pub fn trait_option(x: Option<Box<Drop>>) -> Option<Box<Drop>> {
130 // CHECK: { [0 x i16]*, [[USIZE]] } @return_slice([0 x i16]* noalias nonnull readonly align 2 %x.0, [[USIZE]] %x.1)
132 pub fn return_slice(x: &[u16]) -> &[u16] {
136 // CHECK: { i16, i16 } @enum_id_1(i16 %x.0, i16 %x.1)
138 pub fn enum_id_1(x: Option<Result<u16, u16>>) -> Option<Result<u16, u16>> {
142 // CHECK: { i8, i8 } @enum_id_2(i1 zeroext %x.0, i8 %x.1)
144 pub fn enum_id_2(x: Option<u8>) -> Option<u8> {
148 // CHECK: noalias i8* @allocator()
151 pub fn allocator() -> *const i8 {