struct-packed-align.c revision 7d076643e77a941cd1e53ed4a328df64c88140a5
1// RUN: clang %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 49struct as2 { 50 char c; 51 int __attribute__((aligned(8))) a; 52}; 53 54extern int f1[sizeof(struct as2) == 16 ? 1 : -1]; 55extern int f2[__alignof(struct as2) == 8 ? 1 : -1]; 56 57struct __attribute__((packed)) as3 { 58 char c; 59 int a; 60 int __attribute__((aligned(8))) b; 61}; 62 63extern int g1[sizeof(struct as3) == 16 ? 1 : -1]; 64extern int g2[__alignof(struct as3) == 8 ? 1 : -1]; 65 66 67// rdar://5921025 68struct packedtest { 69 int ted_likes_cheese; 70 void *args[] __attribute__((packed)); 71}; 72 73// Packed union 74union __attribute__((packed)) au4 {char c; int x;}; 75extern int h1[sizeof(union au4) == 4 ? 1 : -1]; 76extern int h2[__alignof(union au4) == 1 ? 1 : -1]; 77 78// Aligned union 79union au5 {__attribute__((aligned(4))) char c;}; 80extern int h1[sizeof(union au5) == 4 ? 1 : -1]; 81extern int h2[__alignof(union au5) == 4 ? 1 : -1]; 82 83// Alignment+packed 84struct as6 {char c; __attribute__((packed, aligned(2))) int x;}; 85extern int i1[sizeof(struct as6) == 6 ? 1 : -1]; 86extern int i2[__alignof(struct as6) == 2 ? 1 : -1]; 87 88union au6 {char c; __attribute__((packed, aligned(2))) int x;}; 89extern int k1[sizeof(union au6) == 4 ? 1 : -1]; 90extern int k2[__alignof(union au6) == 2 ? 1 : -1]; 91 92// Check postfix attributes 93union au7 {char c; int x;} __attribute__((packed)); 94extern int l1[sizeof(union au7) == 4 ? 1 : -1]; 95extern int l2[__alignof(union au7) == 1 ? 1 : -1]; 96 97struct packed_fas2 { 98 char a; 99 int b[]; 100} __attribute__((packed)); 101 102extern int m1[sizeof(struct packed_fas2) == 1 ? 1 : -1]; 103extern int m2[__alignof(struct packed_fas2) == 1 ? 1 : -1]; 104