blob: eb3d5a6bd6311e1b716189bdb193776a666a7a67 [file] [log] [blame]
Anton Korobeynikov00000b02012-04-13 11:23:39 +00001// RUN: %clang_cc1 -triple armv7---eabi -target-abi aapcs -mfloat-abi hard -emit-llvm %s -o - | FileCheck %s
Anton Korobeynikova8063c32012-04-23 09:02:13 +00002
3typedef long long int64_t;
4typedef unsigned int uint32_t;
Anton Korobeynikov00000b02012-04-13 11:23:39 +00005
6/* This is not a homogenous aggregate - fundamental types are different */
7typedef union {
8 float f[4];
9 uint32_t i[4];
10} union_with_first_floats;
11union_with_first_floats g_u_f;
12
13extern void takes_union_with_first_floats(union_with_first_floats a);
14extern union_with_first_floats returns_union_with_first_floats(void);
15
16void test_union_with_first_floats(void) {
17 takes_union_with_first_floats(g_u_f);
18}
19// CHECK: declare arm_aapcs_vfpcc void @takes_union_with_first_floats([4 x i32])
20
21void test_return_union_with_first_floats(void) {
22 g_u_f = returns_union_with_first_floats();
23}
24// CHECK: declare arm_aapcs_vfpcc void @returns_union_with_first_floats(%union.union_with_first_floats* sret)
25
26/* This is not a homogenous aggregate - fundamental types are different */
27typedef union {
28 uint32_t i[4];
29 float f[4];
30} union_with_non_first_floats;
31union_with_non_first_floats g_u_nf_f;
32
33extern void takes_union_with_non_first_floats(union_with_non_first_floats a);
34extern union_with_non_first_floats returns_union_with_non_first_floats(void);
35
36void test_union_with_non_first_floats(void) {
37 takes_union_with_non_first_floats(g_u_nf_f);
38}
39// CHECK: declare arm_aapcs_vfpcc void @takes_union_with_non_first_floats([4 x i32])
40
41void test_return_union_with_non_first_floats(void) {
42 g_u_nf_f = returns_union_with_non_first_floats();
43}
44// CHECK: declare arm_aapcs_vfpcc void @returns_union_with_non_first_floats(%union.union_with_non_first_floats* sret)
45
46/* This is not a homogenous aggregate - fundamental types are different */
47typedef struct {
48 float a;
49 union_with_first_floats b;
50} struct_with_union_with_first_floats;
51struct_with_union_with_first_floats g_s_f;
52
53extern void takes_struct_with_union_with_first_floats(struct_with_union_with_first_floats a);
54extern struct_with_union_with_first_floats returns_struct_with_union_with_first_floats(void);
55
56void test_struct_with_union_with_first_floats(void) {
57 takes_struct_with_union_with_first_floats(g_s_f);
58}
59// CHECK: declare arm_aapcs_vfpcc void @takes_struct_with_union_with_first_floats([5 x i32])
60
61void test_return_struct_with_union_with_first_floats(void) {
62 g_s_f = returns_struct_with_union_with_first_floats();
63}
64// CHECK: declare arm_aapcs_vfpcc void @returns_struct_with_union_with_first_floats(%struct.struct_with_union_with_first_floats* sret)
65
66/* This is not a homogenous aggregate - fundamental types are different */
67typedef struct {
68 float a;
69 union_with_non_first_floats b;
70} struct_with_union_with_non_first_floats;
71struct_with_union_with_non_first_floats g_s_nf_f;
72
73extern void takes_struct_with_union_with_non_first_floats(struct_with_union_with_non_first_floats a);
74extern struct_with_union_with_non_first_floats returns_struct_with_union_with_non_first_floats(void);
75
76void test_struct_with_union_with_non_first_floats(void) {
77 takes_struct_with_union_with_non_first_floats(g_s_nf_f);
78}
79// CHECK: declare arm_aapcs_vfpcc void @takes_struct_with_union_with_non_first_floats([5 x i32])
80
81void test_return_struct_with_union_with_non_first_floats(void) {
82 g_s_nf_f = returns_struct_with_union_with_non_first_floats();
83}
84// CHECK: declare arm_aapcs_vfpcc void @returns_struct_with_union_with_non_first_floats(%struct.struct_with_union_with_non_first_floats* sret)
85
86/* Plain array is not a homogenous aggregate */
87extern void takes_array_of_floats(float a[4]);
88void test_array_of_floats(void) {
89 float a[4] = {1.0, 2.0, 3.0, 4.0};
90 takes_array_of_floats(a);
91}
92// CHECK: declare arm_aapcs_vfpcc void @takes_array_of_floats(float*)
93
94/* Struct-type homogenous aggregate */
95typedef struct {
96 float x, y, z, w;
97} struct_with_fundamental_elems;
98struct_with_fundamental_elems g_s;
99
100extern void takes_struct_with_fundamental_elems(struct_with_fundamental_elems a);
101extern struct_with_fundamental_elems returns_struct_with_fundamental_elems(void);
102
103void test_struct_with_fundamental_elems(void) {
104 takes_struct_with_fundamental_elems(g_s);
105// CHECK: call arm_aapcs_vfpcc void @takes_struct_with_fundamental_elems(float {{.*}}, float {{.*}}, float{{.*}}, float {{.*}})
106}
107// CHECK: declare arm_aapcs_vfpcc void @takes_struct_with_fundamental_elems(float, float, float, float)
108
109void test_return_struct_with_fundamental_elems(void) {
110 g_s = returns_struct_with_fundamental_elems();
111// CHECK: call arm_aapcs_vfpcc %struct.struct_with_fundamental_elems @returns_struct_with_fundamental_elems()
112}
113// CHECK: declare arm_aapcs_vfpcc %struct.struct_with_fundamental_elems @returns_struct_with_fundamental_elems()
114
115/* Array-type homogenous aggregate */
116typedef struct {
117 float xyzw[4];
118} struct_with_array;
119struct_with_array g_s_a;
120
121extern void takes_struct_with_array(struct_with_array a);
122extern struct_with_array returns_struct_with_array(void);
123
124void test_struct_with_array(void) {
125 takes_struct_with_array(g_s_a);
126// CHECK: call arm_aapcs_vfpcc void @takes_struct_with_array(float {{.*}}, float {{.*}}, float {{.*}}, float {{.*}})
127}
128// CHECK: declare arm_aapcs_vfpcc void @takes_struct_with_array(float, float, float, float)
129
130void test_return_struct_with_array(void) {
131 g_s_a = returns_struct_with_array();
132// CHECK: call arm_aapcs_vfpcc %struct.struct_with_array @returns_struct_with_array()
133}
134// CHECK: declare arm_aapcs_vfpcc %struct.struct_with_array @returns_struct_with_array()
135
136/* This union is a homogenous aggregate. Check that it's passed properly */
137typedef union {
138 struct_with_fundamental_elems xyzw;
139 float a[3];
140} union_with_struct_with_fundamental_elems;
141union_with_struct_with_fundamental_elems g_u_s_fe;
142
143extern void takes_union_with_struct_with_fundamental_elems(union_with_struct_with_fundamental_elems a);
144extern union_with_struct_with_fundamental_elems returns_union_with_struct_with_fundamental_elems(void);
145
146void test_union_with_struct_with_fundamental_elems(void) {
147 takes_union_with_struct_with_fundamental_elems(g_u_s_fe);
148// CHECK: call arm_aapcs_vfpcc void @takes_union_with_struct_with_fundamental_elems(float {{.*}}, float {{.*}}, float {{.*}}, float {{.*}})
149}
150// CHECK: declare arm_aapcs_vfpcc void @takes_union_with_struct_with_fundamental_elems(float, float, float, float)
151
152void test_return_union_with_struct_with_fundamental_elems(void) {
153 g_u_s_fe = returns_union_with_struct_with_fundamental_elems();
154// CHECK: call arm_aapcs_vfpcc %union.union_with_struct_with_fundamental_elems @returns_union_with_struct_with_fundamental_elems()
155}
156// CHECK: declare arm_aapcs_vfpcc %union.union_with_struct_with_fundamental_elems @returns_union_with_struct_with_fundamental_elems()
157
158// FIXME: Tests necessary:
159// - Vectors
160// - C++ stuff