blob: 8173f0f2827271694d9145e6c4b50c010b1f2999 [file] [log] [blame]
Anders Carlsson6a24acb2008-02-16 01:20:23 +00001// RUN: clang %s -fsyntax-only -verify
2
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
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];
Chris Lattnerabb57582008-05-09 05:34:49 +000065
66
67// rdar://5921025
68struct packedtest {
69 int ted_likes_cheese;
70 void *args[] __attribute__((packed));
71};
Eli Friedman4bd998b2008-05-30 09:31:38 +000072
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
Daniel Dunbar7d076642008-10-03 17:33:35 +000092// 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];