Daniel Dunbar | 3b0db90 | 2008-10-16 02:34:03 +0000 | [diff] [blame] | 1 | // RUN: clang -triple i686-apple-darwin9 %s -fsyntax-only -verify |
| 2 | |
| 3 | #include <stddef.h> |
| 4 | |
| 5 | #pragma pack(4) |
| 6 | |
| 7 | // Baseline |
| 8 | struct s0 { |
| 9 | char f0; |
| 10 | int f1; |
| 11 | }; |
| 12 | extern int a0[offsetof(struct s0, f1) == 4 ? 1 : -1]; |
| 13 | |
| 14 | #pragma pack(push, 2) |
| 15 | struct s1 { |
| 16 | char f0; |
| 17 | int f1; |
| 18 | }; |
| 19 | extern int a1[offsetof(struct s1, f1) == 2 ? 1 : -1]; |
| 20 | #pragma pack(pop) |
| 21 | |
| 22 | // Test scope of definition |
| 23 | |
| 24 | #pragma pack(push, 2) |
| 25 | struct s2_0 { |
| 26 | #pragma pack(pop) |
| 27 | char f0; |
| 28 | int f1; |
| 29 | }; |
| 30 | extern int a2_0[offsetof(struct s2_0, f1) == 2 ? 1 : -1]; |
| 31 | |
| 32 | struct s2_1 { |
| 33 | char f0; |
| 34 | #pragma pack(push, 2) |
| 35 | int f1; |
| 36 | #pragma pack(pop) |
| 37 | }; |
| 38 | extern int a2_1[offsetof(struct s2_1, f1) == 4 ? 1 : -1]; |
| 39 | |
| 40 | struct s2_2 { |
| 41 | char f0; |
| 42 | int f1; |
| 43 | #pragma pack(push, 2) |
| 44 | }; |
| 45 | #pragma pack(pop) |
| 46 | extern int a2_2[offsetof(struct s2_2, f1) == 4 ? 1 : -1]; |
| 47 | |
| 48 | struct s2_3 { |
| 49 | char f0; |
| 50 | #pragma pack(push, 2) |
| 51 | struct s2_3_0 { |
| 52 | #pragma pack(pop) |
| 53 | int f0; |
| 54 | } f1; |
| 55 | }; |
| 56 | extern int a2_3[offsetof(struct s2_3, f1) == 2 ? 1 : -1]; |
| 57 | |
| 58 | struct s2_4 { |
| 59 | char f0; |
| 60 | struct s2_4_0 { |
| 61 | int f0; |
| 62 | #pragma pack(push, 2) |
| 63 | } f1; |
| 64 | #pragma pack(pop) |
| 65 | }; |
| 66 | extern int a2_4[offsetof(struct s2_4, f1) == 4 ? 1 : -1]; |
Daniel Dunbar | 79cd116 | 2009-03-06 20:45:54 +0000 | [diff] [blame] | 67 | |
| 68 | #pragma pack(1) |
| 69 | struct s3_0 { |
| 70 | char f0; |
| 71 | int f1; |
| 72 | }; |
| 73 | #pragma pack() |
| 74 | struct s3_1 { |
| 75 | char f0; |
| 76 | int f1; |
| 77 | }; |
| 78 | extern int a3_0[offsetof(struct s3_0, f1) == 1 ? 1 : -1]; |
| 79 | extern int a3_1[offsetof(struct s3_1, f1) == 4 ? 1 : -1]; |
| 80 | |
| 81 | // pack(0) is like pack() |
| 82 | #pragma pack(1) |
| 83 | struct s4_0 { |
| 84 | char f0; |
| 85 | int f1; |
| 86 | }; |
| 87 | #pragma pack(0) |
| 88 | struct s4_1 { |
| 89 | char f0; |
| 90 | int f1; |
| 91 | }; |
| 92 | extern int a4_0[offsetof(struct s4_0, f1) == 1 ? 1 : -1]; |
| 93 | extern int a4_1[offsetof(struct s4_1, f1) == 4 ? 1 : -1]; |