[v2,0/4] gdb: (includes PR28413), Suppress some general warnings if built with Clang

Message ID cover.1663835104.git.research_trasio@irq.a4lg.com
Headers
Series gdb: (includes PR28413), Suppress some general warnings if built with Clang |

Message

Tsukasa OI Sept. 22, 2022, 8:25 a.m. UTC
  Hello,

[Common Background: Building GNU Binutils / GDB with Clang 15.0.0]

I'm now testing to build GNU Binutils / GDB with latest Clang (15.0.0) and
found some errors by default (when Binutils / GDB is not configured with
"--disable-werror").

While the best compiler to build GNU Binutils / GDB is GNU GCC, testing
other compilers are helpful to discover underlying problems and modernize
Binutils / GDB, even if building entire Binutils / GDB with the latest Clang
is unrealistic.  To be sure, I'm not going to finish "porting for Clang".
I will take low-hanging fruits and...

1.  make building with Clang easier and/or
2.  fix code issues (or non-issues) discovered as Clang warnings.

I made four patchsets in which, applying them all makes it possible to
build GNU Binutils / GDB with Clang (without help of --disable-werrors) for
many (but not all) targets including i386 and RISC-V with Ubuntu 22.04 LTS
(x86_64) host.  At least, I think they fix all (at minimum, most of) arch-
independent parts which prevents building with the latest version of Clang.

This is the one of them.


[Changes: v1 -> v2]

-   Fix commit messages
    (commit message of PATCH 4/4 was very wrong)


[About this Patchset]

This patchset deals with two kinds of warnings but with similar methods.

1.  gdb/unittests: PR28413, suppress custom warnings by Gnulib
    (PATCH 1/4, 3/4)

Gnulib generates a warning ("-Wuser-defined-warnings" on Clang) if the
system version of certain functions are used (to redirect the developer to
use Gnulib version).  However, this behavior is found harmful to
gdb/unittests/string_view-selftests.c, making the build failure.

This issue occurs if:

-   Compiled with Clang
-   -Werror is specified (by default)
-   C++ standard used by Clang is before C++17 (by default as of 15.0.0)
    when this unit test is activated.

This error is identified as PR28413.

Warnings about "free" may be resolved by modifying libiberty part but one of
the warnings generated by Gnulib points at the C++ standard library.

So, directly fixing the location which generates the warning is partially
impossible.  In the past, there were a proposal to fix this issue from the
Gnulib side:
<https://lists.gnu.org/archive/html/bug-gnulib/2021-10/msg00003.html>
but rejected because it ruins the intent of Gnulib warnings.  So, a fix from
the Binutils / GDB side is desired.

2.  gdb: Suppress "unused" variable warning on Clang in Bison-generated code
    (PATCH 2/4, 4/4)

Clang generates a warning on "written but not read thereafter" varibles
("-Wset-but-unused-variable"), making the build failure.

The unique problem here is, the cause is the variable yynerrs in
$(builddir)/gdb/cp-name-parser.c, generated by
$(srcdir)/gdb/cp-name-parser.y.  So, directly fixing the location which
causes the warning is nonfeasible.


In either cases, we can resolve the problem if we use include/diagnostics.h.
This header file defines a set of macros to suppress certain warnings only
when necessary.  In this patchset (PATCH 1-2/4), it adds two "ignore
warning" macros and uses them when necessary (PATCH 3-4/4).

This is mainly a GDB-side fix.  But since it contains changes to shared
part (includes/diagnostics.h), this patchset is also posted to Binutils ML.


Thanks,
Tsukasa




Tsukasa OI (4):
  include: Add macro to ignore -Wuser-defined-warnings
  include: Add macro to ignore -Wunused-but-set-variable
  gdb/unittests: PR28413, suppress warnings generated by Gnulib
  gdb: Suppress "unused" variable warning on Clang

 gdb/cp-name-parser.y                  |  4 ++++
 gdb/unittests/string_view-selftests.c |  5 +++++
 include/diagnostics.h                 | 23 +++++++++++++++++++++++
 3 files changed, 32 insertions(+)


base-commit: b59f8a90ba0866a8605106fdb09389833c7fe8ad