1 // FIXME -Wno-aix-compat added temporarily while the diagnostic is being
3 // RUN: %clang_analyze_cc1 -verify -Wno-aix-compat %s \
4 // RUN: -analyzer-checker=optin.performance \
5 // RUN: -analyzer-config optin.performance.Padding:AllowedPad=2
7 // RUN: not %clang_analyze_cc1 -verify -Wno-aix-compat %s \
8 // RUN: -analyzer-checker=core \
9 // RUN: -analyzer-checker=optin.performance.Padding \
10 // RUN: -analyzer-config optin.performance.Padding:AllowedPad=-10 \
11 // RUN: 2>&1 | FileCheck %s -check-prefix=CHECK-PAD-NEGATIVE-VALUE
13 // CHECK-PAD-NEGATIVE-VALUE: (frontend): invalid input for checker option
14 // CHECK-PAD-NEGATIVE-VALUE-SAME: 'optin.performance.Padding:AllowedPad', that
15 // CHECK-PAD-NEGATIVE-VALUE-SAME: expects a non-negative value
17 #if __has_include(<stdalign.h>)
21 #if __has_include(<stdalign.h>) || defined(__cplusplus)
22 // expected-warning@+1{{Excessive padding in 'struct FieldAttrAlign' (6 padding}}
23 struct FieldAttrAlign
{
29 // expected-warning@+1{{Excessive padding in 'struct FieldAttrOverAlign' (10 padding}}
30 struct FieldAttrOverAlign
{
36 #endif // __has_include(<stdalign.h>) || defined(__cplusplus)
38 // Re-ordering members of these structs won't reduce padding, so don't warn
39 struct LeadingChar
{ // no-warning
44 struct TrailingChar
{ // no-warning
49 struct Helpless
{ // no-warning
50 struct TrailingChar i1
;
51 struct LeadingChar i2
;
57 struct SquishedIntSandwich
{ // no-warning
64 // Re-ordering members of these structs will reduce padding, so warn
65 struct IntSandwich
{ // expected-warning{{Excessive padding in 'struct IntSandwich'}}
71 struct TurDuckHen
{ // expected-warning{{Excessive padding in 'struct TurDuckHen'}}
79 struct SmallIntSandwich
{ // expected-warning{{Excessive padding in 'struct SmallIntSandwich'}}
90 union SomeUnion
{ // no-warning
96 struct HoldsAUnion
{ // expected-warning{{Excessive padding in 'struct HoldsAUnion'}}
102 struct BigCharArray
{ // no-warning
106 struct SmallCharArray
{ // no-warning
110 struct MediumIntArray
{ // no-warning
114 struct LargeSizeToSmallSize
{ // expected-warning{{Excessive padding in 'struct LargeSizeToSmallSize'}}
115 struct BigCharArray b
;
116 struct MediumIntArray m
;
117 struct SmallCharArray s
;
120 struct LargeAlignToSmallAlign
{ // no-warning
121 struct MediumIntArray m
;
122 struct BigCharArray b
;
123 struct SmallCharArray s
;
126 // Currently ignoring VLA padding problems. Still need to make sure we don't
127 // choke on VLAs though
128 struct HoldsVLA
{ // no-warning
135 // Currently ignoring bitfield padding problems. Still need to make sure we
136 // don't choke on bitfields though
137 struct HoldsBitfield
{ // no-warning
141 unsigned char b1
: 3;
142 unsigned char b2
: 3;
143 unsigned char b3
: 2;
146 typedef struct { // expected-warning{{Excessive padding in 'TypedefSandwich'}}
152 // expected-warning@+1{{Excessive padding in 'struct StructAttrAlign' (10 padding}}
153 struct StructAttrAlign
{
157 } __attribute__((aligned(8)));
159 struct CorrectOverlyAlignedChar
{ // no-warning
160 char c
__attribute__((aligned(4096)));
168 struct OverlyAlignedChar
{ // expected-warning{{Excessive padding in 'struct OverlyAlignedChar'}}
172 char c
__attribute__((aligned(4096)));
175 struct HoldsOverlyAlignedChar
{ // expected-warning{{Excessive padding in 'struct HoldsOverlyAlignedChar'}}
177 struct OverlyAlignedChar o
;
181 void internalStructFunc(void) {
182 struct X
{ // expected-warning{{Excessive padding in 'struct X'}}
190 void typedefStructFunc(void) {
191 typedef struct { // expected-warning{{Excessive padding in 'S'}}
199 void anonStructFunc(void) {
200 struct { // expected-warning{{Excessive padding in 'struct (unnamed}}
207 struct CorrectDefaultAttrAlign
{ // no-warning
211 } __attribute__((aligned
));
213 struct TooSmallShortSandwich
{ // no-warning
219 // expected-warning@+1{{Excessive padding in 'struct SmallArrayShortSandwich'}}
220 struct SmallArrayShortSandwich
{
226 // expected-warning@+1{{Excessive padding in 'struct SmallArrayInFunc'}}
227 struct SmallArrayInFunc
{
233 void arrayHolder(void) {
234 struct SmallArrayInFunc Arr
[15];
237 // xxxexpected-warning@+1{{Excessive padding in 'struct SmallArrayInStruct'}}
238 struct SmallArrayInStruct
{
244 struct HoldsSmallArray
{
245 struct SmallArrayInStruct Field
[20];
246 } HoldsSmallArrayElt
;
248 void nestedPadding(void) {
249 struct HoldsSmallArray Arr
[15];