1 // compile-flags: -O -C no-prepopulate-passes
2 // ignore-tidy-linelength
3 // min-system-llvm-version: 12.0
6 #![feature(rustc_attrs)]
12 pub struct UnsafeInner {
13 _field: std::cell::UnsafeCell<i16>,
16 // CHECK: zeroext i1 @boolean(i1 zeroext %x)
18 pub fn boolean(x: bool) -> bool {
22 // CHECK: @readonly_borrow(i32* noalias readonly align 4 dereferenceable(4) %_1)
23 // FIXME #25759 This should also have `nocapture`
25 pub fn readonly_borrow(_: &i32) {
28 // CHECK: @static_borrow(i32* noalias readonly align 4 dereferenceable(4) %_1)
29 // static borrow may be captured
31 pub fn static_borrow(_: &'static i32) {
34 // CHECK: @named_borrow(i32* noalias readonly align 4 dereferenceable(4) %_1)
35 // borrow with named lifetime may be captured
37 pub fn named_borrow<'r>(_: &'r i32) {
40 // CHECK: @unsafe_borrow(i16* align 2 dereferenceable(2) %_1)
41 // unsafe interior means this isn't actually readonly and there may be aliases ...
43 pub fn unsafe_borrow(_: &UnsafeInner) {
46 // CHECK: @mutable_unsafe_borrow(i16* noalias align 2 dereferenceable(2) %_1)
47 // ... unless this is a mutable borrow, those never alias
49 pub fn mutable_unsafe_borrow(_: &mut UnsafeInner) {
52 // CHECK: @mutable_borrow(i32* noalias align 4 dereferenceable(4) %_1)
53 // FIXME #25759 This should also have `nocapture`
55 pub fn mutable_borrow(_: &mut i32) {
58 // CHECK: @indirect_struct(%S* noalias nocapture dereferenceable(32) %_1)
60 pub fn indirect_struct(_: S) {
63 // CHECK: @borrowed_struct(%S* noalias readonly align 4 dereferenceable(32) %_1)
64 // FIXME #25759 This should also have `nocapture`
66 pub fn borrowed_struct(_: &S) {
69 // `Box` can get deallocated during execution of the function, so it should
70 // not get `dereferenceable`.
71 // CHECK: noalias nonnull align 4 i32* @_box(i32* noalias nonnull align 4 %x)
73 pub fn _box(x: Box<i32>) -> Box<i32> {
77 // CHECK: @struct_return(%S* noalias nocapture sret(%S) dereferenceable(32){{( %0)?}})
79 pub fn struct_return() -> S {
81 _field: [0, 0, 0, 0, 0, 0, 0, 0]
85 // Hack to get the correct size for the length part in slices
86 // CHECK: @helper([[USIZE:i[0-9]+]] %_1)
88 pub fn helper(_: usize) {
91 // CHECK: @slice([0 x i8]* noalias nonnull readonly align 1 %_1.0, [[USIZE]] %_1.1)
92 // FIXME #25759 This should also have `nocapture`
94 pub fn slice(_: &[u8]) {
97 // CHECK: @mutable_slice([0 x i8]* noalias nonnull align 1 %_1.0, [[USIZE]] %_1.1)
98 // FIXME #25759 This should also have `nocapture`
100 pub fn mutable_slice(_: &mut [u8]) {
103 // CHECK: @unsafe_slice([0 x i16]* nonnull align 2 %_1.0, [[USIZE]] %_1.1)
104 // unsafe interior means this isn't actually readonly and there may be aliases ...
106 pub fn unsafe_slice(_: &[UnsafeInner]) {
109 // CHECK: @str([0 x i8]* noalias nonnull readonly align 1 %_1.0, [[USIZE]] %_1.1)
110 // FIXME #25759 This should also have `nocapture`
112 pub fn str(_: &[u8]) {
115 // CHECK: @trait_borrow({}* nonnull align 1 %_1.0, [3 x [[USIZE]]]* noalias readonly align {{.*}} dereferenceable({{.*}}) %_1.1)
116 // FIXME #25759 This should also have `nocapture`
118 pub fn trait_borrow(_: &Drop) {
121 // CHECK: @trait_box({}* noalias nonnull align 1{{( %0)?}}, [3 x [[USIZE]]]* noalias readonly align {{.*}} dereferenceable({{.*}}){{( %1)?}})
123 pub fn trait_box(_: Box<Drop>) {
126 // CHECK: { i8*, i8* } @trait_option(i8* noalias align 1 %x.0, i8* %x.1)
128 pub fn trait_option(x: Option<Box<Drop>>) -> Option<Box<Drop>> {
132 // CHECK: { [0 x i16]*, [[USIZE]] } @return_slice([0 x i16]* noalias nonnull readonly align 2 %x.0, [[USIZE]] %x.1)
134 pub fn return_slice(x: &[u16]) -> &[u16] {
138 // CHECK: { i16, i16 } @enum_id_1(i16 %x.0, i16 %x.1)
140 pub fn enum_id_1(x: Option<Result<u16, u16>>) -> Option<Result<u16, u16>> {
144 // CHECK: { i8, i8 } @enum_id_2(i1 zeroext %x.0, i8 %x.1)
146 pub fn enum_id_2(x: Option<u8>) -> Option<u8> {
150 // CHECK: noalias i8* @allocator()
153 pub fn allocator() -> *const i8 {