From: Martin Liska Date: Tue, 25 Jun 2019 12:30:19 +0000 (+0200) Subject: Transform filter-rtags-warnings to filter-clang-warnings. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=247b63e33d21cb5971ae93c8232a50c678480eeb;p=gcc.git Transform filter-rtags-warnings to filter-clang-warnings. 2019-06-25 Martin Liska contrib/filter-clang-warnings.py: Transform from filter-rtags-warnings.py. From-SVN: r272652 --- diff --git a/ChangeLog b/ChangeLog index fb836d45de0..22a671aa3a0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2019-06-25 Martin Liska + + contrib/filter-clang-warnings.py: Transform from + filter-rtags-warnings.py. + 2019-06-15 Tom Tromey * configure.ac (host_libs): Add gnulib. diff --git a/contrib/filter-clang-warnings.py b/contrib/filter-clang-warnings.py new file mode 100755 index 00000000000..15cca5ff2df --- /dev/null +++ b/contrib/filter-clang-warnings.py @@ -0,0 +1,72 @@ +#!/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 sys +import argparse + +def skip_warning(filename, message): + ignores = { + '': ['-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'], + 'insn-modes.c': ['-Wshift-count-overflow'], + 'insn-emit.c': ['-Wtautological-compare'], + 'insn-attrtab.c': ['-Wparentheses-equality'], + 'gimple-match.c': ['-Wunused-', '-Wtautological-compare'], + 'generic-match.c': ['-Wunused-', '-Wtautological-compare'], + 'i386.md': ['-Wparentheses-equality', '-Wtautological-compare'], + 'sse.md': ['-Wparentheses-equality', '-Wtautological-compare'], + 'genautomata.c': ['-Wstring-plus-int'] + + } + + for name, ignores in ignores.items(): + for i in ignores: + 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 = [l.strip() for l in open(args.log)] +total = 0 +messages = [] +for l in lines: + token = ': warning: ' + i = l.find(token) + if i != -1: + location = l[:i] + message = l[i + len(token):] + if not skip_warning(location, message): + total += 1 + messages.append(l) + +for l in sorted(messages): + print(l) +print('\nTotal warnings: %d' % total) diff --git a/contrib/filter-rtags-warnings.py b/contrib/filter-rtags-warnings.py deleted file mode 100755 index ee27e7c8942..00000000000 --- a/contrib/filter-rtags-warnings.py +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/env python3 -# -# Script to analyze warnings produced by rtags command (using LLVM): -# rc --diagnose-all --synchronous-diagnostics --json -# -# 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 sys -import json -import argparse - -def skip_warning(filename, warning): - ignores = { - '': ['-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'], - 'insn-modes.c': ['-Wshift-count-overflow'], - 'insn-emit.c': ['-Wtautological-compare'], - 'insn-attrtab.c': ['-Wparentheses-equality'], - 'gimple-match.c': ['-Wunused-', '-Wtautological-compare'], - 'generic-match.c': ['-Wunused-', '-Wtautological-compare'], - } - - message = warning['message'] - - if warning['type'] == 'fixit': - return True - - for name, ignores in ignores.items(): - for i in ignores: - if name in filename and i in message: - return True - - return False - -parser = argparse.ArgumentParser() -parser.add_argument('json_file', help = 'Rtags JSON file with diagnostics') -parser.add_argument('-n', '--no-filter', action = 'store_true', help = 'No filter') - -args = parser.parse_args() - -data = json.load(open(args.json_file)) -file_warnings = data['checkStyle'] - -total = 0 -for filename, warnings in file_warnings.items(): - if warnings: - for w in warnings: - if args.no_filter or not skip_warning(filename, w): - total += 1 - print('%s:%d:%d:%s' % (filename, w['line'], w['column'], w['message'])) - -print('Total: %d' % total)