* gcc.dg/const-elim-1.c: xfail for xtensa.
[official-gcc.git] / gcc / testsuite / gcc.dg / pack-test-1.c
blob4d54647918ee6d9b0ccf9ed59abfbc9e9b41fe6a
1 /* Test semantics of #pragma pack.
2 Contributed by Mike Coleman <mcoleman2@kc.rr.com> */
4 /* { dg-do compile { target *-*-linux* *-*-cygwin* powerpc*-*-eabi* } } */
6 /* We only test the alignment of char, short, and int, because these
7 are the only ones that are pretty certain to be the same across
8 platforms (and maybe not even those). Mainly we're just testing
9 whether pushing and popping seem to be working correctly, and
10 verifying the (alignment == 1) case, which is really the only
11 reason anyone would use this pragma anyway.
14 #include <stddef.h>
16 /* gap in bytes between fields a and b in struct s */
17 #define gap(s, a, b) (offsetof(struct s, a) - offsetof(struct s, b))
18 /* generalized compile-time test expression */
19 #define test(n, expr) int test_##n [(expr) ? 1 : -1]
20 /* test a gap */
21 #define testgap(n, a, b, val) test(n, gap(SNAME, a, b) == val)
23 #define SNAME s0
24 #include "pack-test-1.h"
26 /* Save original alignment values. Can't use const ints because they
27 won't be expanded and we'll get bogus errors about variable length
28 arrays. (Possible bug in C front end?) Use s0, not SNAME, so these
29 won't change later. */
30 #define al1 gap(s0, f1, f0)
31 #define al2 gap(s0, f2, f1)
32 #define al3 gap(s0, f3, f2)
33 #define al4 gap(s0, f4, f3)
34 #define al5 gap(s0, f5, f4)
35 #define al6 gap(s0, f6, f5)
36 #define al7 gap(s0, f7, f6)
38 #undef SNAME
39 #define SNAME s1
40 #pragma pack(push, p1, 1)
41 #include "pack-test-1.h"
43 void SNAME() {
44 testgap(0, f1, f0, sizeof(char));
45 testgap(1, f3, f2, sizeof(short));
46 testgap(2, f5, f4, sizeof(int));
49 #undef SNAME
50 #define SNAME s2
51 #pragma pack(push, p2, 2)
52 #include "pack-test-1.h"
54 void SNAME() {
55 testgap(0, f1, f0, sizeof(short));
56 testgap(1, f3, f2, sizeof(short));
57 testgap(2, f5, f4, sizeof(int));
60 #undef SNAME
61 #define SNAME s3
62 #pragma pack(push, p3, 4)
63 #include "pack-test-1.h"
65 void SNAME() {
66 testgap(0, f1, f0, sizeof(int));
67 testgap(1, f3, f2, sizeof(int));
68 testgap(2, f5, f4, sizeof(int));
71 #undef SNAME
72 #define SNAME s4
73 #pragma pack(pop)
74 #include "pack-test-1.h"
76 void SNAME() {
77 testgap(0, f1, f0, sizeof(short));
78 testgap(1, f3, f2, sizeof(short));
79 testgap(2, f5, f4, sizeof(int));
82 #undef SNAME
83 #define SNAME s5
84 #pragma pack(pop, p2)
85 #include "pack-test-1.h"
87 void SNAME() {
88 testgap(0, f1, f0, sizeof(char));
89 testgap(1, f3, f2, sizeof(short));
90 testgap(2, f5, f4, sizeof(int));
93 #undef SNAME
94 #define SNAME s6
95 #pragma pack(pop, p1)
96 #include "pack-test-1.h"
98 void SNAME() {
99 testgap(0, f1, f0, al1);
100 testgap(1, f3, f2, al3);
101 testgap(2, f5, f4, al5);
104 #undef SNAME
105 #define SNAME s7
106 #pragma pack(1)
107 #include "pack-test-1.h"
109 void SNAME() {
110 testgap(0, f1, f0, sizeof(char));
111 testgap(1, f3, f2, sizeof(short));
112 testgap(2, f5, f4, sizeof(int));
115 #undef SNAME
116 #define SNAME s8
117 #pragma pack(push, p2, 2)
118 #include "pack-test-1.h"
120 void SNAME() {
121 testgap(0, f1, f0, sizeof(short));
122 testgap(1, f3, f2, sizeof(short));
123 testgap(2, f5, f4, sizeof(int));
126 #undef SNAME
127 #define SNAME s9
128 #pragma pack(pop)
129 #include "pack-test-1.h"
131 void SNAME() {
132 testgap(0, f1, f0, sizeof(char));
133 testgap(1, f3, f2, sizeof(short));
134 testgap(2, f5, f4, sizeof(int));
137 #undef SNAME
138 #define SNAME s10
139 #pragma pack()
140 #include "pack-test-1.h"
142 void SNAME() {
143 testgap(0, f1, f0, al1);
144 testgap(1, f3, f2, al3);
145 testgap(2, f5, f4, al5);