xref: /aosp_15_r20/external/clang/test/Sema/pragma-pack-3.c (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -triple i686-apple-darwin9 %s -fsyntax-only -verify
2*67e74705SXin Li // expected-no-diagnostics
3*67e74705SXin Li 
4*67e74705SXin Li // Stack: [], Alignment: 8
5*67e74705SXin Li 
6*67e74705SXin Li #pragma pack(push, 1)
7*67e74705SXin Li // Stack: [8], Alignment: 1
8*67e74705SXin Li 
9*67e74705SXin Li #pragma pack(push, 4)
10*67e74705SXin Li // Stack: [8, 1], Alignment: 4
11*67e74705SXin Li 
12*67e74705SXin Li // Note that this differs from gcc; pack() in gcc appears to pop the
13*67e74705SXin Li // top stack entry and resets the current alignment. This is both
14*67e74705SXin Li // inconsistent with MSVC, and the gcc documentation. In other cases,
15*67e74705SXin Li // for example changing this to pack(8), I don't even understand what gcc
16*67e74705SXin Li // is doing.
17*67e74705SXin Li 
18*67e74705SXin Li #pragma pack()
19*67e74705SXin Li // Stack: [8, 1], Alignment: 8
20*67e74705SXin Li 
21*67e74705SXin Li #pragma pack(pop)
22*67e74705SXin Li // Stack: [8], Alignment: 1
23*67e74705SXin Li struct s0 {
24*67e74705SXin Li   char f0;
25*67e74705SXin Li   short f1;
26*67e74705SXin Li };
27*67e74705SXin Li int a[sizeof(struct s0) == 3 ? 1 : -1];
28*67e74705SXin Li 
29*67e74705SXin Li #pragma pack(pop)
30*67e74705SXin Li // Stack: [], Alignment: 8
31*67e74705SXin Li struct s1 {
32*67e74705SXin Li   char f0;
33*67e74705SXin Li   short f1;
34*67e74705SXin Li };
35*67e74705SXin Li int b[sizeof(struct s1) == 4 ? 1 : -1];
36