[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / CodeGen / mcu-struct-return.c
blob38a9bc2a36bfec4d7520181b39227920a6c30f5f
1 // RUN: %clang_cc1 -triple i386-pc-elfiamcu -emit-llvm %s -o - | FileCheck %s
3 // Structure that is more than 8 byte.
4 struct Big {
5 double a[10];
6 };
8 // Empty union with zero size must be returned as void.
9 union U1 {
10 } u1;
12 // Too large union (80 bytes) must be returned via memory.
13 union U2 {
14 struct Big b;
15 } u2;
17 // Must be returned in register.
18 union U3 {
19 int x;
20 } u3;
22 // Empty struct with zero size, must be returned as void.
23 struct S1 {
24 } s1;
26 // Must be returend in register.
27 struct S2 {
28 int x;
29 } s2;
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 }
38 union U1 foo1(void) { return u1; }
39 union U2 foo2(void) { return u2; }
40 union U3 foo3(void) { return u3; }
41 struct S1 bar1(void) { return s1; }
42 struct S2 bar2(void) { return s2; }
43 struct S1 bar3(union U1 u) { return s1; }
44 // CHECK: define{{.*}} void @foo1()
45 // CHECK: define{{.*}} void @foo2(ptr dead_on_unwind noalias writable sret([[UNION2_TYPE]]) align 4 %{{.+}})
46 // CHECK: define{{.*}} i32 @foo3()
47 // CHECK: define{{.*}} void @bar1()
48 // CHECK: define{{.*}} i32 @bar2()
49 // CHECK: define{{.*}} void @bar3()
51 void run(void) {
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);
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(ptr dead_on_unwind writable sret([[UNION2_TYPE]]) align 4 [[X2]])
66 // CHECK: {{.+}} = call i32 @foo3()
67 // CHECK: call void @bar1()
68 // CHECK: {{.+}} = call i32 @bar2()
69 // CHECK: call void @bar3()