• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# python3
2# Copyright (C) 2019 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16"""Warning patterns for C/C++ compiler, but not clang-tidy."""
17
18# No need of doc strings for trivial small functions.
19# pylint:disable=missing-function-docstring
20
21import re
22
23# pylint:disable=relative-beyond-top-level
24from .severity import Severity
25
26
27def cpp_warn(severity, description, pattern_list):
28  return {
29      'category': 'C/C++',
30      'severity': severity,
31      'description': description,
32      'patterns': pattern_list
33  }
34
35
36def fixmenow(description, pattern_list):
37  return cpp_warn(Severity.FIXMENOW, description, pattern_list)
38
39
40def high(description, pattern_list):
41  return cpp_warn(Severity.HIGH, description, pattern_list)
42
43
44def medium(description, pattern_list):
45  return cpp_warn(Severity.MEDIUM, description, pattern_list)
46
47
48def low(description, pattern_list):
49  return cpp_warn(Severity.LOW, description, pattern_list)
50
51
52def skip(description, pattern_list):
53  return cpp_warn(Severity.SKIP, description, pattern_list)
54
55
56def harmless(description, pattern_list):
57  return cpp_warn(Severity.HARMLESS, description, pattern_list)
58
59
60warn_patterns = [
61    # pylint does not recognize g-inconsistent-quotes
62    # pylint:disable=line-too-long,bad-option-value,g-inconsistent-quotes
63    medium('Implicit function declaration',
64           [r".*: warning: implicit declaration of function .+",
65            r".*: warning: implicitly declaring library function"]),
66    skip('skip, conflicting types for ...',
67         [r".*: warning: conflicting types for '.+'"]),
68    high('Expression always evaluates to true or false',
69         [r".*: warning: comparison is always .+ due to limited range of data type",
70          r".*: warning: comparison of unsigned .*expression .+ is always true",
71          r".*: warning: comparison of unsigned .*expression .+ is always false"]),
72    high('Use transient memory for control value',
73         [r".*: warning: .+Using such transient memory for the control value is .*dangerous."]),
74    high('Return address of stack memory',
75         [r".*: warning: Address of stack memory .+ returned to caller",
76          r".*: warning: Address of stack memory .+ will be a dangling reference"]),
77    high('Infinite recursion',
78         [r".*: warning: all paths through this function will call itself"]),
79    high('Potential buffer overflow',
80         [r".*: warning: Size argument is greater than .+ the destination buffer",
81          r".*: warning: Potential buffer overflow.",
82          r".*: warning: String copy function overflows destination buffer"]),
83    medium('Incompatible pointer types',
84           [r".*: warning: assignment from incompatible pointer type",
85            r".*: warning: return from incompatible pointer type",
86            r".*: warning: passing argument [0-9]+ of '.*' from incompatible pointer type",
87            r".*: warning: initialization from incompatible pointer type"]),
88    high('Incompatible declaration of built in function',
89         [r".*: warning: incompatible implicit declaration of built-in function .+"]),
90    high('Incompatible redeclaration of library function',
91         [r".*: warning: incompatible redeclaration of library function .+"]),
92    high('Null passed as non-null argument',
93         [r".*: warning: Null passed to a callee that requires a non-null"]),
94    medium('Unused parameter',
95           [r".*: warning: unused parameter '.*'"]),
96    medium('Unused function, variable, label, comparison, etc.',
97           [r".*: warning: '.+' defined but not used",
98            r".*: warning: unused function '.+'",
99            r".*: warning: unused label '.+'",
100            r".*: warning: relational comparison result unused",
101            r".*: warning: lambda capture .* is not used",
102            r".*: warning: private field '.+' is not used",
103            r".*: warning: unused variable '.+'"]),
104    medium('Statement with no effect or result unused',
105           [r".*: warning: statement with no effect",
106            r".*: warning: expression result unused"]),
107    medium('Ignoreing return value of function',
108           [r".*: warning: ignoring return value of function .+Wunused-result"]),
109    medium('Missing initializer',
110           [r".*: warning: missing initializer"]),
111    medium('Need virtual destructor',
112           [r".*: warning: delete called .* has virtual functions but non-virtual destructor"]),
113    skip('skip, near initialization for ...',
114         [r".*: warning: \(near initialization for '.+'\)"]),
115    medium('Expansion of data or time macro',
116           [r".*: warning: expansion of date or time macro is not reproducible"]),
117    medium('Macro expansion has undefined behavior',
118           [r".*: warning: macro expansion .* has undefined behavior"]),
119    medium('Format string does not match arguments',
120           [r".*: warning: format '.+' expects type '.+', but argument [0-9]+ has type '.+'",
121            r".*: warning: more '%' conversions than data arguments",
122            r".*: warning: data argument not used by format string",
123            r".*: warning: incomplete format specifier",
124            r".*: warning: unknown conversion type .* in format",
125            r".*: warning: format .+ expects .+ but argument .+Wformat=",
126            r".*: warning: field precision should have .+ but argument has .+Wformat",
127            r".*: warning: format specifies type .+ but the argument has .*type .+Wformat"]),
128    medium('Too many arguments for format string',
129           [r".*: warning: too many arguments for format"]),
130    medium('Too many arguments in call',
131           [r".*: warning: too many arguments in call to "]),
132    medium('Invalid format specifier',
133           [r".*: warning: invalid .+ specifier '.+'.+format-invalid-specifier"]),
134    medium('Comparison between signed and unsigned',
135           [r".*: warning: comparison between signed and unsigned",
136            r".*: warning: comparison of promoted \~unsigned with unsigned",
137            r".*: warning: signed and unsigned type in conditional expression"]),
138    medium('Comparison between enum and non-enum',
139           [r".*: warning: enumeral and non-enumeral type in conditional expression"]),
140    medium('libpng: zero area',
141           [r".*libpng warning: Ignoring attempt to set cHRM RGB triangle with zero area"]),
142    medium('Missing braces around initializer',
143           [r".*: warning: missing braces around initializer.*"]),
144    harmless('No newline at end of file',
145             [r".*: warning: no newline at end of file"]),
146    harmless('Missing space after macro name',
147             [r".*: warning: missing whitespace after the macro name"]),
148    low('Cast increases required alignment',
149        [r".*: warning: cast from .* to .* increases required alignment .*"]),
150    medium('Qualifier discarded',
151           [r".*: warning: passing argument [0-9]+ of '.+' discards qualifiers from pointer target type",
152            r".*: warning: assignment discards qualifiers from pointer target type",
153            r".*: warning: passing .+ to parameter of type .+ discards qualifiers",
154            r".*: warning: assigning to .+ from .+ discards qualifiers",
155            r".*: warning: initializing .+ discards qualifiers .+types-discards-qualifiers",
156            r".*: warning: return discards qualifiers from pointer target type"]),
157    medium('Unknown attribute',
158           [r".*: warning: unknown attribute '.+'"]),
159    medium('Attribute ignored',
160           [r".*: warning: '_*packed_*' attribute ignored",
161            r".*: warning: .* not supported .*Wignored-attributes",
162            r".*: warning: attribute declaration must precede definition .+ignored-attributes"]),
163    medium('Visibility problem',
164           [r".*: warning: declaration of '.+' will not be visible outside of this function"]),
165    medium('Visibility mismatch',
166           [r".*: warning: '.+' declared with greater visibility than the type of its field '.+'"]),
167    medium('Shift count greater than width of type',
168           [r".*: warning: (left|right) shift count >= width of type"]),
169    medium('extern <foo> is initialized',
170           [r".*: warning: '.+' initialized and declared 'extern'",
171            r".*: warning: 'extern' variable has an initializer"]),
172    medium('Old style declaration',
173           [r".*: warning: 'static' is not at beginning of declaration"]),
174    medium('Missing return value',
175           [r".*: warning: control reaches end of non-void function"]),
176    medium('Implicit int type',
177           [r".*: warning: type specifier missing, defaults to 'int'",
178            r".*: warning: type defaults to 'int' in declaration of '.+'"]),
179    medium('Main function should return int',
180           [r".*: warning: return type of 'main' is not 'int'"]),
181    medium('Variable may be used uninitialized',
182           [r".*: warning: '.+' may be used uninitialized in this function"]),
183    high('Variable is used uninitialized',
184         [r".*: warning: '.+' is used uninitialized in this function",
185          r".*: warning: variable '.+' is uninitialized when used here"]),
186    medium('ld: possible enum size mismatch',
187           [r".*: warning: .* uses variable-size enums yet the output is to use 32-bit enums; use of enum values across objects may fail"]),
188    medium('Pointer targets differ in signedness',
189           [r".*: warning: pointer targets in initialization differ in signedness",
190            r".*: warning: pointer targets in assignment differ in signedness",
191            r".*: warning: pointer targets in return differ in signedness",
192            r".*: warning: pointer targets in passing argument [0-9]+ of '.+' differ in signedness"]),
193    medium('Assuming overflow does not occur',
194           [r".*: warning: assuming signed overflow does not occur when assuming that .* is always (true|false)"]),
195    medium('Suggest adding braces around empty body',
196           [r".*: warning: suggest braces around empty body in an 'if' statement",
197            r".*: warning: empty body in an if-statement",
198            r".*: warning: suggest braces around empty body in an 'else' statement",
199            r".*: warning: empty body in an else-statement"]),
200    medium('Suggest adding parentheses',
201           [r".*: warning: suggest explicit braces to avoid ambiguous 'else'",
202            r".*: warning: suggest parentheses around arithmetic in operand of '.+'",
203            r".*: warning: suggest parentheses around comparison in operand of '.+'",
204            r".*: warning: logical not is only applied to the left hand side of this comparison",
205            r".*: warning: using the result of an assignment as a condition without parentheses",
206            r".*: warning: .+ has lower precedence than .+ be evaluated first .+Wparentheses",
207            r".*: warning: suggest parentheses around '.+?' .+ '.+?'",
208            r".*: warning: suggest parentheses around assignment used as truth value"]),
209    medium('Static variable used in non-static inline function',
210           [r".*: warning: '.+' is static but used in inline function '.+' which is not static"]),
211    medium('No type or storage class (will default to int)',
212           [r".*: warning: data definition has no type or storage class"]),
213    skip('skip, parameter name (without types) in function declaration',
214         [r".*: warning: parameter names \(without types\) in function declaration"]),
215    medium('Dereferencing <foo> breaks strict aliasing rules',
216           [r".*: warning: dereferencing .* break strict-aliasing rules"]),
217    medium('Cast from pointer to integer of different size',
218           [r".*: warning: cast from pointer to integer of different size",
219            r".*: warning: initialization makes pointer from integer without a cast"]),
220    medium('Cast to pointer from integer of different size',
221           [r".*: warning: cast to pointer from integer of different size"]),
222    medium('Macro redefined',
223           [r".*: warning: '.+' macro redefined"]),
224    skip('skip, ... location of the previous definition',
225         [r".*: warning: this is the location of the previous definition"]),
226    medium('ld: type and size of dynamic symbol are not defined',
227           [r".*: warning: type and size of dynamic symbol `.+' are not defined"]),
228    medium('Pointer from integer without cast',
229           [r".*: warning: assignment makes pointer from integer without a cast"]),
230    medium('Pointer from integer without cast',
231           [r".*: warning: passing argument [0-9]+ of '.+' makes pointer from integer without a cast"]),
232    medium('Integer from pointer without cast',
233           [r".*: warning: assignment makes integer from pointer without a cast"]),
234    medium('Integer from pointer without cast',
235           [r".*: warning: passing argument [0-9]+ of '.+' makes integer from pointer without a cast"]),
236    medium('Integer from pointer without cast',
237           [r".*: warning: return makes integer from pointer without a cast"]),
238    medium('Ignoring pragma',
239           [r".*: warning: ignoring #pragma .+"]),
240    medium('Pragma warning messages',
241           [r".*: warning: .+W#pragma-messages"]),
242    medium('Variable might be clobbered by longjmp or vfork',
243           [r".*: warning: variable '.+' might be clobbered by 'longjmp' or 'vfork'"]),
244    medium('Argument might be clobbered by longjmp or vfork',
245           [r".*: warning: argument '.+' might be clobbered by 'longjmp' or 'vfork'"]),
246    medium('Redundant declaration',
247           [r".*: warning: redundant redeclaration of '.+'"]),
248    skip('skip, previous declaration ... was here',
249         [r".*: warning: previous declaration of '.+' was here"]),
250    high('Enum value not handled in switch',
251         [r".*: warning: .*enumeration value.* not handled in switch.+Wswitch"]),
252    medium('User defined warnings',
253           [r".*: warning: .* \[-Wuser-defined-warnings\]$"]),
254    medium('Taking address of temporary',
255           [r".*: warning: taking address of temporary"]),
256    medium('Taking address of packed member',
257           [r".*: warning: taking address of packed member"]),
258    medium('Pack alignment value is modified',
259           [r".*: warning: .*#pragma pack alignment value is modified.*Wpragma-pack.*"]),
260    medium('Possible broken line continuation',
261           [r".*: warning: backslash and newline separated by space"]),
262    medium('Undefined variable template',
263           [r".*: warning: instantiation of variable .* no definition is available"]),
264    medium('Inline function is not defined',
265           [r".*: warning: inline function '.*' is not defined"]),
266    medium('Excess elements in initializer',
267           [r".*: warning: excess elements in .+ initializer"]),
268    medium('Decimal constant is unsigned only in ISO C90',
269           [r".*: warning: this decimal constant is unsigned only in ISO C90"]),
270    medium('main is usually a function',
271           [r".*: warning: 'main' is usually a function"]),
272    medium('Typedef ignored',
273           [r".*: warning: 'typedef' was ignored in this declaration"]),
274    high('Address always evaluates to true',
275         [r".*: warning: the address of '.+' will always evaluate as 'true'"]),
276    fixmenow('Freeing a non-heap object',
277             [r".*: warning: attempt to free a non-heap object '.+'"]),
278    medium('Array subscript has type char',
279           [r".*: warning: array subscript .+ type 'char'.+Wchar-subscripts"]),
280    medium('Constant too large for type',
281           [r".*: warning: integer constant is too large for '.+' type"]),
282    medium('Constant too large for type, truncated',
283           [r".*: warning: large integer implicitly truncated to unsigned type"]),
284    medium('Overflow in expression',
285           [r".*: warning: overflow in expression; .*Winteger-overflow"]),
286    medium('Overflow in implicit constant conversion',
287           [r".*: warning: overflow in implicit constant conversion"]),
288    medium('Declaration does not declare anything',
289           [r".*: warning: declaration 'class .+' does not declare anything"]),
290    medium('Initialization order will be different',
291           [r".*: warning: '.+' will be initialized after",
292            r".*: warning: field .+ will be initialized after .+Wreorder"]),
293    skip('skip,   ....',
294         [r".*: warning:   '.+'"]),
295    skip('skip,   base ...',
296         [r".*: warning:   base '.+'"]),
297    skip('skip,   when initialized here',
298         [r".*: warning:   when initialized here"]),
299    medium('Parameter type not specified',
300           [r".*: warning: type of '.+' defaults to 'int'"]),
301    medium('Missing declarations',
302           [r".*: warning: declaration does not declare anything"]),
303    medium('Missing noreturn',
304           [r".*: warning: function '.*' could be declared with attribute 'noreturn'"]),
305    medium('User warning',
306           [r".*: warning: #warning \".+\""]),
307    medium('Vexing parsing problem',
308           [r".*: warning: empty parentheses interpreted as a function declaration"]),
309    medium('Dereferencing void*',
310           [r".*: warning: dereferencing 'void \*' pointer"]),
311    medium('Comparison of pointer and integer',
312           [r".*: warning: ordered comparison of pointer with integer zero",
313            r".*: warning: .*comparison between pointer and integer"]),
314    medium('Use of error-prone unary operator',
315           [r".*: warning: use of unary operator that may be intended as compound assignment"]),
316    medium('Conversion of string constant to non-const char*',
317           [r".*: warning: deprecated conversion from string constant to '.+'"]),
318    medium('Function declaration isn''t a prototype',
319           [r".*: warning: function declaration isn't a prototype"]),
320    medium('Type qualifiers ignored on function return value',
321           [r".*: warning: type qualifiers ignored on function return type",
322            r".*: warning: .+ type qualifier .+ has no effect .+Wignored-qualifiers"]),
323    medium('<foo> declared inside parameter list, scope limited to this definition',
324           [r".*: warning: '.+' declared inside parameter list"]),
325    skip('skip, its scope is only this ...',
326         [r".*: warning: its scope is only this definition or declaration, which is probably not what you want"]),
327    low('Line continuation inside comment',
328        [r".*: warning: multi-line comment"]),
329    low('Comment inside comment',
330        [r".*: warning: '.+' within block comment .*-Wcomment"]),
331    low('Deprecated declarations',
332        [r".*: warning: .+ is deprecated.+deprecated-declarations"]),
333    low('Deprecated register',
334        [r".*: warning: 'register' storage class specifier is deprecated"]),
335    low('Converts between pointers to integer types with different sign',
336        [r".*: warning: .+ converts between pointers to integer types with different sign"]),
337    harmless('Extra tokens after #endif',
338             [r".*: warning: extra tokens at end of #endif directive"]),
339    medium('Comparison between different enums',
340           [r".*: warning: comparison between '.+' and '.+'.+Wenum-compare",
341            r".*: warning: comparison of .* enumeration types .*-Wenum-compare.*"]),
342    medium('Conversion may change value',
343           [r".*: warning: converting negative value '.+' to '.+'",
344            r".*: warning: conversion to '.+' .+ may (alter|change)"]),
345    medium('Converting to non-pointer type from NULL',
346           [r".*: warning: converting to non-pointer type '.+' from NULL"]),
347    medium('Implicit sign conversion',
348           [r".*: warning: implicit conversion changes signedness"]),
349    medium('Converting NULL to non-pointer type',
350           [r".*: warning: implicit conversion of NULL constant to '.+'"]),
351    medium('Zero used as null pointer',
352           [r".*: warning: expression .* zero treated as a null pointer constant"]),
353    medium('Compare pointer to null character',
354           [r".*: warning: comparing a pointer to a null character constant"]),
355    medium('Implicit conversion changes value or loses precision',
356           [r".*: warning: implicit conversion .* changes value from .* to .*-conversion",
357            r".*: warning: implicit conversion loses integer precision:"]),
358    medium('Passing NULL as non-pointer argument',
359           [r".*: warning: passing NULL to non-pointer argument [0-9]+ of '.+'"]),
360    medium('Class seems unusable because of private ctor/dtor',
361           [r".*: warning: all member functions in class '.+' are private"]),
362    # skip this next one, because it only points out some RefBase-based classes
363    # where having a private destructor is perfectly fine
364    skip('Class seems unusable because of private ctor/dtor',
365         [r".*: warning: 'class .+' only defines a private destructor and has no friends"]),
366    medium('Class seems unusable because of private ctor/dtor',
367           [r".*: warning: 'class .+' only defines private constructors and has no friends"]),
368    medium('In-class initializer for static const float/double',
369           [r".*: warning: in-class initializer for static data member of .+const (float|double)"]),
370    medium('void* used in arithmetic',
371           [r".*: warning: pointer of type 'void \*' used in (arithmetic|subtraction)",
372            r".*: warning: arithmetic on .+ to void is a GNU extension.*Wpointer-arith",
373            r".*: warning: wrong type argument to increment"]),
374    medium('Overload resolution chose to promote from unsigned or enum to signed type',
375           [r".*: warning: passing '.+' chooses '.+' over '.+'.*Wsign-promo"]),
376    skip('skip,   in call to ...',
377         [r".*: warning:   in call to '.+'"]),
378    high('Base should be explicitly initialized in copy constructor',
379         [r".*: warning: base class '.+' should be explicitly initialized in the copy constructor"]),
380    medium('Return value from void function',
381           [r".*: warning: 'return' with a value, in function returning void"]),
382    medium('Multi-character character constant',
383           [r".*: warning: multi-character character constant"]),
384    medium('Conversion from string literal to char*',
385           [r".*: warning: .+ does not allow conversion from string literal to 'char \*'"]),
386    low('Extra \';\'',
387        [r".*: warning: extra ';' .+extra-semi"]),
388    low('Useless specifier',
389        [r".*: warning: useless storage class specifier in empty declaration"]),
390    low('Duplicate declaration specifier',
391        [r".*: warning: duplicate '.+' declaration specifier"]),
392    low('Comparison of self is always false',
393        [r".*: self-comparison always evaluates to false"]),
394    low('Logical op with constant operand',
395        [r".*: use of logical '.+' with constant operand"]),
396    low('Needs a space between literal and string macro',
397        [r".*: warning: invalid suffix on literal.+ requires a space .+Wliteral-suffix"]),
398    low('Warnings from #warning',
399        [r".*: warning: .+-W#warnings"]),
400    low('Using float/int absolute value function with int/float argument',
401        [r".*: warning: using .+ absolute value function .+ when argument is .+ type .+Wabsolute-value",
402         r".*: warning: absolute value function '.+' given .+ which may cause truncation .+Wabsolute-value"]),
403    low('Using C++11 extensions',
404        [r".*: warning: 'auto' type specifier is a C\+\+11 extension"]),
405    low('Using C++17 extensions',
406        [r".*: warning: .* a C\+\+17 extension .+Wc\+\+17-extensions"]),
407    low('Refers to implicitly defined namespace',
408        [r".*: warning: using directive refers to implicitly-defined namespace .+"]),
409    low('Invalid pp token',
410        [r".*: warning: missing .+Winvalid-pp-token"]),
411    low('need glibc to link',
412        [r".*: warning: .* requires at runtime .* glibc .* for linking"]),
413    medium('Operator new returns NULL',
414           [r".*: warning: 'operator new' must not return NULL unless it is declared 'throw\(\)' .+"]),
415    medium('NULL used in arithmetic',
416           [r".*: warning: NULL used in arithmetic",
417            r".*: warning: comparison between NULL and non-pointer"]),
418    medium('Misspelled header guard',
419           [r".*: warning: '.+' is used as a header guard .+ followed by .+ different macro"]),
420    medium('Empty loop body',
421           [r".*: warning: .+ loop has empty body"]),
422    medium('Implicit conversion from enumeration type',
423           [r".*: warning: implicit conversion from enumeration type '.+'"]),
424    medium('case value not in enumerated type',
425           [r".*: warning: case value not in enumerated type '.+'"]),
426    medium('Use of deprecated method',
427           [r".*: warning: '.+' is deprecated .+"]),
428    medium('Use of garbage or uninitialized value',
429           [r".*: warning: .+ uninitialized .+\[-Wsometimes-uninitialized\]"]),
430    medium('Sizeof on array argument',
431           [r".*: warning: sizeof on array function parameter will return"]),
432    medium('Bad argument size of memory access functions',
433           [r".*: warning: .+\[-Wsizeof-pointer-memaccess\]"]),
434    medium('Return value not checked',
435           [r".*: warning: The return value from .+ is not checked"]),
436    medium('Possible heap pollution',
437           [r".*: warning: .*Possible heap pollution from .+ type .+"]),
438    medium('Variable used in loop condition not modified in loop body',
439           [r".*: warning: variable '.+' used in loop condition.*Wfor-loop-analysis"]),
440    medium('Closing a previously closed file',
441           [r".*: warning: Closing a previously closed file"]),
442    medium('Unnamed template type argument',
443           [r".*: warning: template argument.+Wunnamed-type-template-args"]),
444    medium('Unannotated fall-through between switch labels',
445           [r".*: warning: unannotated fall-through between switch labels.+Wimplicit-fallthrough"]),
446    medium('Invalid partial specialization',
447           [r".*: warning: class template partial specialization.+Winvalid-partial-specialization"]),
448    medium('Overlapping comparisons',
449           [r".*: warning: overlapping comparisons.+Wtautological-overlap-compare"]),
450    medium('bitwise comparison',
451           [r".*: warning: bitwise comparison.+Wtautological-bitwise-compare"]),
452    medium('int in bool context',
453           [r".*: warning: converting.+to a boolean.+Wint-in-bool-context"]),
454    medium('bitwise conditional parentheses',
455           [r".*: warning: operator.+has lower precedence.+Wbitwise-conditional-parentheses"]),
456    medium('sizeof array div',
457           [r".*: warning: .+number of elements in.+array.+Wsizeof-array-div"]),
458    medium('bool operation',
459           [r".*: warning: .+boolean.+always.+Wbool-operation"]),
460    medium('Undefined bool conversion',
461           [r".*: warning: .+may be.+always.+true.+Wundefined-bool-conversion"]),
462    medium('Typedef requires a name',
463           [r".*: warning: typedef requires a name.+Wmissing-declaration"]),
464    medium('Unknown escape sequence',
465           [r".*: warning: unknown escape sequence.+Wunknown-escape-sequence"]),
466    medium('Unicode whitespace',
467           [r".*: warning: treating Unicode.+as whitespace.+Wunicode-whitespace"]),
468    medium('Unused local typedef',
469           [r".*: warning: unused typedef.+Wunused-local-typedef"]),
470    medium('varargs warnings',
471           [r".*: warning: .*argument to 'va_start'.+\[-Wvarargs\]"]),
472    harmless('Discarded qualifier from pointer target type',
473             [r".*: warning: .+ discards '.+' qualifier from pointer target type"]),
474    harmless('Use snprintf instead of sprintf',
475             [r".*: warning: .*sprintf is often misused; please use snprintf"]),
476    harmless('Unsupported optimizaton flag',
477             [r".*: warning: optimization flag '.+' is not supported"]),
478    harmless('Extra or missing parentheses',
479             [r".*: warning: equality comparison with extraneous parentheses",
480              r".*: warning: .+ within .+Wlogical-op-parentheses"]),
481    harmless('Mismatched class vs struct tags',
482             [r".*: warning: '.+' defined as a .+ here but previously declared as a .+mismatched-tags",
483              r".*: warning: .+ was previously declared as a .+mismatched-tags"]),
484]
485
486
487def compile_patterns(patterns):
488  """Precompiling every pattern speeds up parsing by about 30x."""
489  for i in patterns:
490    i['compiled_patterns'] = []
491    for pat in i['patterns']:
492      i['compiled_patterns'].append(re.compile(pat))
493
494
495compile_patterns(warn_patterns)
496