Hi. I've left using rtags, but I'm still interested in clang warnings produced for GCC. Thus I'm transforming the script a bit. Current output:
/home/marxin/Programming/gcc/gcc/config/i386/i386.c:10364:6: warning: use of logical '||' with constant operand [-Wconstant-logical-operand] /home/marxin/Programming/gcc/gcc/cp/lex.c:169:45: warning: result of comparison of constant 64 with expression of type 'enum ovl_op_code' is always true [-Wtautological-constant-out-of-range-compare] /home/marxin/Programming/gcc/gcc/dwarf2out.c:5150:1: warning: unused function 'add_AT_vms_delta' [-Wunused-function] /home/marxin/Programming/gcc/gcc/edit-context.c:1642:23: warning: empty parentheses interpreted as a function declaration [-Wvexing-parse] /home/marxin/Programming/gcc/gcc/edit-context.c:1673:23: warning: empty parentheses interpreted as a function declaration [-Wvexing-parse] /home/marxin/Programming/gcc/gcc/fortran/gfortran.texi:1791: warning: @node name should not contain `,': Default widths for F, G and I format descriptors /home/marxin/Programming/gcc/gcc/fortran/gfortran.texi:2777: warning: @ref node name should not contain `:' /home/marxin/Programming/gcc/gcc/genconditions.c:126:58: warning: cast from 'void **' to 'const struct c_test **' must have all intermediate pointers const qualified to be safe [-Wcast-qual] /home/marxin/Programming/gcc/gcc/ggc-page.c:946:60: warning: format specifies type 'void *' but the argument has type 'char *' [-Wformat-pedantic] /home/marxin/Programming/gcc/gcc/ggc-page.c:947:7: warning: format specifies type 'void *' but the argument has type 'char *' [-Wformat-pedantic] /home/marxin/Programming/gcc/gcc/ggc-page.c:980:20: warning: format specifies type 'void *' but the argument has type 'char *' [-Wformat-pedantic] /home/marxin/Programming/gcc/gcc/ggc-page.c:980:7: warning: format specifies type 'void *' but the argument has type 'char *' [-Wformat-pedantic] /home/marxin/Programming/gcc/gcc/omp-grid.c:1069:7: warning: comparison of two values with different enumeration types in switch statement ('enum tree_code' and 'omp_clause_code') [-Wenum-compare-switch] /home/marxin/Programming/gcc/gcc/omp-grid.c:1080:7: warning: comparison of two values with different enumeration types in switch statement ('enum tree_code' and 'omp_clause_code') [-Wenum-compare-switch] /home/marxin/Programming/gcc/gcc/omp-grid.c:1081:7: warning: comparison of two values with different enumeration types in switch statement ('enum tree_code' and 'omp_clause_code') [-Wenum-compare-switch] /home/marxin/Programming/gcc/gcc/omp-grid.c:1082:7: warning: comparison of two values with different enumeration types in switch statement ('enum tree_code' and 'omp_clause_code') [-Wenum-compare-switch] /home/marxin/Programming/gcc/gcc/print-rtl.h:72:22: warning: private field 'm_rtx_reuse_manager' is not used [-Wunused-private-field] /home/marxin/Programming/gcc/gcc/reload1.c:3530:32: warning: unknown warning group '-Wmaybe-uninitialized', ignored [-Wunknown-warning-option] /home/marxin/Programming/gcc/gcc/tree.c:13462:16: warning: result of comparison of constant 42405 with expression of type 'enum tree_code' is always false [-Wtautological-constant-out-of-range-compare] /home/marxin/Programming/gcc/gcc/tree.c:13840:28: warning: use of logical '&&' with constant operand [-Wconstant-logical-operand] /home/marxin/Programming/gcc/libcpp/include/cpplib.h:897:14: warning: private field 'm_line_table' is not used [-Wunused-private-field] /home/marxin/Programming/gcc/libcpp/include/cpplib.h:897:14: warning: private field 'm_line_table' is not used [-Wunused-private-field] libtool: install: warning: remember to run `libtool --finish /home/marxin/bin/gcc/lib/gcc/x86_64-pc-linux-gnu/10.0.0' Apart from that, it noticed 2 warnings that I'm going to address in a separate patch. I'm going to install it. Martin ChangeLog: contrib/filter-clang-warnings.py: Transform from filter-rtags-warnings.py. --- ...s-warnings.py => filter-clang-warnings.py} | 47 ++++++++++--------- 1 file changed, 24 insertions(+), 23 deletions(-) rename contrib/{filter-rtags-warnings.py => filter-clang-warnings.py} (66%)
diff --git a/contrib/filter-rtags-warnings.py b/contrib/filter-clang-warnings.py similarity index 66% rename from contrib/filter-rtags-warnings.py rename to contrib/filter-clang-warnings.py index ee27e7c8942..15cca5ff2df 100755 --- a/contrib/filter-rtags-warnings.py +++ b/contrib/filter-clang-warnings.py @@ -1,7 +1,6 @@ #!/usr/bin/env python3 # -# Script to analyze warnings produced by rtags command (using LLVM): -# rc --diagnose-all --synchronous-diagnostics --json +# Script to analyze warnings produced by clang. # # This file is part of GCC. # @@ -23,26 +22,26 @@ # import sys -import json import argparse -def skip_warning(filename, warning): +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'], + '-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'], - } - - message = warning['message'] + 'i386.md': ['-Wparentheses-equality', '-Wtautological-compare'], + 'sse.md': ['-Wparentheses-equality', '-Wtautological-compare'], + 'genautomata.c': ['-Wstring-plus-int'] - if warning['type'] == 'fixit': - return True + } for name, ignores in ignores.items(): for i in ignores: @@ -52,20 +51,22 @@ def skip_warning(filename, warning): 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') - +parser.add_argument('log', help = 'Log file with clang warnings') args = parser.parse_args() -data = json.load(open(args.json_file)) -file_warnings = data['checkStyle'] - +lines = [l.strip() for l in open(args.log)] 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'])) +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) -print('Total: %d' % total) +for l in sorted(messages): + print(l) +print('\nTotal warnings: %d' % total)