Files
gcc/contrib/filter-clang-warnings.py
Martin Jambor f555ee597a Ignore more clang warnings in contrib/filter-clang-warnings.py
in contrib we have a script filter-clang-warnings.py which supposedly
filters out uninteresting warnings emitted by clang when it compiles
GCC.  I'm not sure if anyone else uses it but our internal SUSE
testing infrastructure does.

Since Martin Liška left, I have mostly ignored the warnings and so
they have multiplied.  In an effort to improve the situation, I have
tried to fix those warnings which I think are worth it and would like
to adjust the filtering script so that we get to zero "interesting"
warnings again.

The changes are the following:

1. Ignore -Woverloaded-shift-op-parentheses warnings.  IIUC, those
   make some sense when << and >> are used for I/O but since that is
   not the case in GCC they are not really interesting.

2. Ignore -Wunused-function and -Wunneeded-internal-declaration.  I
   think it is OK to occasionally prepare APIs before they are used
   (and with our LTO we should be able to get rid of them).

3. Ignore -Wvla-cxx-extension and -Wunused-command-line-argument which
   just don't seem to be useful.

4. Ignore -Wunused-private-field warning in diagnostic-path-output.cc
   which can only be correct if quite a few functions are removed and
   looks like it is just not an oversight:

     gcc/diagnostic-path-output.cc:271:35: warning: private field 'm_logical_loc_mgr' is not used [-Wunused-private-field]

5. Ignore a case in -Wunused-but-set-variable about named_args which
   is used in a piece of code behind an ifdef in ipa-strub.cc.

6. Adjust the gimple-match and generic-match filters to the fact that
   we now have multiple such files.

7. Ignore warnings about using memcpy to copy around wide_ints, like
   the one below.  I seem to remember wide-int has undergone fairly
   rigorous review and TBH I just hope I know what we are doing.

     gcc/wide-int.h:1198:11: warning: first argument in call to 'memcpy' is a pointer to non-trivially copyable type 'wide_int_storage' [-Wnontrivial-memcall]

8. Ignore -Wc++11-narrowing warning reported in omp-builtins.def when
   it is included from JIT.  The code probably has a bigger issue
   described in PR 120960.

9. Since the patch number 14 in the original series did not get
   approved, I assume that private member field m_wanted_type of class
   element_expected_type_with_indirection in c-family/c-format.cc will
   get a use sooner or later, so I ignore a warning about it being
   unused.

10. I have decided to ignore warnings in m2/gm2-compiler-boot about
    unused stuff (all reported unused stuff are variables).  These
    sources are in the build directory so I assume they are somehow
    generated and so warnings about unused things are a bit expected
    and probably not too bad.

11. On the Zulip chat, I have informed Rust folks they have a bunch of
    -Wunused-private-field cases in the FE.  Until they sort it out
    I'm ignoring these.  I might add the missing explicit type-cast
    case here too if it takes time for the patch I'm posting in this
    series to reach master.

12. I ignore warning about use of offsetof in libiberty/sha1.c which is
    apparently only a "C23 extension:"

      libiberty/sha1.c:239:11: warning: defining a type within 'offsetof' is a C23 extension [-Wc23-extensions]
      libiberty/sha1.c:460:11: warning: defining a type within 'offsetof' is a C23 extension [-Wc23-extensions]

13. I have enlarged the list of .texi files where warnings somehow got
    reported.  Not sure why that happens.

14. In analyzer/sm.cc there are several "no-op" methods which have
    named but unused parameters.  It seems this is deliberate and so I
    have filtered the -Wunused-parameter warning for this file.

I have also re-arranged the entries in a way which hopefully makes
somewhat more sense.

Thanks,

Martin

contrib/ChangeLog:

2025-07-07  Martin Jambor  <mjambor@suse.cz>

	* filter-clang-warnings.py (skip_warning): Also ignore
	-Woverloaded-shift-op-parentheses, -Wunused-function,
	-Wunneeded-internal-declaration, -Wvla-cxx-extension', and
	-Wunused-command-line-argument everywhere and a warning about
	m_logical_loc_mgr in diagnostic-path-output.cc.  Adjust gimple-match
	and generic-match "filenames."  Ignore -Wnontrivial-memcall warnings
	in wide-int.h, all warnings about unused stuff in files under
	m2/gm2-compiler-boot, all -Wunused-private-field in rust FE, in
	analyzer/ana-state-to-diagnostic-state.h and c-family/c-format.cc, all
	Warnings in avr-mmcu.texi, install.texi and libgccjit.texi and all
	-Wc23-extensions warnings in libiberty/sha1.c. Ignore
	-Wunused-parameter in analyzer/sm.cc.  Reorder entries.
2025-07-07 21:50:22 +02:00

111 lines
4.4 KiB
Python
Executable File

#!/usr/bin/env python3
# Copyright (C) 2018-2025 Free Software Foundation, Inc.
#
# 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
# <http://www.gnu.org/licenses/>.
#
#
#
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', '-Wundefined-internal',
'-Wunknown-warning-option', '-Wc++20-extensions',
'-Wbitwise-instead-of-logical', 'egrep is obsolescent',
'-Woverloaded-shift-op-parentheses',
'-Wunused-function', '-Wunneeded-internal-declaration',
'-Wvla-cxx-extension', '-Wunused-command-line-argument'],
'diagnostic-path-output.cc': ['m_logical_loc_mgr'],
'fold-const-call.cc': ['-Wreturn-type'],
'gimple-match': ['-Wunused-', '-Wtautological-compare'],
'generic-match': ['-Wunused-', '-Wtautological-compare'],
'genautomata.cc': ['-Wstring-plus-int'],
# Perhaps revisit when ATTR_FNSPEC_DECONST_WATERMARK ifdef case is
# made default or removed:
'ipa-strub.cc': ['-Wunused-but-set-variable'],
'insn-modes.cc': ['-Wshift-count-overflow'],
'insn-emit.cc': ['-Wtautological-compare'],
'insn-attrtab.cc': ['-Wparentheses-equality'],
'omp-builtins.def': ['-Wc++11-narrowing'],
'wide-int.h': ['-Wnontrivial-memcall'],
'i386.md': ['-Wparentheses-equality', '-Wtautological-compare',
'-Wtautological-overlap-compare'],
'sse.md': ['-Wparentheses-equality', '-Wtautological-compare',
'-Wconstant-logical-operand'],
'mmx.md': ['-Wtautological-compare'],
'lex.cc': ['-Wc++20-attribute-extensions'],
# Perhaps remove once PR 120960 is resolved:
'analyzer/ana-state-to-diagnostic-state.h': ['-Wunused-private-field'],
'analyzer/sm.cc': ['-Wunused-parameter'],
'c-family/c-format.cc': ['-Wunused-private-field'],
'm2/gm2-compiler-boot': ['-Wunused-'],
# Rust peopel promised to clean these warnings too
'rust/': ['-Wunused-private-field'],
'libiberty/sha1.c': ['-Wc23-extensions'],
'avr-mmcu.texi': [''],
'gfortran.texi': [''],
'install.texi': [''],
'libgccjit.texi': [''],
'libtool': ['']
}
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)]
messages = set()
for line in lines:
token = ': warning: '
i = line.find(token)
if i != -1:
location = line[:i]
message = line[i + len(token):]
if '/libffi/' in location or location.startswith('Makefile'):
continue
if not skip_warning(location, message):
messages.add(line)
for line in sorted(messages):
print(line)
print('\nTotal warnings: %d' % len(messages))