summaryrefslogtreecommitdiff
path: root/clang/test/CodeGen/arm-homogenous.c
blob: eb3d5a6bd6311e1b716189bdb193776a666a7a67 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// RUN: %clang_cc1 -triple armv7---eabi -target-abi aapcs -mfloat-abi hard -emit-llvm %s -o - | FileCheck %s

typedef long long int64_t;
typedef unsigned int uint32_t;

/* This is not a homogenous aggregate - fundamental types are different */
typedef union {
  float       f[4];
  uint32_t    i[4];
} union_with_first_floats;
union_with_first_floats g_u_f;

extern void takes_union_with_first_floats(union_with_first_floats a);
extern union_with_first_floats returns_union_with_first_floats(void);

void test_union_with_first_floats(void) {
  takes_union_with_first_floats(g_u_f);
}
// CHECK: declare arm_aapcs_vfpcc void @takes_union_with_first_floats([4 x i32])

void test_return_union_with_first_floats(void) {
  g_u_f = returns_union_with_first_floats();
}
// CHECK: declare arm_aapcs_vfpcc void @returns_union_with_first_floats(%union.union_with_first_floats* sret)

/* This is not a homogenous aggregate - fundamental types are different */
typedef union {
    uint32_t    i[4];
    float       f[4];
} union_with_non_first_floats;
union_with_non_first_floats g_u_nf_f;

extern void takes_union_with_non_first_floats(union_with_non_first_floats a);
extern union_with_non_first_floats returns_union_with_non_first_floats(void);

void test_union_with_non_first_floats(void) {
  takes_union_with_non_first_floats(g_u_nf_f);
}
// CHECK: declare arm_aapcs_vfpcc void @takes_union_with_non_first_floats([4 x i32])

void test_return_union_with_non_first_floats(void) {
  g_u_nf_f = returns_union_with_non_first_floats();
}
// CHECK: declare arm_aapcs_vfpcc void @returns_union_with_non_first_floats(%union.union_with_non_first_floats* sret)

/* This is not a homogenous aggregate - fundamental types are different */
typedef struct {
  float a;
  union_with_first_floats b;
} struct_with_union_with_first_floats;
struct_with_union_with_first_floats g_s_f;

extern void takes_struct_with_union_with_first_floats(struct_with_union_with_first_floats a);
extern struct_with_union_with_first_floats returns_struct_with_union_with_first_floats(void);

void test_struct_with_union_with_first_floats(void) {
  takes_struct_with_union_with_first_floats(g_s_f);
}
// CHECK: declare arm_aapcs_vfpcc void @takes_struct_with_union_with_first_floats([5 x i32])

void test_return_struct_with_union_with_first_floats(void) {
  g_s_f = returns_struct_with_union_with_first_floats();
}
// CHECK: declare arm_aapcs_vfpcc void @returns_struct_with_union_with_first_floats(%struct.struct_with_union_with_first_floats* sret)

/* This is not a homogenous aggregate - fundamental types are different */
typedef struct {
  float a;
  union_with_non_first_floats b;
} struct_with_union_with_non_first_floats;
struct_with_union_with_non_first_floats g_s_nf_f;

extern void takes_struct_with_union_with_non_first_floats(struct_with_union_with_non_first_floats a);
extern struct_with_union_with_non_first_floats returns_struct_with_union_with_non_first_floats(void);

void test_struct_with_union_with_non_first_floats(void) {
  takes_struct_with_union_with_non_first_floats(g_s_nf_f);
}
// CHECK: declare arm_aapcs_vfpcc void @takes_struct_with_union_with_non_first_floats([5 x i32])

void test_return_struct_with_union_with_non_first_floats(void) {
  g_s_nf_f = returns_struct_with_union_with_non_first_floats();
}
// CHECK: declare arm_aapcs_vfpcc void @returns_struct_with_union_with_non_first_floats(%struct.struct_with_union_with_non_first_floats* sret)

