[clang-cl] Ignore /Wv and /Wv:17 flags
[llvm-project.git] / clang / test / Analysis / padding_c.c
blob869e443c4785e1f90e174a4563f6ecf24edb5bec
1 // FIXME -Wno-aix-compat added temporarily while the diagnostic is being
2 // refined.
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>)
18 #include <stdalign.h>
19 #endif
21 #if __has_include(<stdalign.h>) || defined(__cplusplus)
22 // expected-warning@+1{{Excessive padding in 'struct FieldAttrAlign' (6 padding}}
23 struct FieldAttrAlign {
24 char c1;
25 alignas(4) int i;
26 char c2;
29 // expected-warning@+1{{Excessive padding in 'struct FieldAttrOverAlign' (10 padding}}
30 struct FieldAttrOverAlign {
31 char c1;
32 alignas(8) int i;
33 char c2;
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
40 char c;
41 int i;
44 struct TrailingChar { // no-warning
45 int i;
46 char c;
49 struct Helpless { // no-warning
50 struct TrailingChar i1;
51 struct LeadingChar i2;
52 char c;
55 #pragma pack(push)
56 #pragma pack(1)
57 struct SquishedIntSandwich { // no-warning
58 char c1;
59 int i;
60 char c2;
62 #pragma pack(pop)
64 // Re-ordering members of these structs will reduce padding, so warn
65 struct IntSandwich { // expected-warning{{Excessive padding in 'struct IntSandwich'}}
66 char c1;
67 int i;
68 char c2;
71 struct TurDuckHen { // expected-warning{{Excessive padding in 'struct TurDuckHen'}}
72 char c1;
73 struct IntSandwich i;
74 char c2;
77 #pragma pack(push)
78 #pragma pack(2)
79 struct SmallIntSandwich { // expected-warning{{Excessive padding in 'struct SmallIntSandwich'}}
80 char c1;
81 int i1;
82 char c2;
83 int i2;
84 char c3;
85 int i3;
86 char c4;
88 #pragma pack(pop)
90 union SomeUnion { // no-warning
91 char c;
92 short s;
93 int i;
96 struct HoldsAUnion { // expected-warning{{Excessive padding in 'struct HoldsAUnion'}}
97 char c1;
98 union SomeUnion u;
99 char c2;
102 struct BigCharArray { // no-warning
103 char c[129];
106 struct SmallCharArray { // no-warning
107 char c[5];
110 struct MediumIntArray { // no-warning
111 int i[5];
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
129 char c1;
130 int x;
131 char c2;
132 int vla[];
135 // Currently ignoring bitfield padding problems. Still need to make sure we
136 // don't choke on bitfields though
137 struct HoldsBitfield { // no-warning
138 char c1;
139 int x;
140 char c2;
141 unsigned char b1 : 3;
142 unsigned char b2 : 3;
143 unsigned char b3 : 2;
146 typedef struct { // expected-warning{{Excessive padding in 'TypedefSandwich'}}
147 char c1;
148 int i;
149 char c2;
150 } TypedefSandwich;
152 // expected-warning@+1{{Excessive padding in 'struct StructAttrAlign' (10 padding}}
153 struct StructAttrAlign {
154 char c1;
155 int i;
156 char c2;
157 } __attribute__((aligned(8)));
159 struct CorrectOverlyAlignedChar { // no-warning
160 char c __attribute__((aligned(4096)));
161 char c1;
162 int x1;
163 char c2;
164 int x2;
165 char c3;
168 struct OverlyAlignedChar { // expected-warning{{Excessive padding in 'struct OverlyAlignedChar'}}
169 char c1;
170 int x;
171 char c2;
172 char c __attribute__((aligned(4096)));
175 struct HoldsOverlyAlignedChar { // expected-warning{{Excessive padding in 'struct HoldsOverlyAlignedChar'}}
176 char c1;
177 struct OverlyAlignedChar o;
178 char c2;
181 void internalStructFunc(void) {
182 struct X { // expected-warning{{Excessive padding in 'struct X'}}
183 char c1;
184 int t;
185 char c2;
187 struct X obj;
190 void typedefStructFunc(void) {
191 typedef struct { // expected-warning{{Excessive padding in 'S'}}
192 char c1;
193 int t;
194 char c2;
195 } S;
196 S obj;
199 void anonStructFunc(void) {
200 struct { // expected-warning{{Excessive padding in 'struct (unnamed}}
201 char c1;
202 int t;
203 char c2;
204 } obj;
207 struct CorrectDefaultAttrAlign { // no-warning
208 long long i;
209 char c1;
210 char c2;
211 } __attribute__((aligned));
213 struct TooSmallShortSandwich { // no-warning
214 char c1;
215 short s;
216 char c2;
219 // expected-warning@+1{{Excessive padding in 'struct SmallArrayShortSandwich'}}
220 struct SmallArrayShortSandwich {
221 char c1;
222 short s;
223 char c2;
224 } ShortArray[20];
226 // expected-warning@+1{{Excessive padding in 'struct SmallArrayInFunc'}}
227 struct SmallArrayInFunc {
228 char c1;
229 short s;
230 char c2;
233 void arrayHolder(void) {
234 struct SmallArrayInFunc Arr[15];
237 // xxxexpected-warning@+1{{Excessive padding in 'struct SmallArrayInStruct'}}
238 struct SmallArrayInStruct {
239 char c1;
240 short s;
241 char c2;
244 struct HoldsSmallArray {
245 struct SmallArrayInStruct Field[20];
246 } HoldsSmallArrayElt;
248 void nestedPadding(void) {
249 struct HoldsSmallArray Arr[15];