1 // RUN: %clang_cc1 -triple=x86_64-none-none -Wpadded -Wpacked -verify=expected,top %s -emit-llvm-only
2 // RUN: %clang_cc1 -triple=x86_64-none-none -Wpadded -Wpacked -verify=expected,abi15 -fclang-abi-compat=15 %s -emit-llvm-only
3 // -Wpacked-non-pod itself should not emit the "packed attribute is unnecessary" warnings.
4 // RUN: %clang_cc1 -triple=x86_64-none-none -Wpacked-non-pod -verify=top %s -emit-llvm-only
5 // -Wall should not emit the "packed attribute is unnecessary" warnings without -Wpacked.
6 // RUN: %clang_cc1 -triple=x86_64-none-none -Wall -verify=top %s -emit-llvm-only
11 short s
; // expected-warning {{padding struct 'S1' with 1 byte to align 's'}}
12 long l
; // expected-warning {{padding struct 'S1' with 4 bytes to align 'l'}}
15 struct S2
{ // expected-warning {{padding size of 'S2' with 3 bytes to alignment boundary}}
23 } __attribute__((packed
));
28 } __attribute__((packed
));
35 } u
; // expected-warning {{padding struct 'S5' with 3 bytes to align 'u'}}
38 struct S6
{ // expected-warning {{padding size of 'S6' with 30 bits to alignment boundary}}
42 struct S7
{ // expected-warning {{padding size of 'S7' with 7 bytes to alignment boundary}}
52 int i
; // expected-warning {{padding struct 'S8' with 3 bytes to align 'i'}}
58 } __attribute__((packed
));
63 } __attribute__((packed
));
66 struct S11
{ // expected-warning {{packed attribute is unnecessary for 'S11'}}
69 } __attribute__((packed
));
73 char c
; // expected-warning {{padding struct 'S12' with 7 bits to align 'c'}}
76 struct S13
{ // expected-warning {{padding size of 'S13' with 6 bits to alignment boundary}}
81 struct S14
{ // expected-warning {{packed attribute is unnecessary for 'S14'}}
83 } __attribute__((packed
));
85 struct S15
{ // expected-warning {{packed attribute is unnecessary for 'S15'}}
88 } __attribute__((packed
));
90 struct S16
{ // expected-warning {{padding size of 'S16' with 2 bytes to alignment boundary}} expected-warning {{packed attribute is unnecessary for 'S16'}}
92 } __attribute__((packed
, aligned(4)));
97 } __attribute__((packed
, aligned(2)));
99 struct S18
{ // expected-warning {{padding size of 'S18' with 2 bytes to alignment boundary}} expected-warning {{packed attribute is unnecessary for 'S18'}}
102 } __attribute__((packed
, aligned(4)));
104 struct S19
{ // expected-warning {{packed attribute is unnecessary for 'S19'}}
107 } __attribute__((packed
, aligned(1)));
112 } __attribute__((packed
, aligned(1)));
114 struct S21
{ // expected-warning {{padding size of 'S21' with 4 bits to alignment boundary}}
117 } __attribute__((packed
, aligned(1)));
119 struct S22
{ // expected-warning {{packed attribute is unnecessary for 'S22'}}
122 } __attribute__((packed
));
124 struct S23
{ // expected-warning {{padding size of 'S23' with 4 bits to alignment boundary}} expected-warning {{packed attribute is unnecessary for 'S23'}}
127 } __attribute__((packed
));
138 } __attribute__((packed
));
140 struct S25
{ // expected-warning {{padding size of 'S25' with 7 bits to alignment boundary}} expected-warning {{packed attribute is unnecessary for 'S25'}}
143 } __attribute__((packed
));
145 struct S26
{ // expected-warning {{packed attribute is unnecessary for 'S26'}}
147 unsigned char b
; //expected-warning {{padding struct 'S26' with 7 bits to align 'b'}}
148 } __attribute__((packed
));
150 struct S27
{ // expected-warning {{padding size of 'S27' with 7 bits to alignment boundary}}
153 } __attribute__((packed
));
163 S28_non_pod p1
; // top-warning {{not packing field 'p1' as it is non-POD for the purposes of layout}}
164 } __attribute__((packed
));
166 struct S29_non_pod_align_1
{
171 S29_non_pod_align_1 p1
;
173 } __attribute__((packed
)); // no warning
174 static_assert(alignof(S29
) == 1, "");
179 } __attribute__((packed
)); // no warning
180 struct S30_use
{ // abi15-warning {{packed attribute is unnecessary for 'S30_use'}}
183 } __attribute__((packed
));
184 static_assert(sizeof(S30_use
) == 3, "");
186 // The warnings are emitted when the layout of the structs is computed, so we have to use them.
187 void f(S1
, S2
, S3
, S4
, S5
, S6
, S7
, S8
, S9
, S10
, S11
, S12
, S13
,
188 S14
, S15
, S16
, S17
, S18
, S19
, S20
, S21
, S22
, S23
, S24
, S25
,
189 S26
, S27
, S28
, S29
){}