1 // RUN: %clang_analyze_cc1 -verify %s \
2 // RUN: -analyzer-checker=optin.performance \
3 // RUN: -analyzer-config optin.performance.Padding:AllowedPad=2
5 // RUN: not %clang_analyze_cc1 -verify %s \
6 // RUN: -analyzer-checker=core \
7 // RUN: -analyzer-checker=optin.performance.Padding \
8 // RUN: -analyzer-config optin.performance.Padding:AllowedPad=-10 \
9 // RUN: 2>&1 | FileCheck %s -check-prefix=CHECK-PAD-NEGATIVE-VALUE
11 // CHECK-PAD-NEGATIVE-VALUE: (frontend): invalid input for checker option
12 // CHECK-PAD-NEGATIVE-VALUE-SAME: 'optin.performance.Padding:AllowedPad', that
13 // CHECK-PAD-NEGATIVE-VALUE-SAME: expects a non-negative value
15 #if __has_include(<stdalign.h>)
19 #if __has_include(<stdalign.h>) || defined(__cplusplus)
20 // expected-warning@+1{{Excessive padding in 'struct FieldAttrAlign' (6 padding}}
21 struct FieldAttrAlign
{
27 // expected-warning@+1{{Excessive padding in 'struct FieldAttrOverAlign' (10 padding}}
28 struct FieldAttrOverAlign
{
34 #endif // __has_include(<stdalign.h>) || defined(__cplusplus)
36 // Re-ordering members of these structs won't reduce padding, so don't warn
37 struct LeadingChar
{ // no-warning
42 struct TrailingChar
{ // no-warning
47 struct Helpless
{ // no-warning
48 struct TrailingChar i1
;
49 struct LeadingChar i2
;
55 struct SquishedIntSandwich
{ // no-warning
62 // Re-ordering members of these structs will reduce padding, so warn
63 struct IntSandwich
{ // expected-warning{{Excessive padding in 'struct IntSandwich'}}
69 struct TurDuckHen
{ // expected-warning{{Excessive padding in 'struct TurDuckHen'}}
77 struct SmallIntSandwich
{ // expected-warning{{Excessive padding in 'struct SmallIntSandwich'}}
88 union SomeUnion
{ // no-warning
94 struct HoldsAUnion
{ // expected-warning{{Excessive padding in 'struct HoldsAUnion'}}
100 struct BigCharArray
{ // no-warning
104 struct SmallCharArray
{ // no-warning
108 struct MediumIntArray
{ // no-warning
112 struct LargeSizeToSmallSize
{ // expected-warning{{Excessive padding in 'struct LargeSizeToSmallSize'}}
113 struct BigCharArray b
;
114 struct MediumIntArray m
;
115 struct SmallCharArray s
;
118 struct LargeAlignToSmallAlign
{ // no-warning
119 struct MediumIntArray m
;
120 struct BigCharArray b
;
121 struct SmallCharArray s
;
124 // Currently ignoring VLA padding problems. Still need to make sure we don't
125 // choke on VLAs though
126 struct HoldsVLA
{ // no-warning
133 // Currently ignoring bitfield padding problems. Still need to make sure we
134 // don't choke on bitfields though
135 struct HoldsBitfield
{ // no-warning
139 unsigned char b1
: 3;
140 unsigned char b2
: 3;
141 unsigned char b3
: 2;
144 typedef struct { // expected-warning{{Excessive padding in 'TypedefSandwich'}}
150 // expected-warning@+1{{Excessive padding in 'struct StructAttrAlign' (10 padding}}
151 struct StructAttrAlign
{
155 } __attribute__((aligned(8)));
157 struct CorrectOverlyAlignedChar
{ // no-warning
158 char c
__attribute__((aligned(4096)));
166 struct OverlyAlignedChar
{ // expected-warning{{Excessive padding in 'struct OverlyAlignedChar'}}
170 char c
__attribute__((aligned(4096)));
173 struct HoldsOverlyAlignedChar
{ // expected-warning{{Excessive padding in 'struct HoldsOverlyAlignedChar'}}
175 struct OverlyAlignedChar o
;
179 void internalStructFunc(void) {
180 struct X
{ // expected-warning{{Excessive padding in 'struct X'}}
188 void typedefStructFunc(void) {
189 typedef struct { // expected-warning{{Excessive padding in 'S'}}
197 void anonStructFunc(void) {
198 struct { // expected-warning{{Excessive padding in 'struct (unnamed}}
205 struct CorrectDefaultAttrAlign
{ // no-warning
209 } __attribute__((aligned
));
211 struct TooSmallShortSandwich
{ // no-warning
217 // expected-warning@+1{{Excessive padding in 'struct SmallArrayShortSandwich'}}
218 struct SmallArrayShortSandwich
{
224 // expected-warning@+1{{Excessive padding in 'struct SmallArrayInFunc'}}
225 struct SmallArrayInFunc
{
231 void arrayHolder(void) {
232 struct SmallArrayInFunc Arr
[15];
235 // xxxexpected-warning@+1{{Excessive padding in 'struct SmallArrayInStruct'}}
236 struct SmallArrayInStruct
{
242 struct HoldsSmallArray
{
243 struct SmallArrayInStruct Field
[20];
244 } HoldsSmallArrayElt
;
246 void nestedPadding(void) {
247 struct HoldsSmallArray Arr
[15];