libstdc++: Fix std::format test for Solaris [PR113450]
[official-gcc.git] / contrib / filter-clang-warnings.py
blob6ae2a90404728ca67e63355a08f8fb4f1d0ab583
1 #!/usr/bin/env python3
3 # Copyright (C) 2018-2024 Free Software Foundation, Inc.
5 # Script to analyze warnings produced by clang.
7 # This file is part of GCC.
9 # GCC is free software; you can redistribute it and/or modify it under
10 # the terms of the GNU General Public License as published by the Free
11 # Software Foundation; either version 3, or (at your option) any later
12 # version.
14 # GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 # for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with GCC; see the file COPYING3. If not see
21 # <http://www.gnu.org/licenses/>.
26 import argparse
29 def skip_warning(filename, message):
30 ignores = {
31 '': ['-Warray-bounds', '-Wmismatched-tags',
32 'gcc_gfc: -Wignored-attributes', '-Wchar-subscripts',
33 'string literal (potentially insecure): -Wformat-security',
34 '-Wdeprecated-register',
35 '-Wvarargs', 'keyword is hidden by macro definition',
36 "but the argument has type 'char *': -Wformat-pedantic",
37 '-Wnested-anon-types',
38 'qualifier in explicit instantiation of',
39 'attribute argument not supported: asm_fprintf',
40 'when in C++ mode, this behavior is deprecated',
41 '-Wignored-attributes', '-Wgnu-zero-variadic-macro-arguments',
42 '-Wformat-security', '-Wundefined-internal',
43 '-Wunknown-warning-option', '-Wc++20-extensions',
44 '-Wbitwise-instead-of-logical', 'egrep is obsolescent'],
45 'insn-modes.cc': ['-Wshift-count-overflow'],
46 'insn-emit.cc': ['-Wtautological-compare'],
47 'insn-attrtab.cc': ['-Wparentheses-equality'],
48 'gimple-match.cc': ['-Wunused-', '-Wtautological-compare'],
49 'generic-match.cc': ['-Wunused-', '-Wtautological-compare'],
50 'i386.md': ['-Wparentheses-equality', '-Wtautological-compare',
51 '-Wtautological-overlap-compare'],
52 'sse.md': ['-Wparentheses-equality', '-Wtautological-compare',
53 '-Wconstant-logical-operand'],
54 'mmx.md': ['-Wtautological-compare'],
55 'genautomata.cc': ['-Wstring-plus-int'],
56 'fold-const-call.cc': ['-Wreturn-type'],
57 'gfortran.texi': [''],
58 'libtool': [''],
59 'lex.cc': ['-Wc++20-attribute-extensions'],
62 for name, ignore in ignores.items():
63 for i in ignore:
64 if name in filename and i in message:
65 return True
66 return False
69 parser = argparse.ArgumentParser()
70 parser.add_argument('log', help='Log file with clang warnings')
71 args = parser.parse_args()
73 lines = [line.strip() for line in open(args.log)]
74 messages = set()
75 for line in lines:
76 token = ': warning: '
77 i = line.find(token)
78 if i != -1:
79 location = line[:i]
80 message = line[i + len(token):]
81 if '/libffi/' in location or location.startswith('Makefile'):
82 continue
83 if not skip_warning(location, message):
84 messages.add(line)
86 for line in sorted(messages):
87 print(line)
89 print('\nTotal warnings: %d' % len(messages))