|
| 1 | +// Checks how `reg-struct-return` flag works with different calling conventions: |
| 2 | +// Return struct with 8/16/32/64 bit size will be converted into i8/i16/i32/i64 |
| 3 | +// (like abi_return_struct_as_int target spec). |
| 4 | +// x86 only. |
| 5 | + |
| 6 | +//@ revisions: ENABLED DISABLED |
| 7 | +//@ add-core-stubs |
| 8 | +//@ compile-flags: --target i686-unknown-linux-gnu -O -C no-prepopulate-passes |
| 9 | +//@ [ENABLED] compile-flags: -Zreg-struct-return |
| 10 | +//@ needs-llvm-components: x86 |
| 11 | + |
| 12 | +#![crate_type = "lib"] |
| 13 | +#![no_std] |
| 14 | +#![no_core] |
| 15 | +#![feature(no_core, lang_items)] |
| 16 | + |
| 17 | +extern crate minicore; |
| 18 | +use minicore::*; |
| 19 | + |
| 20 | +#[repr(C)] |
| 21 | +pub struct Foo { |
| 22 | + x: u32, |
| 23 | + y: u32, |
| 24 | +} |
| 25 | + |
| 26 | +#[repr(C)] |
| 27 | +pub struct Foo1 { |
| 28 | + x: u32, |
| 29 | +} |
| 30 | + |
| 31 | +#[repr(C)] |
| 32 | +pub struct Foo2 { |
| 33 | + x: bool, |
| 34 | + y: bool, |
| 35 | + z: i16, |
| 36 | +} |
| 37 | + |
| 38 | +#[repr(C)] |
| 39 | +pub struct Foo3 { |
| 40 | + x: i16, |
| 41 | + y: bool, |
| 42 | + z: bool, |
| 43 | +} |
| 44 | + |
| 45 | +#[repr(C)] |
| 46 | +pub struct Foo4 { |
| 47 | + x: char, |
| 48 | + y: bool, |
| 49 | + z: u8, |
| 50 | +} |
| 51 | + |
| 52 | +#[repr(C)] |
| 53 | +pub struct Foo5 { |
| 54 | + x: u32, |
| 55 | + y: u16, |
| 56 | + z: u8, |
| 57 | + a: bool, |
| 58 | +} |
| 59 | + |
| 60 | +#[repr(C)] |
| 61 | +pub struct FooOversize1 { |
| 62 | + x: u32, |
| 63 | + y: u32, |
| 64 | + z: u32, |
| 65 | +} |
| 66 | + |
| 67 | +#[repr(C)] |
| 68 | +pub struct FooOversize2 { |
| 69 | + f0: u16, |
| 70 | + f1: u16, |
| 71 | + f2: u16, |
| 72 | + f3: u16, |
| 73 | + f4: u16, |
| 74 | +} |
| 75 | + |
| 76 | +#[repr(C)] |
| 77 | +pub struct FooFloat1 { |
| 78 | + x: f32, |
| 79 | + y: f32, |
| 80 | +} |
| 81 | + |
| 82 | +#[repr(C)] |
| 83 | +pub struct FooFloat2 { |
| 84 | + x: f64, |
| 85 | +} |
| 86 | + |
| 87 | +#[repr(C)] |
| 88 | +pub struct FooFloat3 { |
| 89 | + x: f32, |
| 90 | +} |
| 91 | + |
| 92 | +pub mod tests { |
| 93 | + use { |
| 94 | + Foo, Foo1, Foo2, Foo3, Foo4, Foo5, FooFloat1, FooFloat2, FooFloat3, FooOversize1, |
| 95 | + FooOversize2, |
| 96 | + }; |
| 97 | + |
| 98 | + // ENABLED: i64 @f1() |
| 99 | + // DISABLED: void @f1(ptr {{.*}}sret |
| 100 | + #[no_mangle] |
| 101 | + pub extern "fastcall" fn f1() -> Foo { |
| 102 | + Foo { x: 1, y: 2 } |
| 103 | + } |
| 104 | + |
| 105 | + // CHECK: { i32, i32 } @f2() |
| 106 | + #[no_mangle] |
| 107 | + pub extern "Rust" fn f2() -> Foo { |
| 108 | + Foo { x: 1, y: 2 } |
| 109 | + } |
| 110 | + |
| 111 | + // ENABLED: i64 @f3() |
| 112 | + // DISABLED: void @f3(ptr {{.*}}sret |
| 113 | + #[no_mangle] |
| 114 | + pub extern "C" fn f3() -> Foo { |
| 115 | + Foo { x: 1, y: 2 } |
| 116 | + } |
| 117 | + |
| 118 | + // ENABLED: i64 @f4() |
| 119 | + // DISABLED: void @f4(ptr {{.*}}sret |
| 120 | + #[no_mangle] |
| 121 | + pub extern "cdecl" fn f4() -> Foo { |
| 122 | + Foo { x: 1, y: 2 } |
| 123 | + } |
| 124 | + |
| 125 | + // ENABLED: i64 @f5() |
| 126 | + // DISABLED: void @f5(ptr {{.*}}sret |
| 127 | + #[no_mangle] |
| 128 | + pub extern "stdcall" fn f5() -> Foo { |
| 129 | + Foo { x: 1, y: 2 } |
| 130 | + } |
| 131 | + |
| 132 | + // ENABLED: i64 @f6() |
| 133 | + // DISABLED: void @f6(ptr {{.*}}sret |
| 134 | + #[no_mangle] |
| 135 | + pub extern "thiscall" fn f6() -> Foo { |
| 136 | + Foo { x: 1, y: 2 } |
| 137 | + } |
| 138 | + |
| 139 | + // ENABLED: i32 @f7() |
| 140 | + // DISABLED: void @f7(ptr {{.*}}sret |
| 141 | + #[no_mangle] |
| 142 | + pub extern "C" fn f7() -> Foo1 { |
| 143 | + Foo1 { x: 1 } |
| 144 | + } |
| 145 | + |
| 146 | + // ENABLED: i32 @f8() |
| 147 | + // DISABLED: void @f8(ptr {{.*}}sret |
| 148 | + #[no_mangle] |
| 149 | + pub extern "C" fn f8() -> Foo2 { |
| 150 | + Foo2 { x: true, y: false, z: 5 } |
| 151 | + } |
| 152 | + |
| 153 | + // ENABLED: i32 @f9() |
| 154 | + // DISABLED: void @f9(ptr {{.*}}sret |
| 155 | + #[no_mangle] |
| 156 | + pub extern "C" fn f9() -> Foo3 { |
| 157 | + Foo3 { x: 5, y: false, z: true } |
| 158 | + } |
| 159 | + |
| 160 | + // ENABLED: i64 @f10() |
| 161 | + // DISABLED: void @f10(ptr {{.*}}sret |
| 162 | + #[no_mangle] |
| 163 | + pub extern "C" fn f10() -> Foo4 { |
| 164 | + Foo4 { x: 'x', y: true, z: 170 } |
| 165 | + } |
| 166 | + |
| 167 | + // ENABLED: i64 @f11() |
| 168 | + // DISABLED: void @f11(ptr {{.*}}sret |
| 169 | + #[no_mangle] |
| 170 | + pub extern "C" fn f11() -> Foo5 { |
| 171 | + Foo5 { x: 1, y: 2, z: 3, a: true } |
| 172 | + } |
| 173 | + |
| 174 | + // CHECK: void @f12(ptr {{.*}}sret |
| 175 | + #[no_mangle] |
| 176 | + pub extern "C" fn f12() -> FooOversize1 { |
| 177 | + FooOversize1 { x: 1, y: 2, z: 3 } |
| 178 | + } |
| 179 | + |
| 180 | + // CHECK: void @f13(ptr {{.*}}sret |
| 181 | + #[no_mangle] |
| 182 | + pub extern "C" fn f13() -> FooOversize2 { |
| 183 | + FooOversize2 { f0: 1, f1: 2, f2: 3, f3: 4, f4: 5 } |
| 184 | + } |
| 185 | + |
| 186 | + // ENABLED: i64 @f14() |
| 187 | + // DISABLED: void @f14(ptr {{.*}}sret |
| 188 | + #[no_mangle] |
| 189 | + pub extern "C" fn f14() -> FooFloat1 { |
| 190 | + FooFloat1 { x: 1.0, y: 1.0 } |
| 191 | + } |
| 192 | + |
| 193 | + // ENABLED: double @f15() |
| 194 | + // DISABLED: void @f15(ptr {{.*}}sret |
| 195 | + #[no_mangle] |
| 196 | + pub extern "C" fn f15() -> FooFloat2 { |
| 197 | + FooFloat2 { x: 1.0 } |
| 198 | + } |
| 199 | + |
| 200 | + // ENABLED: float @f16() |
| 201 | + // DISABLED: void @f16(ptr {{.*}}sret |
| 202 | + #[no_mangle] |
| 203 | + pub extern "C" fn f16() -> FooFloat3 { |
| 204 | + FooFloat3 { x: 1.0 } |
| 205 | + } |
| 206 | +} |
0 commit comments