struct-packed-align.c revision a5728872c7702ddd09537c95bc3cbd20e1f2fb09
1// RUN: %clang_cc1 %s -fsyntax-only -verify 2 3// Packed structs. 4struct s { 5 char a; 6 int b __attribute__((packed)); 7 char c; 8 int d; 9}; 10 11extern int a1[sizeof(struct s) == 12 ? 1 : -1]; 12extern int a2[__alignof(struct s) == 4 ? 1 : -1]; 13 14struct __attribute__((packed)) packed_s { 15 char a; 16 int b __attribute__((packed)); 17 char c; 18 int d; 19}; 20 21extern int b1[sizeof(struct packed_s) == 10 ? 1 : -1]; 22extern int b2[__alignof(struct packed_s) == 1 ? 1 : -1]; 23 24struct fas { 25 char a; 26 int b[]; 27}; 28 29extern int c1[sizeof(struct fas) == 4 ? 1 : -1]; 30extern int c2[__alignof(struct fas) == 4 ? 1 : -1]; 31 32struct __attribute__((packed)) packed_fas { 33 char a; 34 int b[]; 35}; 36 37extern int d1[sizeof(struct packed_fas) == 1 ? 1 : -1]; 38extern int d2[__alignof(struct packed_fas) == 1 ? 1 : -1]; 39 40// Alignment 41 42struct __attribute__((aligned(8))) as1 { 43 char c; 44}; 45 46extern int e1[sizeof(struct as1) == 8 ? 1 : -1]; 47extern int e2[__alignof(struct as1) == 8 ? 1 : -1]; 48 49// FIXME: Will need to force arch once max usable alignment isn't hard 50// coded. 51struct __attribute__((aligned)) as1_2 { 52 char c; 53}; 54extern int e1_2[sizeof(struct as1_2) == 16 ? 1 : -1]; 55extern int e2_2[__alignof(struct as1_2) == 16 ? 1 : -1]; 56 57struct as2 { 58 char c; 59 int __attribute__((aligned(8))) a; 60}; 61 62extern int f1[sizeof(struct as2) == 16 ? 1 : -1]; 63extern int f2[__alignof(struct as2) == 8 ? 1 : -1]; 64 65struct __attribute__((packed)) as3 { 66 char c; 67 int a; 68 int __attribute__((aligned(8))) b; 69}; 70 71extern int g1[sizeof(struct as3) == 16 ? 1 : -1]; 72extern int g2[__alignof(struct as3) == 8 ? 1 : -1]; 73 74 75// rdar://5921025 76struct packedtest { 77 int ted_likes_cheese; 78 void *args[] __attribute__((packed)); 79}; 80 81// Packed union 82union __attribute__((packed)) au4 {char c; int x;}; 83extern int h1[sizeof(union au4) == 4 ? 1 : -1]; 84extern int h2[__alignof(union au4) == 1 ? 1 : -1]; 85 86// Aligned union 87union au5 {__attribute__((aligned(4))) char c;}; 88extern int h1[sizeof(union au5) == 4 ? 1 : -1]; 89extern int h2[__alignof(union au5) == 4 ? 1 : -1]; 90 91// Alignment+packed 92struct as6 {char c; __attribute__((packed, aligned(2))) int x;}; 93extern int i1[sizeof(struct as6) == 6 ? 1 : -1]; 94extern int i2[__alignof(struct as6) == 2 ? 1 : -1]; 95 96union au6 {char c; __attribute__((packed, aligned(2))) int x;}; 97extern int k1[sizeof(union au6) == 4 ? 1 : -1]; 98extern int k2[__alignof(union au6) == 2 ? 1 : -1]; 99 100// Check postfix attributes 101union au7 {char c; int x;} __attribute__((packed)); 102extern int l1[sizeof(union au7) == 4 ? 1 : -1]; 103extern int l2[__alignof(union au7) == 1 ? 1 : -1]; 104 105struct packed_fas2 { 106 char a; 107 int b[]; 108} __attribute__((packed)); 109 110extern int m1[sizeof(struct packed_fas2) == 1 ? 1 : -1]; 111extern int m2[__alignof(struct packed_fas2) == 1 ? 1 : -1]; 112