Clang Project

clang_source_code/test/CodeGen/mcu-struct-return.c
1// RUN: %clang_cc1 -triple i386-pc-elfiamcu -emit-llvm %s -o - | FileCheck %s
2
3// Structure that is more than 8 byte.
4struct Big {
5  double a[10];
6};
7
8// Empty union with zero size must be returned as void.
9union U1 {
10} u1;
11
12// Too large union (80 bytes) must be returned via memory.
13union U2 {
14  struct Big b;
15} u2;
16
17// Must be returned in register.
18union U3 {
19  int x;
20} u3;
21
22// Empty struct with zero size, must be returned as void.
23struct S1 {
24} s1;
25
26// Must be returend in register.
27struct 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
38union U1 foo1() { return u1; }
39union U2 foo2() { return u2; }
40union U3 foo3() { return u3; }
41struct S1 bar1() { return s1; }
42struct S2 bar2() { return s2; }
43struct 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
51void 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