Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple i686-apple-darwin9 %s -fsyntax-only -verify |
Andy Gibbs | 8e8fb3b | 2012-10-19 12:44:48 +0000 | [diff] [blame] | 2 | // expected-no-diagnostics |
Daniel Dunbar | 3b0db90 | 2008-10-16 02:34:03 +0000 | [diff] [blame] | 3 | |
| 4 | #include <stddef.h> |
| 5 | |
| 6 | #pragma pack(4) |
| 7 | |
| 8 | // Baseline |
| 9 | struct s0 { |
| 10 | char f0; |
| 11 | int f1; |
| 12 | }; |
| 13 | extern int a0[offsetof(struct s0, f1) == 4 ? 1 : -1]; |
| 14 | |
| 15 | #pragma pack(push, 2) |
| 16 | struct s1 { |
| 17 | char f0; |
| 18 | int f1; |
| 19 | }; |
| 20 | extern int a1[offsetof(struct s1, f1) == 2 ? 1 : -1]; |
| 21 | #pragma pack(pop) |
| 22 | |
Daniel Dunbar | 79cd116 | 2009-03-06 20:45:54 +0000 | [diff] [blame] | 23 | #pragma pack(1) |
| 24 | struct s3_0 { |
| 25 | char f0; |
| 26 | int f1; |
| 27 | }; |
| 28 | #pragma pack() |
| 29 | struct s3_1 { |
| 30 | char f0; |
| 31 | int f1; |
| 32 | }; |
| 33 | extern int a3_0[offsetof(struct s3_0, f1) == 1 ? 1 : -1]; |
| 34 | extern int a3_1[offsetof(struct s3_1, f1) == 4 ? 1 : -1]; |
| 35 | |
| 36 | // pack(0) is like pack() |
| 37 | #pragma pack(1) |
| 38 | struct s4_0 { |
| 39 | char f0; |
| 40 | int f1; |
| 41 | }; |
| 42 | #pragma pack(0) |
| 43 | struct s4_1 { |
| 44 | char f0; |
| 45 | int f1; |
| 46 | }; |
| 47 | extern int a4_0[offsetof(struct s4_0, f1) == 1 ? 1 : -1]; |
| 48 | extern int a4_1[offsetof(struct s4_1, f1) == 4 ? 1 : -1]; |
Eli Friedman | aa5ab26 | 2012-02-23 23:47:16 +0000 | [diff] [blame] | 49 | |
| 50 | void 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 | } |