]>
git.proxmox.com Git - rustc.git/blob - src/test/codegen/function-arguments.rs
1 // compile-flags: -O -C no-prepopulate-passes
4 #![feature(rustc_attrs)]
6 use std
::mem
::MaybeUninit
;
7 use std
::num
::NonZeroU64
;
8 use std
::marker
::PhantomPinned
;
14 pub struct UnsafeInner
{
15 _field
: std
::cell
::UnsafeCell
<i16>,
20 _marker
: PhantomPinned
,
28 // CHECK: noundef zeroext i1 @boolean(i1 noundef zeroext %x)
30 pub fn boolean(x
: bool
) -> bool
{
34 // CHECK: i8 @maybeuninit_boolean(i8 %x)
36 pub fn maybeuninit_boolean(x
: MaybeUninit
<bool
>) -> MaybeUninit
<bool
> {
40 // CHECK: noundef zeroext i1 @enum_bool(i1 noundef zeroext %x)
42 pub fn enum_bool(x
: MyBool
) -> MyBool
{
46 // CHECK: i8 @maybeuninit_enum_bool(i8 %x)
48 pub fn maybeuninit_enum_bool(x
: MaybeUninit
<MyBool
>) -> MaybeUninit
<MyBool
> {
52 // CHECK: noundef i32 @char(i32 noundef %x)
54 pub fn char(x
: char) -> char {
58 // CHECK: i32 @maybeuninit_char(i32 %x)
60 pub fn maybeuninit_char(x
: MaybeUninit
<char>) -> MaybeUninit
<char> {
64 // CHECK: i64 @int(i64 %x)
66 pub fn int(x
: u64) -> u64 {
70 // CHECK: noundef i64 @nonzero_int(i64 noundef %x)
72 pub fn nonzero_int(x
: NonZeroU64
) -> NonZeroU64
{
76 // CHECK: i64 @option_nonzero_int(i64 %x)
78 pub fn option_nonzero_int(x
: Option
<NonZeroU64
>) -> Option
<NonZeroU64
> {
82 // CHECK: @readonly_borrow({{i32\*|ptr}} noalias noundef readonly align 4 dereferenceable(4) %_1)
83 // FIXME #25759 This should also have `nocapture`
85 pub fn readonly_borrow(_
: &i32) {
88 // CHECK: @static_borrow({{i32\*|ptr}} noalias noundef readonly align 4 dereferenceable(4) %_1)
89 // static borrow may be captured
91 pub fn static_borrow(_
: &'
static i32) {
94 // CHECK: @named_borrow({{i32\*|ptr}} noalias noundef readonly align 4 dereferenceable(4) %_1)
95 // borrow with named lifetime may be captured
97 pub fn named_borrow
<'r
>(_
: &'r
i32) {
100 // CHECK: @unsafe_borrow({{i16\*|ptr}} noundef nonnull align 2 %_1)
101 // unsafe interior means this isn't actually readonly and there may be aliases ...
103 pub fn unsafe_borrow(_
: &UnsafeInner
) {
106 // CHECK: @mutable_unsafe_borrow({{i16\*|ptr}} noalias noundef align 2 dereferenceable(2) %_1)
107 // ... unless this is a mutable borrow, those never alias
109 pub fn mutable_unsafe_borrow(_
: &mut UnsafeInner
) {
112 // CHECK: @mutable_borrow({{i32\*|ptr}} noalias noundef align 4 dereferenceable(4) %_1)
113 // FIXME #25759 This should also have `nocapture`
115 pub fn mutable_borrow(_
: &mut i32) {
119 // CHECK: @mutable_notunpin_borrow({{i32\*|ptr}} noundef align 4 dereferenceable(4) %_1)
120 // This one is *not* `noalias` because it might be self-referential.
121 pub fn mutable_notunpin_borrow(_
: &mut NotUnpin
) {
124 // CHECK: @notunpin_borrow({{i32\*|ptr}} noalias noundef readonly align 4 dereferenceable(4) %_1)
125 // But `&NotUnpin` behaves perfectly normal.
127 pub fn notunpin_borrow(_
: &NotUnpin
) {
130 // CHECK: @indirect_struct({{%S\*|ptr}} noalias nocapture noundef readonly dereferenceable(32) %_1)
132 pub fn indirect_struct(_
: S
) {
135 // CHECK: @borrowed_struct({{%S\*|ptr}} noalias noundef readonly align 4 dereferenceable(32) %_1)
136 // FIXME #25759 This should also have `nocapture`
138 pub fn borrowed_struct(_
: &S
) {
141 // CHECK: @raw_struct({{%S\*|ptr}} %_1)
143 pub fn raw_struct(_
: *const S
) {
146 // `Box` can get deallocated during execution of the function, so it should
147 // not get `dereferenceable`.
148 // CHECK: noalias noundef nonnull align 4 {{i32\*|ptr}} @_box({{i32\*|ptr}} noalias noundef nonnull align 4 %x)
150 pub fn _box(x
: Box
<i32>) -> Box
<i32> {
154 // CHECK: @struct_return({{%S\*|ptr}} noalias nocapture noundef sret(%S) dereferenceable(32){{( %0)?}})
156 pub fn struct_return() -> S
{
158 _field
: [0, 0, 0, 0, 0, 0, 0, 0]
162 // Hack to get the correct size for the length part in slices
163 // CHECK: @helper([[USIZE:i[0-9]+]] %_1)
165 pub fn helper(_
: usize) {
168 // CHECK: @slice({{\[0 x i8\]\*|ptr}} noalias noundef nonnull readonly align 1 %_1.0, [[USIZE]] %_1.1)
169 // FIXME #25759 This should also have `nocapture`
171 pub fn slice(_
: &[u8]) {
174 // CHECK: @mutable_slice({{\[0 x i8\]\*|ptr}} noalias noundef nonnull align 1 %_1.0, [[USIZE]] %_1.1)
175 // FIXME #25759 This should also have `nocapture`
177 pub fn mutable_slice(_
: &mut [u8]) {
180 // CHECK: @unsafe_slice({{\[0 x i16\]\*|ptr}} noundef nonnull align 2 %_1.0, [[USIZE]] %_1.1)
181 // unsafe interior means this isn't actually readonly and there may be aliases ...
183 pub fn unsafe_slice(_
: &[UnsafeInner
]) {
186 // CHECK: @raw_slice({{\[0 x i8\]\*|ptr}} %_1.0, [[USIZE]] %_1.1)
188 pub fn raw_slice(_
: *const [u8]) {
191 // CHECK: @str({{\[0 x i8\]\*|ptr}} noalias noundef nonnull readonly align 1 %_1.0, [[USIZE]] %_1.1)
192 // FIXME #25759 This should also have `nocapture`
194 pub fn str(_
: &[u8]) {
197 // CHECK: @trait_borrow({{\{\}\*|ptr}} noundef nonnull align 1 %_1.0, {{.+}} noalias noundef readonly align {{.*}} dereferenceable({{.*}}) %_1.1)
198 // FIXME #25759 This should also have `nocapture`
200 pub fn trait_borrow(_
: &Drop
) {
203 // CHECK: @trait_raw({{\{\}\*|ptr}} %_1.0, {{.+}} noalias noundef readonly align {{.*}} dereferenceable({{.*}}) %_1.1)
205 pub fn trait_raw(_
: *const Drop
) {
208 // CHECK: @trait_box({{\{\}\*|ptr}} noalias noundef nonnull align 1{{( %0)?}}, {{.+}} noalias noundef readonly align {{.*}} dereferenceable({{.*}}){{( %1)?}})
210 pub fn trait_box(_
: Box
<Drop
>) {
213 // CHECK: { {{i8\*|ptr}}, {{i8\*|ptr}} } @trait_option({{i8\*|ptr}} noalias noundef align 1 %x.0, {{i8\*|ptr}} %x.1)
215 pub fn trait_option(x
: Option
<Box
<Drop
>>) -> Option
<Box
<Drop
>> {
219 // CHECK: { {{\[0 x i16\]\*|ptr}}, [[USIZE]] } @return_slice({{\[0 x i16\]\*|ptr}} noalias noundef nonnull readonly align 2 %x.0, [[USIZE]] %x.1)
221 pub fn return_slice(x
: &[u16]) -> &[u16] {
225 // CHECK: { i16, i16 } @enum_id_1(i16 noundef %x.0, i16 %x.1)
227 pub fn enum_id_1(x
: Option
<Result
<u16, u16>>) -> Option
<Result
<u16, u16>> {
231 // CHECK: { i8, i8 } @enum_id_2(i1 noundef zeroext %x.0, i8 %x.1)
233 pub fn enum_id_2(x
: Option
<u8>) -> Option
<u8> {