struct.c revision 292d4f9a1aaa37ad052ed50896c803fa3a98f77c
1// RUN: clang -triple i386-unknown-unknown %s -emit-llvm -o - 2 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} 40 41/* Nested structs */ 42typedef struct NA { 43 int data; 44 struct NA *next; 45} NA; 46void f1() { NA a; } 47 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 58extern NB *f3(); 59void f4() { 60 f3()->d1 = 42; 61} 62 63void f5() { 64 (f3())->d1 = 42; 65} 66 67/* Function calls */ 68typedef struct { 69 int location; 70 int length; 71} range; 72extern range f6(); 73void f7() 74{ 75 range r = f6(); 76} 77 78/* Member expressions */ 79typedef struct { 80 range range1; 81 range range2; 82} rangepair; 83 84void f8() 85{ 86 rangepair p; 87 88 range r = p.range1; 89} 90 91void f9(range *p) 92{ 93 range r = *p; 94} 95 96void f10(range *p) 97{ 98 range r = p[0]; 99} 100 101/* _Bool types */ 102 103struct _w 104{ 105 short a,b; 106 short c,d; 107 short e,f; 108 short g; 109 110 unsigned int h,i; 111 112 _Bool j,k; 113} ws; 114 115/* Implicit casts (due to typedefs) */ 116typedef struct _a 117{ 118 int a; 119} a; 120 121void f11() 122{ 123 struct _a a1; 124 a a2; 125 126 a1 = a2; 127 a2 = a1; 128} 129 130/* Implicit casts (due to const) */ 131void f12() 132{ 133 struct _a a1; 134 const struct _a a2; 135 136 a1 = a2; 137} 138 139/* struct initialization */ 140struct a13 {int b; int c;}; 141struct a13 c13 = {5}; 142typedef struct a13 a13; 143struct a14 { short a; int b; } x = {1, 1}; 144 145/* flexible array members */ 146struct a15 {char a; int b[];} c15; 147int a16(void) {c15.a = 1;} 148 149/* compound literals */ 150void f13() 151{ 152 a13 x; x = (a13){1,2}; 153} 154 155/* va_arg */ 156int f14(int i, ...) { 157 __builtin_va_list l; 158 __builtin_va_start(l,i); 159 a13 b = __builtin_va_arg(l, a13); 160 return b.b; 161} 162 163/* Attribute packed */ 164struct __attribute__((packed)) S2839 { double a[19]; signed char b; } s2839[5]; 165 166struct __attribute__((packed)) SS { long double a; char b; } SS; 167 168 169/* As lvalue */ 170 171int f15() { 172 extern range f15_ext(); 173 return f15_ext().location; 174} 175 176range f16() { 177 extern rangepair f16_ext(); 178 return f16_ext().range1; 179} 180 181int f17() { 182 extern range f17_ext(); 183 range r; 184 return (r = f17_ext()).location; 185} 186 187range f18() { 188 extern rangepair f18_ext(); 189 rangepair rp; 190 return (rp = f18_ext()).range1; 191} 192