1 // RUN: %clang_cc1 -triple i386-pc-elfiamcu -emit-llvm %s -o - | FileCheck %s
2
3 // Structure that is more than 8 byte.
4 struct Big {
5 double a[10];
6 };
7
8 // Empty union with zero size must be returned as void.
9 union U1 {
10 } u1;
11
12 // Too large union (80 bytes) must be returned via memory.
13 union U2 {
14 struct Big b;
15 } u2;
16
17 // Must be returned in register.
18 union U3 {
19 int x;
20 } u3;
21
22 // Empty struct with zero size, must be returned as void.
23 struct S1 {
24 } s1;
25
26 // Must be returend in register.
27 struct S2 {
28 int x;
29 } s2;
30
31 // CHECK: [[UNION1_TYPE:%.+]] = type {}
32 // CHECK: [[UNION2_TYPE:%.+]] = type { [[STRUCT_TYPE:%.+]] }
33 // CHECK: [[STRUCT_TYPE]] = type { [10 x double] }
34 // CHECK: [[UNION3_TYPE:%.+]] = type { i32 }
35 // CHECK: [[STRUCT1_TYPE:%.+]] = type {}
36 // CHECK: [[STRUCT2_TYPE:%.+]] = type { i32 }
37
foo1()38 union U1 foo1() { return u1; }
foo2()39 union U2 foo2() { return u2; }
foo3()40 union U3 foo3() { return u3; }
bar1()41 struct S1 bar1() { return s1; }
bar2()42 struct S2 bar2() { return s2; }
bar3(union U1 u)43 struct S1 bar3(union U1 u) { return s1; }
44 // CHECK: define void @foo1()
45 // CHECK: define void @foo2([[UNION2_TYPE]]* noalias sret %{{.+}})
46 // CHECK: define i32 @foo3()
47 // CHECK: define void @bar1()
48 // CHECK: define i32 @bar2()
49 // CHECK: define void @bar3()
50
run()51 void run() {
52 union U1 x1 = foo1();
53 union U2 x2 = foo2();
54 union U3 x3 = foo3();
55 struct S1 y1 = bar1();
56 struct S2 y2 = bar2();
57 struct S1 y3 = bar3(x1);
58
59 // CHECK: [[X1:%.+]] = alloca [[UNION1_TYPE]]
60 // CHECK: [[X2:%.+]] = alloca [[UNION2_TYPE]]
61 // CHECK: [[X3:%.+]] = alloca [[UNION3_TYPE]]
62 // CHECK: [[Y1:%.+]] = alloca [[STRUCT1_TYPE]]
63 // CHECK: [[Y2:%.+]] = alloca [[STRUCT2_TYPE]]
64 // CHECK: call void @foo1()
65 // CHECK: call void @foo2([[UNION2_TYPE]]* sret [[X2]])
66 // CHECK: {{.+}} = call i32 @foo3()
67 // CHECK: call void @bar1()
68 // CHECK: {{.+}} = call i32 @bar2()
69 // CHECK: call void @bar3()
70 }
71