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