blob: 3696a22d5aa52139d8292e29800695adf16c560a [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -triple i686-apple-darwin9 %s -fsyntax-only -verify
Andy Gibbs8e8fb3b2012-10-19 12:44:48 +00002// expected-no-diagnostics
Daniel Dunbar3b0db902008-10-16 02:34:03 +00003
4#include <stddef.h>
5
6#pragma pack(4)
7
8// Baseline
9struct s0 {
10 char f0;
11 int f1;
12};
13extern int a0[offsetof(struct s0, f1) == 4 ? 1 : -1];
14
15#pragma pack(push, 2)
16struct s1 {
17 char f0;
18 int f1;
19};
20extern int a1[offsetof(struct s1, f1) == 2 ? 1 : -1];
21#pragma pack(pop)
22
Daniel Dunbar79cd1162009-03-06 20:45:54 +000023#pragma pack(1)
24struct s3_0 {
25 char f0;
26 int f1;
27};
28#pragma pack()
29struct s3_1 {
30 char f0;
31 int f1;
32};
33extern int a3_0[offsetof(struct s3_0, f1) == 1 ? 1 : -1];
34extern int a3_1[offsetof(struct s3_1, f1) == 4 ? 1 : -1];
35
36// pack(0) is like pack()
37#pragma pack(1)
38struct s4_0 {
39 char f0;
40 int f1;
41};
42#pragma pack(0)
43struct s4_1 {
44 char f0;
45 int f1;
46};
47extern int a4_0[offsetof(struct s4_0, f1) == 1 ? 1 : -1];
48extern int a4_1[offsetof(struct s4_1, f1) == 4 ? 1 : -1];
Eli Friedmanaa5ab262012-02-23 23:47:16 +000049
50void f() {
51 #pragma pack(push, 2)
52 struct s5_0 {
53 char f0;
54 struct s2_4_0 {
55 int f0;
56 } f1;
57 };
58 #pragma pack(pop)
59 extern int s5_0[offsetof(struct s5_0, f1) == 2 ? 1 : -1];
60}