]> git.ipfire.org Git - thirdparty/gcc.git/blob - contrib/filter-rtags-warnings.py
c++/c-common: Fix convert_vector_to_array_for_subscript for qualified vector types...
[thirdparty/gcc.git] / contrib / filter-rtags-warnings.py
1 #!/usr/bin/env python3
2 #
3 # Script to analyze warnings produced by rtags command (using LLVM):
4 # rc --diagnose-all --synchronous-diagnostics --json
5 #
6 # This file is part of GCC.
7 #
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
11 # version.
12 #
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
16 # for more details.
17 #
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/>. */
21 #
22 #
23 #
24
25 import sys
26 import json
27 import argparse
28
29 def skip_warning(filename, warning):
30 ignores = {
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'],
40 }
41
42 message = warning['message']
43
44 if warning['type'] == 'fixit':
45 return True
46
47 for name, ignores in ignores.items():
48 for i in ignores:
49 if name in filename and i in message:
50 return True
51
52 return False
53
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')
57
58 args = parser.parse_args()
59
60 data = json.load(open(args.json_file))
61 file_warnings = data['checkStyle']
62
63 total = 0
64 for filename, warnings in file_warnings.items():
65 if warnings:
66 for w in warnings:
67 if args.no_filter or not skip_warning(filename, w):
68 total += 1
69 print('%s:%d:%d:%s' % (filename, w['line'], w['column'], w['message']))
70
71 print('Total: %d' % total)