2018-09-25 07:12:52 +00:00
|
|
|
#!/usr/bin/env python3
|
2022-12-14 12:50:03 +00:00
|
|
|
|
2024-01-03 11:19:35 +00:00
|
|
|
# Copyright (C) 2018-2024 Free Software Foundation, Inc.
|
2018-09-25 07:12:52 +00:00
|
|
|
#
|
2019-06-25 12:30:19 +00:00
|
|
|
# Script to analyze warnings produced by clang.
|
2018-09-25 07:12:52 +00:00
|
|
|
#
|
|
|
|
# This file is part of GCC.
|
|
|
|
#
|
|
|
|
# GCC is free software; you can redistribute it and/or modify it under
|
|
|
|
# the terms of the GNU General Public License as published by the Free
|
|
|
|
# Software Foundation; either version 3, or (at your option) any later
|
|
|
|
# version.
|
|
|
|
#
|
|
|
|
# GCC is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
# for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with GCC; see the file COPYING3. If not see
|
2024-01-04 15:01:20 +00:00
|
|
|
# <http://www.gnu.org/licenses/>.
|
2018-09-25 07:12:52 +00:00
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
|
2020-12-08 10:07:25 +00:00
|
|
|
|
2019-06-25 12:30:19 +00:00
|
|
|
def skip_warning(filename, message):
|
2018-09-25 07:12:52 +00:00
|
|
|
ignores = {
|
2020-12-08 10:07:25 +00:00
|
|
|
'': ['-Warray-bounds', '-Wmismatched-tags',
|
|
|
|
'gcc_gfc: -Wignored-attributes', '-Wchar-subscripts',
|
|
|
|
'string literal (potentially insecure): -Wformat-security',
|
|
|
|
'-Wdeprecated-register',
|
|
|
|
'-Wvarargs', 'keyword is hidden by macro definition',
|
|
|
|
"but the argument has type 'char *': -Wformat-pedantic",
|
|
|
|
'-Wnested-anon-types',
|
|
|
|
'qualifier in explicit instantiation of',
|
|
|
|
'attribute argument not supported: asm_fprintf',
|
|
|
|
'when in C++ mode, this behavior is deprecated',
|
|
|
|
'-Wignored-attributes', '-Wgnu-zero-variadic-macro-arguments',
|
|
|
|
'-Wformat-security', '-Wundefined-internal',
|
2022-04-25 13:42:09 +00:00
|
|
|
'-Wunknown-warning-option', '-Wc++20-extensions',
|
2022-09-20 08:16:47 +00:00
|
|
|
'-Wbitwise-instead-of-logical', 'egrep is obsolescent'],
|
2022-01-14 15:57:02 +00:00
|
|
|
'insn-modes.cc': ['-Wshift-count-overflow'],
|
|
|
|
'insn-emit.cc': ['-Wtautological-compare'],
|
|
|
|
'insn-attrtab.cc': ['-Wparentheses-equality'],
|
|
|
|
'gimple-match.cc': ['-Wunused-', '-Wtautological-compare'],
|
|
|
|
'generic-match.cc': ['-Wunused-', '-Wtautological-compare'],
|
2020-12-08 10:20:21 +00:00
|
|
|
'i386.md': ['-Wparentheses-equality', '-Wtautological-compare',
|
|
|
|
'-Wtautological-overlap-compare'],
|
2022-01-23 09:52:41 +00:00
|
|
|
'sse.md': ['-Wparentheses-equality', '-Wtautological-compare',
|
|
|
|
'-Wconstant-logical-operand'],
|
2021-10-02 11:30:28 +00:00
|
|
|
'mmx.md': ['-Wtautological-compare'],
|
2022-01-14 15:57:02 +00:00
|
|
|
'genautomata.cc': ['-Wstring-plus-int'],
|
|
|
|
'fold-const-call.cc': ['-Wreturn-type'],
|
2020-12-08 10:20:21 +00:00
|
|
|
'gfortran.texi': [''],
|
2022-04-25 20:26:27 +00:00
|
|
|
'libtool': [''],
|
|
|
|
'lex.cc': ['-Wc++20-attribute-extensions'],
|
2019-06-25 12:30:19 +00:00
|
|
|
}
|
2018-09-25 07:12:52 +00:00
|
|
|
|
2022-09-20 08:16:47 +00:00
|
|
|
for name, ignore in ignores.items():
|
|
|
|
for i in ignore:
|
2018-09-25 07:12:52 +00:00
|
|
|
if name in filename and i in message:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2020-12-08 10:07:25 +00:00
|
|
|
|
2018-09-25 07:12:52 +00:00
|
|
|
parser = argparse.ArgumentParser()
|
2020-12-08 10:07:25 +00:00
|
|
|
parser.add_argument('log', help='Log file with clang warnings')
|
2018-09-25 07:12:52 +00:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
2020-12-08 10:07:25 +00:00
|
|
|
lines = [line.strip() for line in open(args.log)]
|
2022-12-16 12:07:27 +00:00
|
|
|
messages = set()
|
2020-12-08 10:07:25 +00:00
|
|
|
for line in lines:
|
2019-06-25 12:30:19 +00:00
|
|
|
token = ': warning: '
|
2020-12-08 10:07:25 +00:00
|
|
|
i = line.find(token)
|
2019-06-25 12:30:19 +00:00
|
|
|
if i != -1:
|
2020-12-08 10:07:25 +00:00
|
|
|
location = line[:i]
|
|
|
|
message = line[i + len(token):]
|
2022-12-21 08:08:24 +00:00
|
|
|
if '/libffi/' in location or location.startswith('Makefile'):
|
|
|
|
continue
|
2019-06-25 12:30:19 +00:00
|
|
|
if not skip_warning(location, message):
|
2022-12-16 12:07:27 +00:00
|
|
|
messages.add(line)
|
2018-09-25 07:12:52 +00:00
|
|
|
|
2020-12-08 10:07:25 +00:00
|
|
|
for line in sorted(messages):
|
|
|
|
print(line)
|
2022-12-21 08:10:07 +00:00
|
|
|
|
|
|
|
print('\nTotal warnings: %d' % len(messages))
|