1 // Checks that we correctly codegen extern "C" functions returning structs.
2 // See issues #52638 and #86163.
3
4 // compile-flags: -O --target=sparc64-unknown-linux-gnu --crate-type=rlib
5 // needs-llvm-components: sparc
6 #![feature(no_core, lang_items)]
7 #![no_core]
8
9 #[lang="sized"]
10 trait Sized { }
11 #[lang="freeze"]
12 trait Freeze { }
13 #[lang="copy"]
14 trait Copy { }
15
16 #[repr(C)]
17 pub struct Bool {
18 b: bool,
19 }
20
21 // CHECK: define i64 @structbool()
22 // CHECK-NEXT: start:
23 // CHECK-NEXT: ret i64 72057594037927936
24 #[no_mangle]
structbool() -> Bool25 pub extern "C" fn structbool() -> Bool {
26 Bool { b: true }
27 }
28
29
30 #[repr(C)]
31 pub struct BoolFloat {
32 b: bool,
33 f: f32,
34 }
35
36 // CHECK: define inreg { i32, float } @structboolfloat()
37 // CHECK-NEXT: start:
38 // CHECK-NEXT: ret { i32, float } { i32 16777216, float 0x40091EB860000000 }
39 #[no_mangle]
structboolfloat() -> BoolFloat40 pub extern "C" fn structboolfloat() -> BoolFloat {
41 BoolFloat { b: true, f: 3.14 }
42 }
43
44 // CHECK: define void @structboolfloat_input({ i32, float } inreg %0)
45 // CHECK-NEXT: start:
46 #[no_mangle]
structboolfloat_input(a: BoolFloat)47 pub extern "C" fn structboolfloat_input(a: BoolFloat) { }
48
49
50 #[repr(C)]
51 pub struct ShortDouble {
52 s: i16,
53 d: f64,
54 }
55
56 // CHECK: define { i64, double } @structshortdouble()
57 // CHECK-NEXT: start:
58 // CHECK-NEXT: ret { i64, double } { i64 34621422135410688, double 3.140000e+00 }
59 #[no_mangle]
structshortdouble() -> ShortDouble60 pub extern "C" fn structshortdouble() -> ShortDouble {
61 ShortDouble { s: 123, d: 3.14 }
62 }
63
64 // CHECK: define void @structshortdouble_input({ i64, double } %0)
65 // CHECK-NEXT: start:
66 #[no_mangle]
structshortdouble_input(a: ShortDouble)67 pub extern "C" fn structshortdouble_input(a: ShortDouble) { }
68
69
70 #[repr(C)]
71 pub struct FloatLongFloat {
72 f: f32,
73 i: i64,
74 g: f32,
75 }
76
77 // CHECK: define inreg { float, i32, i64, float, i32 } @structfloatlongfloat()
78 // CHECK-NEXT: start:
79 // CHECK-NEXT: ret { float, i32, i64, float, i32 } { float 0x3FB99999A0000000, i32 undef, i64 123, float 0x40091EB860000000, i32 undef }
80 #[no_mangle]
structfloatlongfloat() -> FloatLongFloat81 pub extern "C" fn structfloatlongfloat() -> FloatLongFloat {
82 FloatLongFloat { f: 0.1, i: 123, g: 3.14 }
83 }
84
85 #[repr(C)]
86 pub struct FloatFloat {
87 f: f32,
88 g: f32,
89 }
90
91 #[repr(C)]
92 pub struct NestedStructs {
93 a: FloatFloat,
94 b: FloatFloat,
95 }
96
97 // CHECK: define inreg { float, float, float, float } @structnestestructs()
98 // CHECK-NEXT: start:
99 // CHECK-NEXT: ret { float, float, float, float } { float 0x3FB99999A0000000, float 0x3FF19999A0000000, float 0x40019999A0000000, float 0x400A666660000000 }
100 #[no_mangle]
structnestestructs() -> NestedStructs101 pub extern "C" fn structnestestructs() -> NestedStructs {
102 NestedStructs { a: FloatFloat { f: 0.1, g: 1.1 }, b: FloatFloat { f: 2.2, g: 3.3 } }
103 }
104