From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-sender-0.a4lg.com (mail-sender-0.a4lg.com [IPv6:2401:2500:203:30b:4000:6bfe:4757:0]) by sourceware.org (Postfix) with ESMTPS id D8F823895FE8; Thu, 15 Sep 2022 03:10:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D8F823895FE8 Received: from [127.0.0.1] (localhost [127.0.0.1]) by mail-sender-0.a4lg.com (Postfix) with ESMTPSA id 2990D300089; Thu, 15 Sep 2022 03:10:32 +0000 (UTC) From: Tsukasa OI To: Tsukasa OI , Pedro Alves , Joel Brobecker , Enze Li Cc: gdb-patches@sourceware.org, binutils@sourceware.org Subject: [PATCH 0/4] gdb: (includes PR28413), Suppress some general warnings if built with Clang Date: Thu, 15 Sep 2022 03:10:22 +0000 Message-Id: Mime-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Sep 2022 03:10:36 -0000 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. [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: 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: fe39ffdc202f04397f31557f17170b40bc42b77a -- 2.34.1