3 # Script to analyze warnings produced by rtags command (using LLVM):
4 # rc --diagnose-all --synchronous-diagnostics --json
6 # This file is part of GCC.
8 # GCC is free software; you can redistribute it and/or modify it under
9 # the terms of the GNU General Public License as published by the Free
10 # Software Foundation; either version 3, or (at your option) any later
13 # GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 # You should have received a copy of the GNU General Public License
19 # along with GCC; see the file COPYING3. If not see
20 # <http://www.gnu.org/licenses/>. */
29 def skip_warning(filename
, warning
):
31 '': ['-Warray-bounds', '-Wmismatched-tags', 'gcc_gfc: -Wignored-attributes', '-Wchar-subscripts',
32 'string literal (potentially insecure): -Wformat-security', '-Wdeprecated-register',
33 '-Wvarargs', 'keyword is hidden by macro definition', "but the argument has type 'char *': -Wformat-pedantic",
34 '-Wnested-anon-types', 'qualifier in explicit instantiation of', 'attribute argument not supported: asm_fprintf'],
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'],
42 message
= warning
['message']
44 if warning
['type'] == 'fixit':
47 for name
, ignores
in ignores
.items():
49 if name
in filename
and i
in message
:
54 parser
= argparse
.ArgumentParser()
55 parser
.add_argument('json_file', help = 'Rtags JSON file with diagnostics')
56 parser
.add_argument('-n', '--no-filter', action
= 'store_true', help = 'No filter')
58 args
= parser
.parse_args()
60 data
= json
.load(open(args
.json_file
))
61 file_warnings
= data
['checkStyle']
64 for filename
, warnings
in file_warnings
.items():
67 if args
.no_filter
or not skip_warning(filename
, w
):
69 print('%s:%d:%d:%s' % (filename
, w
['line'], w
['column'], w
['message']))
71 print('Total: %d' % total
)