]>
git.proxmox.com Git - rustc.git/blob - tests/codegen/function-arguments.rs
1 // compile-flags: -O -C no-prepopulate-passes
5 use std
::mem
::MaybeUninit
;
6 use std
::num
::NonZeroU64
;
7 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: noundef i64 @int(i64 noundef %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: noundef i64 @option_nonzero_int(i64 noundef %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: @option_borrow({{i32\*|ptr}} noalias noundef readonly align 4 dereferenceable_or_null(4) %x)
143 pub fn option_borrow(x
: Option
<&i32>) {
146 // CHECK: @option_borrow_mut({{i32\*|ptr}} noalias noundef align 4 dereferenceable_or_null(4) %x)
148 pub fn option_borrow_mut(x
: Option
<&mut i32>) {
151 // CHECK: @raw_struct({{%S\*|ptr}} noundef %_1)
153 pub fn raw_struct(_
: *const S
) {
156 // CHECK: @raw_option_nonnull_struct({{i32\*|ptr}} noundef %_1)
158 pub fn raw_option_nonnull_struct(_
: Option
<NonNull
<S
>>) {
162 // `Box` can get deallocated during execution of the function, so it should
163 // not get `dereferenceable`.
164 // CHECK: noundef nonnull align 4 {{i32\*|ptr}} @_box({{i32\*|ptr}} noalias noundef nonnull align 4 %x)
166 pub fn _box(x
: Box
<i32>) -> Box
<i32> {
170 // CHECK: @struct_return({{%S\*|ptr}} noalias nocapture noundef sret(%S) dereferenceable(32){{( %0)?}})
172 pub fn struct_return() -> S
{
174 _field
: [0, 0, 0, 0, 0, 0, 0, 0]
178 // Hack to get the correct size for the length part in slices
179 // CHECK: @helper([[USIZE:i[0-9]+]] noundef %_1)
181 pub fn helper(_
: usize) {
184 // CHECK: @slice({{\[0 x i8\]\*|ptr}} noalias noundef nonnull readonly align 1 %_1.0, [[USIZE]] noundef %_1.1)
185 // FIXME #25759 This should also have `nocapture`
187 pub fn slice(_
: &[u8]) {
190 // CHECK: @mutable_slice({{\[0 x i8\]\*|ptr}} noalias noundef nonnull align 1 %_1.0, [[USIZE]] noundef %_1.1)
191 // FIXME #25759 This should also have `nocapture`
193 pub fn mutable_slice(_
: &mut [u8]) {
196 // CHECK: @unsafe_slice({{\[0 x i16\]\*|ptr}} noundef nonnull align 2 %_1.0, [[USIZE]] noundef %_1.1)
197 // unsafe interior means this isn't actually readonly and there may be aliases ...
199 pub fn unsafe_slice(_
: &[UnsafeInner
]) {
202 // CHECK: @raw_slice({{\[0 x i8\]\*|ptr}} noundef %_1.0, [[USIZE]] noundef %_1.1)
204 pub fn raw_slice(_
: *const [u8]) {
207 // CHECK: @str({{\[0 x i8\]\*|ptr}} noalias noundef nonnull readonly align 1 %_1.0, [[USIZE]] noundef %_1.1)
208 // FIXME #25759 This should also have `nocapture`
210 pub fn str(_
: &[u8]) {
213 // CHECK: @trait_borrow({{\{\}\*|ptr}} noundef nonnull align 1 %_1.0, {{.+}} noalias noundef readonly align {{.*}} dereferenceable({{.*}}) %_1.1)
214 // FIXME #25759 This should also have `nocapture`
216 pub fn trait_borrow(_
: &dyn Drop
) {
219 // CHECK: @option_trait_borrow({{i8\*|ptr}} noundef align 1 %x.0, {{i8\*|ptr}} %x.1)
221 pub fn option_trait_borrow(x
: Option
<&dyn Drop
>) {
224 // CHECK: @option_trait_borrow_mut({{i8\*|ptr}} noundef align 1 %x.0, {{i8\*|ptr}} %x.1)
226 pub fn option_trait_borrow_mut(x
: Option
<&mut dyn Drop
>) {
229 // CHECK: @trait_raw({{\{\}\*|ptr}} noundef %_1.0, {{.+}} noalias noundef readonly align {{.*}} dereferenceable({{.*}}) %_1.1)
231 pub fn trait_raw(_
: *const dyn Drop
) {
234 // CHECK: @trait_box({{\{\}\*|ptr}} noalias noundef nonnull align 1{{( %0)?}}, {{.+}} noalias noundef readonly align {{.*}} dereferenceable({{.*}}){{( %1)?}})
236 pub fn trait_box(_
: Box
<dyn Drop
>) {
239 // CHECK: { {{i8\*|ptr}}, {{i8\*|ptr}} } @trait_option({{i8\*|ptr}} noalias noundef align 1 %x.0, {{i8\*|ptr}} %x.1)
241 pub fn trait_option(x
: Option
<Box
<dyn Drop
>>) -> Option
<Box
<dyn Drop
>> {
245 // CHECK: { {{\[0 x i16\]\*|ptr}}, [[USIZE]] } @return_slice({{\[0 x i16\]\*|ptr}} noalias noundef nonnull readonly align 2 %x.0, [[USIZE]] noundef %x.1)
247 pub fn return_slice(x
: &[u16]) -> &[u16] {
251 // CHECK: { i16, i16 } @enum_id_1(i16 noundef %x.0, i16 %x.1)
253 pub fn enum_id_1(x
: Option
<Result
<u16, u16>>) -> Option
<Result
<u16, u16>> {
257 // CHECK: { i8, i8 } @enum_id_2(i1 noundef zeroext %x.0, i8 %x.1)
259 pub fn enum_id_2(x
: Option
<u8>) -> Option
<u8> {