]> git.ipfire.org Git - thirdparty/gcc.git/blame - contrib/filter-clang-warnings.py
Update ChangeLog and version files for release
[thirdparty/gcc.git] / contrib / filter-clang-warnings.py
CommitLineData
a0464aa0
ML
1#!/usr/bin/env python3
2#
247b63e3 3# Script to analyze warnings produced by clang.
a0464aa0
ML
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
24import sys
a0464aa0
ML
25import argparse
26
247b63e3 27def skip_warning(filename, message):
a0464aa0
ML
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",
247b63e3
ML
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'],
a0464aa0
ML
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'],
247b63e3
ML
40 'i386.md': ['-Wparentheses-equality', '-Wtautological-compare'],
41 'sse.md': ['-Wparentheses-equality', '-Wtautological-compare'],
42 'genautomata.c': ['-Wstring-plus-int']
a0464aa0 43
247b63e3 44 }
a0464aa0
ML
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
53parser = argparse.ArgumentParser()
247b63e3 54parser.add_argument('log', help = 'Log file with clang warnings')
a0464aa0
ML
55args = parser.parse_args()
56
247b63e3 57lines = [l.strip() for l in open(args.log)]
a0464aa0 58total = 0
247b63e3
ML
59messages = []
60for 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)
a0464aa0 69
247b63e3
ML
70for l in sorted(messages):
71 print(l)
72print('\nTotal warnings: %d' % total)