/* Plain array is not a homogenous aggregate */
extern void takes_array_of_floats(float a[4]);
void test_array_of_floats(void) {
  float a[4] = {1.0, 2.0, 3.0, 4.0};
  takes_array_of_floats(a);
}
// CHECK: declare arm_aapcs_vfpcc void @takes_array_of_floats(float*)

/* Struct-type homogenous aggregate */
typedef struct {
  float x, y, z, w;
} struct_with_fundamental_elems;
struct_with_fundamental_elems g_s;

extern void takes_struct_with_fundamental_elems(struct_with_fundamental_elems a);
extern struct_with_fundamental_elems returns_struct_with_fundamental_elems(void);

void test_struct_with_fundamental_elems(void) {
  takes_struct_with_fundamental_elems(g_s);
// CHECK:  call arm_aapcs_vfpcc  void @takes_struct_with_fundamental_elems(float {{.*}}, float {{.*}}, float{{.*}}, float {{.*}})
}
// CHECK: declare arm_aapcs_vfpcc void @takes_struct_with_fundamental_elems(float, float, float, float)

void test_return_struct_with_fundamental_elems(void) {
  g_s = returns_struct_with_fundamental_elems();
// CHECK: call arm_aapcs_vfpcc  %struct.struct_with_fundamental_elems @returns_struct_with_fundamental_elems()
}
// CHECK: declare arm_aapcs_vfpcc %struct.struct_with_fundamental_elems @returns_struct_with_fundamental_elems()

/* Array-type homogenous aggregate */
typedef struct {
  float xyzw[4];
} struct_with_array;
struct_with_array g_s_a;

extern void takes_struct_with_array(struct_with_array a);
extern struct_with_array returns_struct_with_array(void);

void test_struct_with_array(void) {
  takes_struct_with_array(g_s_a);
// CHECK:   call arm_aapcs_vfpcc  void @takes_struct_with_array(float {{.*}}, float {{.*}}, float {{.*}}, float {{.*}})
}
// CHECK: declare arm_aapcs_vfpcc void @takes_struct_with_array(float, float, float, float)

void test_return_struct_with_array(void) {
  g_s_a = returns_struct_with_array();
// CHECK:   call arm_aapcs_vfpcc  %struct.struct_with_array @returns_struct_with_array()
}
// CHECK: declare arm_aapcs_vfpcc %struct.struct_with_array @returns_struct_with_array()

/* This union is a homogenous aggregate. Check that it's passed properly */
typedef union {
  struct_with_fundamental_elems xyzw;
  float a[3];
} union_with_struct_with_fundamental_elems;
union_with_struct_with_fundamental_elems g_u_s_fe;

extern void takes_union_with_struct_with_fundamental_elems(union_with_struct_with_fundamental_elems a);
extern union_with_struct_with_fundamental_elems returns_union_with_struct_with_fundamental_elems(void);

void test_union_with_struct_with_fundamental_elems(void) {
  takes_union_with_struct_with_fundamental_elems(g_u_s_fe);
// CHECK: call arm_aapcs_vfpcc  void @takes_union_with_struct_with_fundamental_elems(float {{.*}}, float {{.*}}, float {{.*}}, float {{.*}})
}
// CHECK: declare arm_aapcs_vfpcc void @takes_union_with_struct_with_fundamental_elems(float, float, float, float)

void test_return_union_with_struct_with_fundamental_elems(void) {
  g_u_s_fe = returns_union_with_struct_with_fundamental_elems();
// CHECK: call arm_aapcs_vfpcc  %union.union_with_struct_with_fundamental_elems @returns_union_with_struct_with_fundamental_elems()
}
// CHECK: declare arm_aapcs_vfpcc %union.union_with_struct_with_fundamental_elems @returns_union_with_struct_with_fundamental_elems()

// FIXME: Tests necessary:
//         - Vectors
//         - C++ stuff