]>
git.proxmox.com Git - rustc.git/blob - src/test/codegen/function-arguments.rs
1 // compile-flags: -C no-prepopulate-passes
2 // ignore-tidy-linelength
5 #![feature(rustc_attrs)]
11 pub struct UnsafeInner
{
12 _field
: std
::cell
::UnsafeCell
<i16>,
15 // CHECK: zeroext i1 @boolean(i1 zeroext %x)
17 pub fn boolean(x
: bool
) -> bool
{
21 // CHECK: @readonly_borrow(i32* noalias readonly align 4 dereferenceable(4) %arg0)
22 // FIXME #25759 This should also have `nocapture`
24 pub fn readonly_borrow(_
: &i32) {
27 // CHECK: @static_borrow(i32* noalias readonly align 4 dereferenceable(4) %arg0)
28 // static borrow may be captured
30 pub fn static_borrow(_
: &'
static i32) {
33 // CHECK: @named_borrow(i32* noalias readonly align 4 dereferenceable(4) %arg0)
34 // borrow with named lifetime may be captured
36 pub fn named_borrow
<'r
>(_
: &'r
i32) {
39 // CHECK: @unsafe_borrow(i16* align 2 dereferenceable(2) %arg0)
40 // unsafe interior means this isn't actually readonly and there may be aliases ...
42 pub fn unsafe_borrow(_
: &UnsafeInner
) {
45 // CHECK: @mutable_unsafe_borrow(i16* align 2 dereferenceable(2) %arg0)
46 // ... unless this is a mutable borrow, those never alias
48 pub fn mutable_unsafe_borrow(_
: &mut UnsafeInner
) {
51 // CHECK: @mutable_borrow(i32* align 4 dereferenceable(4) %arg0)
52 // FIXME #25759 This should also have `nocapture`
54 pub fn mutable_borrow(_
: &mut i32) {
57 // CHECK: @indirect_struct(%S* noalias nocapture dereferenceable(32) %arg0)
59 pub fn indirect_struct(_
: S
) {
62 // CHECK: @borrowed_struct(%S* noalias readonly align 4 dereferenceable(32) %arg0)
63 // FIXME #25759 This should also have `nocapture`
65 pub fn borrowed_struct(_
: &S
) {
68 // CHECK: noalias align 4 dereferenceable(4) i32* @_box(i32* noalias align 4 dereferenceable(4) %x)
70 pub fn _box(x
: Box
<i32>) -> Box
<i32> {
74 // CHECK: @struct_return(%S* noalias nocapture sret dereferenceable(32))
76 pub fn struct_return() -> S
{
78 _field
: [0, 0, 0, 0, 0, 0, 0, 0]
82 // Hack to get the correct size for the length part in slices
83 // CHECK: @helper([[USIZE:i[0-9]+]] %arg0)
85 pub fn helper(_
: usize) {
88 // CHECK: @slice([0 x i8]* noalias nonnull readonly align 1 %arg0.0, [[USIZE]] %arg0.1)
89 // FIXME #25759 This should also have `nocapture`
91 pub fn slice(_
: &[u8]) {
94 // CHECK: @mutable_slice([0 x i8]* nonnull align 1 %arg0.0, [[USIZE]] %arg0.1)
95 // FIXME #25759 This should also have `nocapture`
97 pub fn mutable_slice(_
: &mut [u8]) {
100 // CHECK: @unsafe_slice([0 x i16]* nonnull align 2 %arg0.0, [[USIZE]] %arg0.1)
101 // unsafe interior means this isn't actually readonly and there may be aliases ...
103 pub fn unsafe_slice(_
: &[UnsafeInner
]) {
106 // CHECK: @str([0 x i8]* noalias nonnull readonly align 1 %arg0.0, [[USIZE]] %arg0.1)
107 // FIXME #25759 This should also have `nocapture`
109 pub fn str(_
: &[u8]) {
112 // CHECK: @trait_borrow({}* nonnull align 1 %arg0.0, [3 x [[USIZE]]]* noalias readonly align {{.*}} dereferenceable({{.*}}) %arg0.1)
113 // FIXME #25759 This should also have `nocapture`
115 pub fn trait_borrow(_
: &Drop
) {
118 // CHECK: @trait_box({}* noalias nonnull align 1, [3 x [[USIZE]]]* noalias readonly align {{.*}} dereferenceable({{.*}}))
120 pub fn trait_box(_
: Box
<Drop
>) {
123 // CHECK: { i8*, i8* } @trait_option(i8* noalias align 1 %x.0, i8* %x.1)
125 pub fn trait_option(x
: Option
<Box
<Drop
>>) -> Option
<Box
<Drop
>> {
129 // CHECK: { [0 x i16]*, [[USIZE]] } @return_slice([0 x i16]* noalias nonnull readonly align 2 %x.0, [[USIZE]] %x.1)
131 pub fn return_slice(x
: &[u16]) -> &[u16] {
135 // CHECK: { i16, i16 } @enum_id_1(i16 %x.0, i16 %x.1)
137 pub fn enum_id_1(x
: Option
<Result
<u16, u16>>) -> Option
<Result
<u16, u16>> {
141 // CHECK: { i8, i8 } @enum_id_2(i1 zeroext %x.0, i8 %x.1)
143 pub fn enum_id_2(x
: Option
<u8>) -> Option
<u8> {
147 // CHECK: noalias i8* @allocator()
150 pub fn allocator() -> *const i8 {