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