1 // RUN: %clang_cc1 -fsyntax-only -verify %s
6 extern void f2(char *);
13 struct __attribute__((packed
)) Arguable
{
19 union __attribute__((packed
)) UnionArguable
{
24 typedef struct Arguable ArguableT
;
26 struct Arguable
*get_arguable(void);
29 void to_intptr(intptr_t);
34 f1(&ok
.x
); // no-warning
35 f2(&ok
.c
); // no-warning
38 struct Arguable arguable
;
39 f2(&arguable
.c0
); // no-warning
40 f1(&arguable
.x
); // expected-warning {{packed member 'x' of class or structure 'Arguable'}}
41 f2(&arguable
.c1
); // no-warning
43 f1((int *)(void *)&arguable
.x
); // no-warning
44 to_void(&arguable
.x
); // no-warning
45 void *p
= &arguable
.x
; // no-warning
47 to_intptr((intptr_t)p
); // no-warning
50 union UnionArguable arguable
;
51 f2(&arguable
.c
); // no-warning
52 f1(&arguable
.x
); // expected-warning {{packed member 'x' of class or structure 'UnionArguable'}}
54 f1((int *)(void *)&arguable
.x
); // no-warning
55 to_void(&arguable
.x
); // no-warning
56 to_intptr((intptr_t)&arguable
.x
); // no-warning
60 f2(&arguable
.c0
); // no-warning
61 f1(&arguable
.x
); // expected-warning {{packed member 'x' of class or structure 'Arguable'}}
62 f2(&arguable
.c1
); // no-warning
64 f1((int *)(void *)&arguable
.x
); // no-warning
65 to_void(&arguable
.x
); // no-warning
66 to_intptr((intptr_t)&arguable
.x
); // no-warning
69 struct Arguable
*arguable
= get_arguable();
70 f2(&arguable
->c0
); // no-warning
71 f1(&arguable
->x
); // expected-warning {{packed member 'x' of class or structure 'Arguable'}}
72 f2(&arguable
->c1
); // no-warning
74 f1((int *)(void *)&arguable
->x
); // no-warning
75 to_void(&arguable
->c1
); // no-warning
76 to_intptr((intptr_t)&arguable
->c1
); // no-warning
79 ArguableT
*arguable
= get_arguable();
80 f2(&(arguable
->c0
)); // no-warning
81 f1(&(arguable
->x
)); // expected-warning {{packed member 'x' of class or structure 'Arguable'}}
82 f2(&(arguable
->c1
)); // no-warning
84 f1((int *)(void *)&(arguable
->x
)); // no-warning
85 to_void(&(arguable
->c1
)); // no-warning
86 to_intptr((intptr_t)&(arguable
->c1
)); // no-warning
92 int i
__attribute__((packed
));
95 int *g1(struct S1
*s1
) {
96 return &s1
->i
; // expected-warning {{packed member 'i' of class or structure 'S1'}}
102 struct __attribute__((packed
)) S2
{
107 int *g2(struct S2
*s2
) {
108 return &s2
->inner
.i
; // expected-warning {{packed member 'inner' of class or structure 'S2'}}
113 struct S2_i inner
__attribute__((packed
));
116 int *g2_a(struct S2_a
*s2_a
) {
117 return &s2_a
->inner
.i
; // expected-warning {{packed member 'inner' of class or structure 'S2_a'}}
120 struct __attribute__((packed
)) S3
{
127 int *g3(struct S3
*s3
) {
128 return &s3
->inner
.i
; // expected-warning {{packed member 'inner' of class or structure 'S3'}}
133 struct __attribute__((packed
)) {
138 int *g4(struct S4
*s4
) {
139 return &s4
->inner
.i
; // expected-warning {{packed member 'i' of class or structure 'S4::struct (unnamed at}}
146 int i
__attribute__((packed
));
150 int *g5(struct S5
*s5
) {
151 return &s5
->inner
.i
; // expected-warning {{packed member 'i' of class or structure 'S5::struct (unnamed at}}
154 struct __attribute__((packed
, aligned(2))) AlignedTo2
{
158 char *g6(struct AlignedTo2
*s
) {
159 return (char *)&s
->x
; // no-warning
162 struct __attribute__((packed
, aligned(2))) AlignedTo2Bis
{
166 struct AlignedTo2Bis
* g7(struct AlignedTo2
*s
)
168 return (struct AlignedTo2Bis
*)&s
->x
; // no-warning
174 } __attribute__((packed
)) TypedefStructArguable
;
179 } __attribute((packed
)) TypedefUnionArguable
;
181 typedef TypedefStructArguable TypedefStructArguableTheSecond
;
183 int *typedef1(TypedefStructArguable
*s
) {
184 return &s
->x
; // expected-warning {{packed member 'x' of class or structure 'TypedefStructArguable'}}
187 int *typedef2(TypedefStructArguableTheSecond
*s
) {
188 return &s
->x
; // expected-warning {{packed member 'x' of class or structure 'TypedefStructArguable'}}
191 int *typedef3(TypedefUnionArguable
*s
) {
192 return &s
->x
; // expected-warning {{packed member 'x' of class or structure 'TypedefUnionArguable'}}
199 } __attribute__((packed
));
202 int *anonymousInnerUnion(struct S6
*s
) {
203 return &s
->x
; // expected-warning {{packed member 'x' of class or structure 'S6::union (anonymous at}}
212 } __attribute__((packed
, aligned(16))) s6
;
216 f1(&s6
.a
); // no-warning
217 f1(&s6
.c
); // no-warning
218 f1(&s6
.d
); // expected-warning {{packed member 'd' of class or structure 'S6a'}}
221 struct __attribute__((packed
, aligned(1))) MisalignedContainee
{ double d
; };
222 struct __attribute__((aligned(8))) AlignedContainer
{ struct MisalignedContainee b
; };
224 struct AlignedContainer
*p
;
226 return &p
->b
.d
; // no-warning
235 struct __attribute__((packed
)) S7
{
239 union OneUnion one_union
;
247 union OneUnion
* get_OneUnion(void)
249 return &au
->s
.one_union
; // no-warning
252 struct __attribute__((packed
)) S8
{
258 #define LE_READ_2(p) \
260 ((((const uint8_t *)(p))[0] ) | \
261 (((const uint8_t *)(p))[1] << 8)))
263 uint32_t get_wider_data(struct S8
*s
)
265 return LE_READ_2(&s
->wider_data
); // no-warning
272 } __attribute__((__packed__
));
274 typedef struct S9
__attribute__((__aligned__(16))) aligned_S9
;
278 struct S9
__attribute__((__aligned__(8))) y
;
282 p32
= &x
.x
; // expected-warning {{packed member 'x' of class or structure 'S9'}}
283 p32
= &y
.x
; // no-warning
284 p32
= &z
.x
; // no-warning
290 int32_t msgh_voucher_port
;
302 } __attribute__((aligned(8), packed
)) a
;
307 } __attribute__((aligned(8), packed
)) b
;
309 } __attribute__((aligned(8), packed
)) S10Data
;
315 S10Data data
[] __attribute__((aligned(8)));
316 } __attribute__((aligned(8), packed
)) S10
;
318 void g11(S10Header
*hdr
);
320 g11(&s
->hdr
); // no-warning
325 } __attribute__((__packed__
));
328 struct S11
__attribute__((__aligned__(4))) a
[4];
330 p32
= &a
[0].x
; // no-warning
335 struct fwd f
; // expected-error {{incomplete type}} expected-note {{forward declaration}}
336 } __attribute__((packed
));
338 void *g14(struct Invalid0
*ivl
) {