]> git.ipfire.org Git - thirdparty/gcc.git/blob - contrib/filter-clang-warnings.py
Change references of .c files to .cc files
[thirdparty/gcc.git] / contrib / filter-clang-warnings.py
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 argparse
25
26
27 def skip_warning(filename, message):
28 ignores = {
29 '': ['-Warray-bounds', '-Wmismatched-tags',
30 'gcc_gfc: -Wignored-attributes', '-Wchar-subscripts',
31 'string literal (potentially insecure): -Wformat-security',
32 '-Wdeprecated-register',
33 '-Wvarargs', 'keyword is hidden by macro definition',
34 "but the argument has type 'char *': -Wformat-pedantic",
35 '-Wnested-anon-types',
36 'qualifier in explicit instantiation of',
37 'attribute argument not supported: asm_fprintf',
38 'when in C++ mode, this behavior is deprecated',
39 '-Wignored-attributes', '-Wgnu-zero-variadic-macro-arguments',
40 '-Wformat-security', '-Wundefined-internal',
41 '-Wunknown-warning-option', '-Wc++20-extensions'],
42 'insn-modes.cc': ['-Wshift-count-overflow'],
43 'insn-emit.cc': ['-Wtautological-compare'],
44 'insn-attrtab.cc': ['-Wparentheses-equality'],
45 'gimple-match.cc': ['-Wunused-', '-Wtautological-compare'],
46 'generic-match.cc': ['-Wunused-', '-Wtautological-compare'],
47 'i386.md': ['-Wparentheses-equality', '-Wtautological-compare',
48 '-Wtautological-overlap-compare'],
49 'sse.md': ['-Wparentheses-equality', '-Wtautological-compare'],
50 'mmx.md': ['-Wtautological-compare'],
51 'genautomata.cc': ['-Wstring-plus-int'],
52 'fold-const-call.cc': ['-Wreturn-type'],
53 'gfortran.texi': [''],
54 'libtool': ['']
55 }
56
57 for name, ignores in ignores.items():
58 for i in ignores:
59 if name in filename and i in message:
60 return True
61 return False
62
63
64 parser = argparse.ArgumentParser()
65 parser.add_argument('log', help='Log file with clang warnings')
66 args = parser.parse_args()
67
68 lines = [line.strip() for line in open(args.log)]
69 total = 0
70 messages = []
71 for line in lines:
72 token = ': warning: '
73 i = line.find(token)
74 if i != -1:
75 location = line[:i]
76 message = line[i + len(token):]
77 if not skip_warning(location, message):
78 total += 1
79 messages.append(line)
80
81 for line in sorted(messages):
82 print(line)
83 print('\nTotal warnings: %d' % total)