blob: 3c68be028a89b0a64bdb27253744c11b70544899 [file] [log] [blame]
#!/usr/bin/env python3
# Script to analyze warnings produced by clang.
# 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
# <>. */
import argparse
def skip_warning(filename, message):
ignores = {
'': ['-Warray-bounds', '-Wmismatched-tags',
'gcc_gfc: -Wignored-attributes', '-Wchar-subscripts',
'string literal (potentially insecure): -Wformat-security',
'-Wvarargs', 'keyword is hidden by macro definition',
"but the argument has type 'char *': -Wformat-pedantic",
'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',
'-Wunknown-warning-option', '-Wc++20-extensions',
'-Wbitwise-instead-of-logical', 'egrep is obsolescent'],
'': ['-Wshift-count-overflow'],
'': ['-Wtautological-compare'],
'': ['-Wparentheses-equality'],
'': ['-Wunused-', '-Wtautological-compare'],
'': ['-Wunused-', '-Wtautological-compare'],
'': ['-Wparentheses-equality', '-Wtautological-compare',
'': ['-Wparentheses-equality', '-Wtautological-compare',
'': ['-Wtautological-compare'],
'': ['-Wstring-plus-int'],
'': ['-Wreturn-type'],
'gfortran.texi': [''],
'libtool': [''],
'': ['-Wc++20-attribute-extensions'],
for name, ignore in ignores.items():
for i in ignore:
if name in filename and i in message:
return True
return False
parser = argparse.ArgumentParser()
parser.add_argument('log', help='Log file with clang warnings')
args = parser.parse_args()
lines = [line.strip() for line in open(args.log)]
total = 0
messages = []
for line in lines:
token = ': warning: '
i = line.find(token)
if i != -1:
location = line[:i]
message = line[i + len(token):]
if not skip_warning(location, message):
total += 1
for line in sorted(messages):
print('\nTotal warnings: %d' % total)