145
|
1 #!/usr/bin/env python3
|
|
2 #
|
|
3 # Script to analyze warnings produced by clang.
|
|
4 #
|
|
5 # This file is part of GCC.
|
|
6 #
|
|
7 # GCC is free software; you can redistribute it and/or modify it under
|
|
8 # the terms of the GNU General Public License as published by the Free
|
|
9 # Software Foundation; either version 3, or (at your option) any later
|
|
10 # version.
|
|
11 #
|
|
12 # GCC is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
14 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
15 # for more details.
|
|
16 #
|
|
17 # You should have received a copy of the GNU General Public License
|
|
18 # along with GCC; see the file COPYING3. If not see
|
|
19 # <http://www.gnu.org/licenses/>. */
|
|
20 #
|
|
21 #
|
|
22 #
|
|
23
|
|
24 import sys
|
|
25 import argparse
|
|
26
|
|
27 def skip_warning(filename, message):
|
|
28 ignores = {
|
|
29 '': ['-Warray-bounds', '-Wmismatched-tags', 'gcc_gfc: -Wignored-attributes', '-Wchar-subscripts',
|
|
30 'string literal (potentially insecure): -Wformat-security', '-Wdeprecated-register',
|
|
31 '-Wvarargs', 'keyword is hidden by macro definition', "but the argument has type 'char *': -Wformat-pedantic",
|
|
32 '-Wnested-anon-types', 'qualifier in explicit instantiation of', 'attribute argument not supported: asm_fprintf',
|
|
33 'when in C++ mode, this behavior is deprecated', '-Wignored-attributes', '-Wgnu-zero-variadic-macro-arguments',
|
|
34 '-Wformat-security'],
|
|
35 'insn-modes.c': ['-Wshift-count-overflow'],
|
|
36 'insn-emit.c': ['-Wtautological-compare'],
|
|
37 'insn-attrtab.c': ['-Wparentheses-equality'],
|
|
38 'gimple-match.c': ['-Wunused-', '-Wtautological-compare'],
|
|
39 'generic-match.c': ['-Wunused-', '-Wtautological-compare'],
|
|
40 'i386.md': ['-Wparentheses-equality', '-Wtautological-compare'],
|
|
41 'sse.md': ['-Wparentheses-equality', '-Wtautological-compare'],
|
|
42 'genautomata.c': ['-Wstring-plus-int']
|
|
43
|
|
44 }
|
|
45
|
|
46 for name, ignores in ignores.items():
|
|
47 for i in ignores:
|
|
48 if name in filename and i in message:
|
|
49 return True
|
|
50
|
|
51 return False
|
|
52
|
|
53 parser = argparse.ArgumentParser()
|
|
54 parser.add_argument('log', help = 'Log file with clang warnings')
|
|
55 args = parser.parse_args()
|
|
56
|
|
57 lines = [l.strip() for l in open(args.log)]
|
|
58 total = 0
|
|
59 messages = []
|
|
60 for l in lines:
|
|
61 token = ': warning: '
|
|
62 i = l.find(token)
|
|
63 if i != -1:
|
|
64 location = l[:i]
|
|
65 message = l[i + len(token):]
|
|
66 if not skip_warning(location, message):
|
|
67 total += 1
|
|
68 messages.append(l)
|
|
69
|
|
70 for l in sorted(messages):
|
|
71 print(l)
|
|
72 print('\nTotal warnings: %d' % total)
|