blob: 6ca6a6096c4ea6640bbb8bb3e2862f23f7cf1008 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 %s -fsyntax-only -verify
Anders Carlsson6a24acb2008-02-16 01:20:23 +00002
Anders Carlsson5a1b0c42008-02-16 19:51:36 +00003// Packed structs.
Anders Carlsson6a24acb2008-02-16 01:20:23 +00004struct s {
5 char a;
6 int b __attribute__((packed));
7 char c;
8 int d;
9};
10
Anders Carlsson5a1b0c42008-02-16 19:51:36 +000011extern int a1[sizeof(struct s) == 12 ? 1 : -1];
12extern int a2[__alignof(struct s) == 4 ? 1 : -1];
13
Anders Carlsson6a24acb2008-02-16 01:20:23 +000014struct __attribute__((packed)) packed_s {
15 char a;
16 int b __attribute__((packed));
17 char c;
18 int d;
19};
20
Anders Carlsson5a1b0c42008-02-16 19:51:36 +000021extern int b1[sizeof(struct packed_s) == 10 ? 1 : -1];
22extern int b2[__alignof(struct packed_s) == 1 ? 1 : -1];
23
Anders Carlsson6a24acb2008-02-16 01:20:23 +000024struct fas {
25 char a;
26 int b[];
27};
28
Anders Carlsson5a1b0c42008-02-16 19:51:36 +000029extern int c1[sizeof(struct fas) == 4 ? 1 : -1];
30extern int c2[__alignof(struct fas) == 4 ? 1 : -1];
31
Anders Carlsson6a24acb2008-02-16 01:20:23 +000032struct __attribute__((packed)) packed_fas {
33 char a;
34 int b[];
35};
36
Anders Carlsson6a24acb2008-02-16 01:20:23 +000037extern int d1[sizeof(struct packed_fas) == 1 ? 1 : -1];
38extern int d2[__alignof(struct packed_fas) == 1 ? 1 : -1];
Anders Carlsson5a1b0c42008-02-16 19:51:36 +000039
Douglas Gregor0b4c9b52010-03-29 14:42:08 +000040struct packed_after_fas {
41 char a;
42 int b[];
43} __attribute__((packed));
44
45extern int d1_2[sizeof(struct packed_after_fas) == 1 ? 1 : -1];
46extern int d2_2[__alignof(struct packed_after_fas) == 1 ? 1 : -1];
47
Anders Carlsson5a1b0c42008-02-16 19:51:36 +000048// Alignment
49
50struct __attribute__((aligned(8))) as1 {
51 char c;
52};
53
54extern int e1[sizeof(struct as1) == 8 ? 1 : -1];
55extern int e2[__alignof(struct as1) == 8 ? 1 : -1];
56
Daniel Dunbar7549c552009-02-18 20:06:09 +000057// FIXME: Will need to force arch once max usable alignment isn't hard
58// coded.
59struct __attribute__((aligned)) as1_2 {
60 char c;
61};
62extern int e1_2[sizeof(struct as1_2) == 16 ? 1 : -1];
63extern int e2_2[__alignof(struct as1_2) == 16 ? 1 : -1];
64
Anders Carlsson5a1b0c42008-02-16 19:51:36 +000065struct as2 {
66 char c;
67 int __attribute__((aligned(8))) a;
68};
69
70extern int f1[sizeof(struct as2) == 16 ? 1 : -1];
71extern int f2[__alignof(struct as2) == 8 ? 1 : -1];
72
73struct __attribute__((packed)) as3 {
74 char c;
75 int a;
76 int __attribute__((aligned(8))) b;
77};
78
79extern int g1[sizeof(struct as3) == 16 ? 1 : -1];
80extern int g2[__alignof(struct as3) == 8 ? 1 : -1];
Chris Lattnerabb57582008-05-09 05:34:49 +000081
82
83// rdar://5921025
84struct packedtest {
85 int ted_likes_cheese;
86 void *args[] __attribute__((packed));
87};
Eli Friedman4bd998b2008-05-30 09:31:38 +000088
89// Packed union
90union __attribute__((packed)) au4 {char c; int x;};
91extern int h1[sizeof(union au4) == 4 ? 1 : -1];
92extern int h2[__alignof(union au4) == 1 ? 1 : -1];
93
94// Aligned union
95union au5 {__attribute__((aligned(4))) char c;};
96extern int h1[sizeof(union au5) == 4 ? 1 : -1];
97extern int h2[__alignof(union au5) == 4 ? 1 : -1];
98
99// Alignment+packed
100struct as6 {char c; __attribute__((packed, aligned(2))) int x;};
101extern int i1[sizeof(struct as6) == 6 ? 1 : -1];
102extern int i2[__alignof(struct as6) == 2 ? 1 : -1];
103
104union au6 {char c; __attribute__((packed, aligned(2))) int x;};
105extern int k1[sizeof(union au6) == 4 ? 1 : -1];
106extern int k2[__alignof(union au6) == 2 ? 1 : -1];
107
Daniel Dunbar7d076642008-10-03 17:33:35 +0000108// Check postfix attributes
109union au7 {char c; int x;} __attribute__((packed));
110extern int l1[sizeof(union au7) == 4 ? 1 : -1];
111extern int l2[__alignof(union au7) == 1 ? 1 : -1];
112
113struct packed_fas2 {
114 char a;
115 int b[];
116} __attribute__((packed));
117
118extern int m1[sizeof(struct packed_fas2) == 1 ? 1 : -1];
119extern int m2[__alignof(struct packed_fas2) == 1 ? 1 : -1];
Chris Lattnerc1de52d2011-02-19 22:55:41 +0000120
121// Attribute aligned can round down typedefs. PR9253
122typedef long long __attribute__((aligned(1))) nt;
123
124struct nS {
125 char buf_nr;
126 nt start_lba;
127};
128
129extern int n1[sizeof(struct nS) == 9 ? 1 : -1];
130extern int n2[__alignof(struct nS) == 1 ? 1 : -1];
131
132
133
134