[LLVM][IR] Use splat syntax when printing ConstantExpr based splats. (#116856)
[llvm-project.git] / clang / test / CodeGen / struct.c
blobc98357160addf1c44aa408bb7395607c6539286d
1 // RUN: %clang_cc1 -triple i386-unknown-unknown %s -emit-llvm -o -
3 struct {
4 int x;
5 int y;
6 } point;
8 void fn1(void) {
9 point.x = 42;
12 /* Nested member */
13 struct {
14 struct {
15 int a;
16 int b;
17 } p1;
18 } point2;
20 void fn2(void) {
21 point2.p1.a = 42;
24 /* Indirect reference */
25 typedef struct __sf {
26 unsigned char *c;
27 short flags;
28 } F;
30 typedef struct __sf2 {
31 F *ff;
32 } F2;
34 int fn3(F2 *c) {
35 if (c->ff->c >= 0)
36 return 1;
37 else
38 return 0;
41 /* Nested structs */
42 typedef struct NA {
43 int data;
44 struct NA *next;
45 } NA;
46 void f1(void) { NA a; }
48 typedef struct NB {
49 int d1;
50 struct _B2 {
51 int d2;
52 struct NB *n2;
53 } B2;
54 } NB;
56 void f2(void) { NB b; }
58 extern NB *f3(void);
59 void f4(void) {
60 f3()->d1 = 42;
63 void f5(void) {
64 (f3())->d1 = 42;
67 /* Function calls */
68 typedef struct {
69 int location;
70 int length;
71 } range;
72 extern range f6(void);
73 void f7(void) {
74 range r = f6();
77 /* Member expressions */
78 typedef struct {
79 range range1;
80 range range2;
81 } rangepair;
83 void f8(void) {
84 rangepair p;
86 range r = p.range1;
89 void f9(range *p) {
90 range r = *p;
93 void f10(range *p) {
94 range r = p[0];
97 /* _Bool types */
99 struct _w {
100 short a,b;
101 short c,d;
102 short e,f;
103 short g;
105 unsigned int h,i;
107 _Bool j,k;
108 } ws;
110 /* Implicit casts (due to typedefs) */
111 typedef struct _a {
112 int a;
113 } a;
115 void f11(void) {
116 struct _a a1;
117 a a2;
119 a1 = a2;
120 a2 = a1;
123 /* Implicit casts (due to const) */
124 void f12(void) {
125 struct _a a1;
126 const struct _a a2;
128 a1 = a2;
131 /* struct initialization */
132 struct a13 {int b; int c;};
133 struct a13 c13 = {5};
134 typedef struct a13 a13;
135 struct a14 { short a; int b; } x = {1, 1};
137 /* flexible array members */
138 struct a15 {char a; int b[];} c15;
139 int a16(void) {c15.a = 1;}
141 /* compound literals */
142 void f13(void) {
143 a13 x; x = (a13){1,2};
146 /* va_arg */
147 int f14(int i, ...) {
148 __builtin_va_list l;
149 __builtin_va_start(l,i);
150 a13 b = __builtin_va_arg(l, a13);
151 int c = __builtin_va_arg(l, a13).c;
152 return b.b;
155 /* Attribute packed */
156 struct __attribute__((packed)) S2839 { double a[19]; signed char b; } s2839[5];
158 struct __attribute__((packed)) SS { long double a; char b; } SS;
161 /* As lvalue */
163 int f15(void) {
164 extern range f15_ext(void);
165 return f15_ext().location;
168 range f16(void) {
169 extern rangepair f16_ext(void);
170 return f16_ext().range1;
173 int f17(void) {
174 extern range f17_ext(void);
175 range r;
176 return (r = f17_ext()).location;
179 range f18(void) {
180 extern rangepair f18_ext(void);
181 rangepair rp;
182 return (rp = f18_ext()).range1;
187 // Complex forward reference of struct.
188 struct f19S;
189 extern struct f19T {
190 struct f19S (*p)(void);
191 } t;
192 struct f19S { int i; };
193 void f19(void) {
194 t.p();