1 // RUN: %clang_cc1 %s -fsyntax-only -verify
2 // RUN: %clang_cc1 %s -fsyntax-only -triple=x86_64-windows-coff -verify
3 // RUN: %clang_cc1 %s -fsyntax-only -triple=x86_64-scei-ps4 -verify
8 int b
__attribute__((packed
));
13 extern int a1
[sizeof(struct s
) == 12 ? 1 : -1];
14 extern int a2
[__alignof(struct s
) == 4 ? 1 : -1];
16 struct __attribute__((packed
)) packed_s
{
18 int b
__attribute__((packed
));
23 extern int b1
[sizeof(struct packed_s
) == 10 ? 1 : -1];
24 extern int b2
[__alignof(struct packed_s
) == 1 ? 1 : -1];
31 extern int c1
[sizeof(struct fas
) == 4 ? 1 : -1];
32 extern int c2
[__alignof(struct fas
) == 4 ? 1 : -1];
34 struct __attribute__((packed
)) packed_fas
{
39 extern int d1
[sizeof(struct packed_fas
) == 1 ? 1 : -1];
40 extern int d2
[__alignof(struct packed_fas
) == 1 ? 1 : -1];
42 struct packed_after_fas
{
45 } __attribute__((packed
));
47 extern int d1_2
[sizeof(struct packed_after_fas
) == 1 ? 1 : -1];
48 extern int d2_2
[__alignof(struct packed_after_fas
) == 1 ? 1 : -1];
52 struct __attribute__((aligned(8))) as1
{
56 extern int e1
[sizeof(struct as1
) == 8 ? 1 : -1];
57 extern int e2
[__alignof(struct as1
) == 8 ? 1 : -1];
59 struct __attribute__((aligned
)) as1_2
{
62 #if ( defined(__s390x__) || ( defined (__ARM_32BIT_STATE) && ! defined(__ANDROID__) ) )
63 extern int e1_2
[sizeof(struct as1_2
) == 8 ? 1 : -1];
64 extern int e2_2
[__alignof(struct as1_2
) == 8 ? 1 : -1];
66 extern int e1_2
[sizeof(struct as1_2
) == 16 ? 1 : -1];
67 extern int e2_2
[__alignof(struct as1_2
) == 16 ? 1 : -1];
72 int __attribute__((aligned(8))) a
;
75 extern int f1
[sizeof(struct as2
) == 16 ? 1 : -1];
76 extern int f2
[__alignof(struct as2
) == 8 ? 1 : -1];
78 struct __attribute__((packed
)) as3
{
81 int __attribute__((aligned(8))) b
;
84 extern int g1
[sizeof(struct as3
) == 16 ? 1 : -1];
85 extern int g2
[__alignof(struct as3
) == 8 ? 1 : -1];
91 void *args
[] __attribute__((packed
));
95 union __attribute__((packed
)) au4
{char c
; int x
;};
96 extern int h1
[sizeof(union au4
) == 4 ? 1 : -1];
97 extern int h2
[__alignof(union au4
) == 1 ? 1 : -1];
100 union au5
{__attribute__((aligned(4))) char c
;};
101 extern int h1
[sizeof(union au5
) == 4 ? 1 : -1];
102 extern int h2
[__alignof(union au5
) == 4 ? 1 : -1];
105 struct as6
{char c
; __attribute__((packed
, aligned(2))) int x
;};
106 extern int i1
[sizeof(struct as6
) == 6 ? 1 : -1];
107 extern int i2
[__alignof(struct as6
) == 2 ? 1 : -1];
109 union au6
{char c
; __attribute__((packed
, aligned(2))) int x
;};
110 extern int k1
[sizeof(union au6
) == 4 ? 1 : -1];
111 extern int k2
[__alignof(union au6
) == 2 ? 1 : -1];
113 // Check postfix attributes
114 union au7
{char c
; int x
;} __attribute__((packed
));
115 extern int l1
[sizeof(union au7
) == 4 ? 1 : -1];
116 extern int l2
[__alignof(union au7
) == 1 ? 1 : -1];
121 } __attribute__((packed
));
123 extern int m1
[sizeof(struct packed_fas2
) == 1 ? 1 : -1];
124 extern int m2
[__alignof(struct packed_fas2
) == 1 ? 1 : -1];
126 // Attribute aligned can round down typedefs. PR9253
127 typedef long long __attribute__((aligned(1))) nt
;
134 #if defined(_WIN32) && !defined(__declspec) // _MSC_VER is unavailable in cc1.
135 // Alignment doesn't affect packing in MS mode.
136 extern int n1
[sizeof(struct nS
) == 16 ? 1 : -1];
137 extern int n2
[__alignof(struct nS
) == 8 ? 1 : -1];
139 extern int n1
[sizeof(struct nS
) == 9 ? 1 : -1];
140 extern int n2
[__alignof(struct nS
) == 1 ? 1 : -1];
143 // Packed attribute shouldn't be ignored for bit-field of char types.
144 // Note from GCC reference manual: The 4.1, 4.2 and 4.3 series of GCC ignore
145 // the packed attribute on bit-fields of type char. This has been fixed in
146 // GCC 4.4 but the change can lead to differences in the structure layout.
147 // See the documentation of -Wpacked-bitfield-compat for more information.
148 struct packed_chars
{
149 char a
: 8, b
: 8, c
: 8, d
: 4;
151 // Test for pre-r254596 clang behavior on the PS4 target. PS4 must maintain
152 // ABI backwards compatibility.
153 char e
: 8 __attribute__((packed
));
154 // expected-warning@-1 {{'packed' attribute ignored for field of type 'char'}}
156 char e
: 8 __attribute__((packed
));
157 // expected-warning@-1 {{'packed' attribute was ignored on bit-fields with single-byte alignment in older versions of GCC and Clang}}
159 char f
: 4, g
: 8, h
: 8, i
: 8;
162 #if (defined(_WIN32) || defined(__ORBIS__)) && !defined(__declspec) // _MSC_VER is unavailable in cc1.
163 // On Windows clang uses MSVC compatible layout in this case.
165 // Additionally, test for pre-r254596 clang behavior on the PS4 target. PS4
166 // must maintain ABI backwards compatibility.
167 extern int o1
[sizeof(struct packed_chars
) == 9 ? 1 : -1];
168 extern int o2
[__alignof(struct packed_chars
) == 1 ? 1 : -1];
170 // On AIX, char bitfields have the same alignment as unsigned int.
171 extern int o1
[sizeof(struct packed_chars
) == 8 ? 1 : -1];
172 extern int o2
[__alignof(struct packed_chars
) == 4 ? 1 : -1];
174 extern int o1
[sizeof(struct packed_chars
) == 8 ? 1 : -1];
175 extern int o2
[__alignof(struct packed_chars
) == 1 ? 1 : -1];