1 // RUN: %clang_analyze_cc1 -triple x86_64-unknown-linux -std=c++14 -analyzer-checker=optin.performance -analyzer-config optin.performance.Padding:AllowedPad=2 -verify %s
3 // expected-warning@+7{{\
4 Excessive padding in
'struct IntSandwich' (6 padding bytes
, where
2 is optimal
). \
5 Optimal fields order
: \
16 // expected-warning@+7{{\
17 Excessive padding in
'struct TurDuckHen' (6 padding bytes
, where
2 is optimal
). \
18 Optimal fields order
: \
31 // expected-warning@+11{{\
32 Excessive padding in
'struct SmallIntSandwich' (4 padding bytes
, where
0 is optimal
). \
33 Optimal fields order
: \
42 struct SmallIntSandwich
{
53 union SomeUnion
{ // no-warning
59 // expected-warning@+7{{\
60 Excessive padding in
'struct HoldsAUnion' (6 padding bytes
, where
2 is optimal
). \
61 Optimal fields order
: \
72 struct SmallCharArray
{ // no-warning
76 struct MediumIntArray
{ // no-warning
80 // expected-warning@+7{{\
81 Excessive padding in
'struct StructSandwich' (6 padding bytes
, where
2 is optimal
). \
82 Optimal fields order
: \
87 struct StructSandwich
{
88 struct SmallCharArray s
;
89 struct MediumIntArray m
;
90 struct SmallCharArray s2
;
93 // expected-warning@+7{{\
94 Excessive padding in
'TypedefSandwich' (6 padding bytes
, where
2 is optimal
). \
95 Optimal fields order
: \
106 // expected-warning@+7{{\
107 Excessive padding in
'struct StructAttrAlign' (10 padding bytes
, where
2 is optimal
). \
108 Optimal fields order
: \
113 struct StructAttrAlign
{
117 } __attribute__((aligned(8)));
119 // expected-warning@+8{{\
120 Excessive padding in
'struct OverlyAlignedChar' (8185 padding bytes
, where
4089 is optimal
). \
121 Optimal fields order
: \
127 struct OverlyAlignedChar
{
131 char c
__attribute__((aligned(4096)));
134 // expected-warning@+7{{\
135 Excessive padding in
'struct HoldsOverlyAlignedChar' (8190 padding bytes
, where
4094 is optimal
). \
136 Optimal fields order
: \
141 struct HoldsOverlyAlignedChar
{
143 struct OverlyAlignedChar o
;
147 void internalStructFunc() {
148 // expected-warning@+7{{\
149 Excessive padding in
'struct X' (6 padding bytes
, where
2 is optimal
). \
150 Optimal fields order
: \
163 void typedefStructFunc() {
164 // expected-warning@+7{{\
165 Excessive padding in
'S' (6 padding bytes
, where
2 is optimal
). \
166 Optimal fields order
: \
179 // expected-warning@+7{{\
180 Excessive padding in
'struct DefaultAttrAlign' (22 padding bytes
, where
6 is optimal
). \
181 Optimal fields order
: \
186 struct DefaultAttrAlign
{
190 } __attribute__((aligned
));
192 // expected-warning@+7{{\
193 Excessive padding in
'struct SmallArrayShortSandwich' (2 padding bytes
, where
0 is optimal
). \
194 Optimal fields order
: \
199 struct SmallArrayShortSandwich
{
205 // expected-warning@+7{{\
206 Excessive padding in
'struct SmallArrayInFunc' (2 padding bytes
, where
0 is optimal
). \
207 Optimal fields order
: \
212 struct SmallArrayInFunc
{
219 struct SmallArrayInFunc Arr
[15];
222 // expected-warning@+7{{\
223 Excessive padding in
'class VirtualIntSandwich' (10 padding bytes
, where
2 is optimal
). \
224 Optimal fields order
: \
229 class VirtualIntSandwich
{
230 virtual void foo() {}
236 // constructed so as not to have tail padding
237 // expected-warning@+8{{\
238 Excessive padding in
'class InnerPaddedB' (6 padding bytes
, where
2 is optimal
). \
239 Optimal fields order
: \
252 class Empty
{}; // no-warning
254 // expected-warning@+7{{\
255 Excessive padding in
'class LotsOfSpace' (6 padding bytes
, where
2 is optimal
). \
256 Optimal fields order
: \
267 // expected-warning@+7{{\
268 Excessive padding in
'struct TypedefSandwich2' (6 padding bytes
, where
2 is optimal
). \
269 Optimal fields order
: \
274 typedef struct TypedefSandwich2
{
276 // expected-warning@+7{{\
277 Excessive padding in
'TypedefSandwich2::NestedTypedef' (6 padding bytes
, where
2 is optimal
). \
278 Optimal fields order
: \
292 template <typename T
>
294 // expected-warning@+7{{\
295 Excessive padding in
'struct Foo<int>::Nested' (6 padding bytes
, where
2 is optimal
). \
296 Optimal fields order
: \
308 struct Holder
{ // no-warning
310 Foo
<char>::Nested t2
;