1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple i386-unknown-unknown %s -emit-llvm -o -
2*f4a2713aSLionel Sambuc
3*f4a2713aSLionel Sambuc struct {
4*f4a2713aSLionel Sambuc int x;
5*f4a2713aSLionel Sambuc int y;
6*f4a2713aSLionel Sambuc } point;
7*f4a2713aSLionel Sambuc
fn1()8*f4a2713aSLionel Sambuc void fn1() {
9*f4a2713aSLionel Sambuc point.x = 42;
10*f4a2713aSLionel Sambuc }
11*f4a2713aSLionel Sambuc
12*f4a2713aSLionel Sambuc /* Nested member */
13*f4a2713aSLionel Sambuc struct {
14*f4a2713aSLionel Sambuc struct {
15*f4a2713aSLionel Sambuc int a;
16*f4a2713aSLionel Sambuc int b;
17*f4a2713aSLionel Sambuc } p1;
18*f4a2713aSLionel Sambuc } point2;
19*f4a2713aSLionel Sambuc
fn2()20*f4a2713aSLionel Sambuc void fn2() {
21*f4a2713aSLionel Sambuc point2.p1.a = 42;
22*f4a2713aSLionel Sambuc }
23*f4a2713aSLionel Sambuc
24*f4a2713aSLionel Sambuc /* Indirect reference */
25*f4a2713aSLionel Sambuc typedef struct __sf {
26*f4a2713aSLionel Sambuc unsigned char *c;
27*f4a2713aSLionel Sambuc short flags;
28*f4a2713aSLionel Sambuc } F;
29*f4a2713aSLionel Sambuc
30*f4a2713aSLionel Sambuc typedef struct __sf2 {
31*f4a2713aSLionel Sambuc F *ff;
32*f4a2713aSLionel Sambuc } F2;
33*f4a2713aSLionel Sambuc
fn3(F2 * c)34*f4a2713aSLionel Sambuc int fn3(F2 *c) {
35*f4a2713aSLionel Sambuc if (c->ff->c >= 0)
36*f4a2713aSLionel Sambuc return 1;
37*f4a2713aSLionel Sambuc else
38*f4a2713aSLionel Sambuc return 0;
39*f4a2713aSLionel Sambuc }
40*f4a2713aSLionel Sambuc
41*f4a2713aSLionel Sambuc /* Nested structs */
42*f4a2713aSLionel Sambuc typedef struct NA {
43*f4a2713aSLionel Sambuc int data;
44*f4a2713aSLionel Sambuc struct NA *next;
45*f4a2713aSLionel Sambuc } NA;
f1()46*f4a2713aSLionel Sambuc void f1() { NA a; }
47*f4a2713aSLionel Sambuc
48*f4a2713aSLionel Sambuc typedef struct NB {
49*f4a2713aSLionel Sambuc int d1;
50*f4a2713aSLionel Sambuc struct _B2 {
51*f4a2713aSLionel Sambuc int d2;
52*f4a2713aSLionel Sambuc struct NB *n2;
53*f4a2713aSLionel Sambuc } B2;
54*f4a2713aSLionel Sambuc } NB;
55*f4a2713aSLionel Sambuc
f2()56*f4a2713aSLionel Sambuc void f2() { NB b; }
57*f4a2713aSLionel Sambuc
58*f4a2713aSLionel Sambuc extern NB *f3();
f4()59*f4a2713aSLionel Sambuc void f4() {
60*f4a2713aSLionel Sambuc f3()->d1 = 42;
61*f4a2713aSLionel Sambuc }
62*f4a2713aSLionel Sambuc
f5()63*f4a2713aSLionel Sambuc void f5() {
64*f4a2713aSLionel Sambuc (f3())->d1 = 42;
65*f4a2713aSLionel Sambuc }
66*f4a2713aSLionel Sambuc
67*f4a2713aSLionel Sambuc /* Function calls */
68*f4a2713aSLionel Sambuc typedef struct {
69*f4a2713aSLionel Sambuc int location;
70*f4a2713aSLionel Sambuc int length;
71*f4a2713aSLionel Sambuc } range;
72*f4a2713aSLionel Sambuc extern range f6();
f7()73*f4a2713aSLionel Sambuc void f7() {
74*f4a2713aSLionel Sambuc range r = f6();
75*f4a2713aSLionel Sambuc }
76*f4a2713aSLionel Sambuc
77*f4a2713aSLionel Sambuc /* Member expressions */
78*f4a2713aSLionel Sambuc typedef struct {
79*f4a2713aSLionel Sambuc range range1;
80*f4a2713aSLionel Sambuc range range2;
81*f4a2713aSLionel Sambuc } rangepair;
82*f4a2713aSLionel Sambuc
f8()83*f4a2713aSLionel Sambuc void f8() {
84*f4a2713aSLionel Sambuc rangepair p;
85*f4a2713aSLionel Sambuc
86*f4a2713aSLionel Sambuc range r = p.range1;
87*f4a2713aSLionel Sambuc }
88*f4a2713aSLionel Sambuc
f9(range * p)89*f4a2713aSLionel Sambuc void f9(range *p) {
90*f4a2713aSLionel Sambuc range r = *p;
91*f4a2713aSLionel Sambuc }
92*f4a2713aSLionel Sambuc
f10(range * p)93*f4a2713aSLionel Sambuc void f10(range *p) {
94*f4a2713aSLionel Sambuc range r = p[0];
95*f4a2713aSLionel Sambuc }
96*f4a2713aSLionel Sambuc
97*f4a2713aSLionel Sambuc /* _Bool types */
98*f4a2713aSLionel Sambuc
99*f4a2713aSLionel Sambuc struct _w {
100*f4a2713aSLionel Sambuc short a,b;
101*f4a2713aSLionel Sambuc short c,d;
102*f4a2713aSLionel Sambuc short e,f;
103*f4a2713aSLionel Sambuc short g;
104*f4a2713aSLionel Sambuc
105*f4a2713aSLionel Sambuc unsigned int h,i;
106*f4a2713aSLionel Sambuc
107*f4a2713aSLionel Sambuc _Bool j,k;
108*f4a2713aSLionel Sambuc } ws;
109*f4a2713aSLionel Sambuc
110*f4a2713aSLionel Sambuc /* Implicit casts (due to typedefs) */
111*f4a2713aSLionel Sambuc typedef struct _a {
112*f4a2713aSLionel Sambuc int a;
113*f4a2713aSLionel Sambuc } a;
114*f4a2713aSLionel Sambuc
f11()115*f4a2713aSLionel Sambuc void f11() {
116*f4a2713aSLionel Sambuc struct _a a1;
117*f4a2713aSLionel Sambuc a a2;
118*f4a2713aSLionel Sambuc
119*f4a2713aSLionel Sambuc a1 = a2;
120*f4a2713aSLionel Sambuc a2 = a1;
121*f4a2713aSLionel Sambuc }
122*f4a2713aSLionel Sambuc
123*f4a2713aSLionel Sambuc /* Implicit casts (due to const) */
f12()124*f4a2713aSLionel Sambuc void f12() {
125*f4a2713aSLionel Sambuc struct _a a1;
126*f4a2713aSLionel Sambuc const struct _a a2;
127*f4a2713aSLionel Sambuc
128*f4a2713aSLionel Sambuc a1 = a2;
129*f4a2713aSLionel Sambuc }
130*f4a2713aSLionel Sambuc
131*f4a2713aSLionel Sambuc /* struct initialization */
132*f4a2713aSLionel Sambuc struct a13 {int b; int c;};
133*f4a2713aSLionel Sambuc struct a13 c13 = {5};
134*f4a2713aSLionel Sambuc typedef struct a13 a13;
135*f4a2713aSLionel Sambuc struct a14 { short a; int b; } x = {1, 1};
136*f4a2713aSLionel Sambuc
137*f4a2713aSLionel Sambuc /* flexible array members */
138*f4a2713aSLionel Sambuc struct a15 {char a; int b[];} c15;
a16(void)139*f4a2713aSLionel Sambuc int a16(void) {c15.a = 1;}
140*f4a2713aSLionel Sambuc
141*f4a2713aSLionel Sambuc /* compound literals */
f13()142*f4a2713aSLionel Sambuc void f13() {
143*f4a2713aSLionel Sambuc a13 x; x = (a13){1,2};
144*f4a2713aSLionel Sambuc }
145*f4a2713aSLionel Sambuc
146*f4a2713aSLionel Sambuc /* va_arg */
f14(int i,...)147*f4a2713aSLionel Sambuc int f14(int i, ...) {
148*f4a2713aSLionel Sambuc __builtin_va_list l;
149*f4a2713aSLionel Sambuc __builtin_va_start(l,i);
150*f4a2713aSLionel Sambuc a13 b = __builtin_va_arg(l, a13);
151*f4a2713aSLionel Sambuc int c = __builtin_va_arg(l, a13).c;
152*f4a2713aSLionel Sambuc return b.b;
153*f4a2713aSLionel Sambuc }
154*f4a2713aSLionel Sambuc
155*f4a2713aSLionel Sambuc /* Attribute packed */
156*f4a2713aSLionel Sambuc struct __attribute__((packed)) S2839 { double a[19]; signed char b; } s2839[5];
157*f4a2713aSLionel Sambuc
158*f4a2713aSLionel Sambuc struct __attribute__((packed)) SS { long double a; char b; } SS;
159*f4a2713aSLionel Sambuc
160*f4a2713aSLionel Sambuc
161*f4a2713aSLionel Sambuc /* As lvalue */
162*f4a2713aSLionel Sambuc
f15()163*f4a2713aSLionel Sambuc int f15() {
164*f4a2713aSLionel Sambuc extern range f15_ext();
165*f4a2713aSLionel Sambuc return f15_ext().location;
166*f4a2713aSLionel Sambuc }
167*f4a2713aSLionel Sambuc
f16()168*f4a2713aSLionel Sambuc range f16() {
169*f4a2713aSLionel Sambuc extern rangepair f16_ext();
170*f4a2713aSLionel Sambuc return f16_ext().range1;
171*f4a2713aSLionel Sambuc }
172*f4a2713aSLionel Sambuc
f17()173*f4a2713aSLionel Sambuc int f17() {
174*f4a2713aSLionel Sambuc extern range f17_ext();
175*f4a2713aSLionel Sambuc range r;
176*f4a2713aSLionel Sambuc return (r = f17_ext()).location;
177*f4a2713aSLionel Sambuc }
178*f4a2713aSLionel Sambuc
f18()179*f4a2713aSLionel Sambuc range f18() {
180*f4a2713aSLionel Sambuc extern rangepair f18_ext();
181*f4a2713aSLionel Sambuc rangepair rp;
182*f4a2713aSLionel Sambuc return (rp = f18_ext()).range1;
183*f4a2713aSLionel Sambuc }
184*f4a2713aSLionel Sambuc
185*f4a2713aSLionel Sambuc
186*f4a2713aSLionel Sambuc
187*f4a2713aSLionel Sambuc // Complex forward reference of struct.
188*f4a2713aSLionel Sambuc struct f19S;
189*f4a2713aSLionel Sambuc extern struct f19T {
190*f4a2713aSLionel Sambuc struct f19S (*p)(void);
191*f4a2713aSLionel Sambuc } t;
192*f4a2713aSLionel Sambuc struct f19S { int i; };
f19(void)193*f4a2713aSLionel Sambuc void f19(void) {
194*f4a2713aSLionel Sambuc t.p();
195*f4a2713aSLionel Sambuc }
196*f4a2713aSLionel Sambuc
197