blob: 9af684b1140eec399cb2da221a440a1ede5764ab [file] [log] [blame]
Daniel Dunbar2d6ca8d2008-08-21 02:51:29 +00001// RUN: clang %s -emit-llvm -o %t
Devang Patelb9b00ad2007-10-23 20:28:39 +00002
3struct {
4 int x;
5 int y;
6} point;
7
8void fn1() {
9 point.x = 42;
10}
11
12/* Nested member */
13struct {
14 struct {
15 int a;
16 int b;
17 } p1;
18} point2;
19
20void fn2() {
21 point2.p1.a = 42;
22}
23
24/* Indirect reference */
25typedef struct __sf {
26 unsigned char *c;
27 short flags;
28} F;
29
30typedef struct __sf2 {
31 F *ff;
32} F2;
33
34int fn3(F2 *c) {
35 if (c->ff->c >= 0)
36 return 1;
37 else
38 return 0;
39}
Devang Patelb1e39892007-10-23 23:26:46 +000040
41/* Nested structs */
42typedef struct NA {
43 int data;
44 struct NA *next;
45} NA;
Devang Pateldbb46b12007-10-23 23:29:51 +000046void f1() { NA a; }
Devang Patelb1e39892007-10-23 23:26:46 +000047
48typedef struct NB {
49 int d1;
50 struct _B2 {
51 int d2;
52 struct NB *n2;
53 } B2;
54} NB;
55
56void f2() { NB b; }
57
Devang Patel126a8562007-10-24 22:26:28 +000058extern NB *f3();
59void f4() {
60 f3()->d1 = 42;
61}
Devang Patel0a961182007-10-26 18:15:21 +000062
63void f5() {
64 (f3())->d1 = 42;
65}
Anders Carlsson148fe672007-10-31 22:04:46 +000066
67/* Function calls */
68typedef struct {
69 int location;
70 int length;
71} range;
72
73extern range f6();
74void f7()
75{
Anders Carlssona1ff3e92007-11-02 16:59:10 +000076 range r = f6();
77}
78
79/* Member expressions */
80typedef struct {
81 range range1;
82 range range2;
83} rangepair;
84
85void f8()
86{
87 rangepair p;
88
89 range r = p.range1;
Anders Carlsson148fe672007-10-31 22:04:46 +000090}
91
Seo Sanghyeon7777bb22007-12-14 01:09:11 +000092void f9(range *p)
93{
94 range r = *p;
95}
Anders Carlsson148fe672007-10-31 22:04:46 +000096
Seo Sanghyeon9b73b392007-12-14 02:04:12 +000097void f10(range *p)
98{
99 range r = p[0];
100}
101
Devang Patel14c75002007-12-10 18:25:34 +0000102/* _Bool types */
103
104struct _w
105{
106 short a,b;
107 short c,d;
108 short e,f;
109 short g;
110
111 unsigned int h,i;
112
113 _Bool j,k;
114} ws;
Anders Carlssone4707ff2008-01-14 06:28:57 +0000115
116/* Implicit casts (due to typedefs) */
117typedef struct _a
118{
119 int a;
120} a;
121
122void f11()
123{
124 struct _a a1;
125 a a2;
126
127 a1 = a2;
128 a2 = a1;
129}
Anders Carlssona46b7592008-01-18 02:25:57 +0000130
131/* Implicit casts (due to const) */
132void f12()
133{
134 struct _a a1;
135 const struct _a a2;
136
137 a1 = a2;
Devang Patel47fb6972008-01-29 23:23:18 +0000138}
139
140/* struct initialization */
Eli Friedman75afb582008-02-06 05:33:51 +0000141struct a13 {int b; int c;};
Devang Patel47fb6972008-01-29 23:23:18 +0000142struct a13 c13 = {5};
Devang Patelbf20b682008-05-27 22:44:22 +0000143typedef struct a13 a13;
Devang Pateleae15602008-02-05 02:39:50 +0000144struct a14 { short a; int b; } x = {1, 1};
Eli Friedman75afb582008-02-06 05:33:51 +0000145
146/* flexible array members */
147struct a15 {char a; int b[];} c15;
148int a16(void) {c15.a = 1;}
Eli Friedmanb1851242008-05-27 15:51:49 +0000149
150/* compound literals */
151void f13()
152{
153 a13 x; x = (a13){1,2};
154}
155
156/* va_arg */
157int f14(int i, ...) {
158 __builtin_va_list l;
159 __builtin_va_start(l,i);
160 a13 b = __builtin_va_arg(l, a13);
161 return b.b;
162}
Devang Patel2fb86e62008-05-27 22:45:40 +0000163
164/* Attribute packed */
165struct __attribute__((packed)) S2839 { double a[19]; signed char b; } s2839[5];
Eli Friedman0408f682008-05-29 10:58:49 +0000166
167struct __attribute__((packed)) SS { long double a; char b; } SS;
168