From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 7hpxLZhanWF6OQAAWB0awg (envelope-from ) for ; Tue, 23 Nov 2021 16:18:16 -0500 Received: by simark.ca (Postfix, from userid 112) id A8C0C1F0CE; Tue, 23 Nov 2021 16:18:16 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 0DDB51EDF0 for ; Tue, 23 Nov 2021 16:18:16 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9C8CA3858421 for ; Tue, 23 Nov 2021 21:18:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9C8CA3858421 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1637702295; bh=VnMqejFiY2SP1LKcViPbuOzfIxGNUoxclbOXCt1fbsk=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=p6rbJ8KjtzVtiP+HAhOQGBkdYKgH1PrmWt8qO439tZ5qOC++wz3xaVzaaSnrKEV2U 4ski6+gYEepK7CDIiUVJBwunHONmurtxZRY3AvSoIihR5oaicNyQa8HZumiJ71heU4 3lgz8y86XJFMaYNKocdQsIOM/mKXuuGT2cXmLQLc= Received: from barracuda.ebox.ca (barracuda.ebox.ca [96.127.255.19]) by sourceware.org (Postfix) with ESMTPS id 65A383858408 for ; Tue, 23 Nov 2021 21:14:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 65A383858408 X-ASG-Debug-ID: 1637702079-0c856e2e4727f830001-fS2M51 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id ilQJM7tcipbztaXT (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 23 Nov 2021 16:14:39 -0500 (EST) X-Barracuda-Envelope-From: simon.marchi@efficios.com X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from epycamd.internal.efficios.com (192-222-180-24.qc.cable.ebox.net [192.222.180.24]) by smtp.ebox.ca (Postfix) with ESMTP id 3E86D441D64; Tue, 23 Nov 2021 16:14:39 -0500 (EST) X-Barracuda-RBL-IP: 192.222.180.24 X-Barracuda-Effective-Source-IP: 192-222-180-24.qc.cable.ebox.net[192.222.180.24] X-Barracuda-Apparent-Source-IP: 192.222.180.24 To: gdb-patches@sourceware.org, binutils@sourceware.org Subject: [PATCH 2/2] include, gdb: fix -Wswitch build errors with gcc 4.8 Date: Tue, 23 Nov 2021 16:14:37 -0500 X-ASG-Orig-Subj: [PATCH 2/2] include, gdb: fix -Wswitch build errors with gcc 4.8 Message-Id: <20211123211437.3783065-2-simon.marchi@efficios.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211123211437.3783065-1-simon.marchi@efficios.com> References: <20211123211437.3783065-1-simon.marchi@efficios.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Barracuda-Connect: smtp.ebox.ca[96.127.255.82] X-Barracuda-Start-Time: 1637702079 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at ebox.ca X-Barracuda-Scan-Msg-Size: 3813 X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.94162 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 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: , From: Simon Marchi via Gdb-patches Reply-To: Simon Marchi Cc: Simon Marchi Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" I started seeing these strange errors when building with gcc 4.8: CXX ada-tasks.o /home/smarchi/src/binutils-gdb/gdb/ada-tasks.c: In function ‘void read_known_tasks()’: /home/smarchi/src/binutils-gdb/gdb/ada-tasks.c:998:10: error: enumeration value ‘ADA_TASKS_UNKNOWN’ not handled in switch [-Werror=switch] switch (data->known_tasks_kind) ^ It is caused by commit 06de25b7af21 ("gdb: introduce target_waitkind_str, use it in target_waitstatus::to_string"), which introduced some pragmas to enable -Wswitch locally. That shouldn't affect the rest of the code, since we are using push and pop around that. It looks like gcc 4.8 (and 4.9)'s diagnostic push/pop is not reliable, as it doesn't cause a problem with later versions. Work around this by not enabling -Wswitch for GCC < 5. This makes the code a bit ugly, it would be nice to find a good way to factor this out, especially if we want to re-use it elsewhere. But for now, I just want to un-break the build. Note that this code (already as it exists in master today) enables -Wswitch at the error level even if --disable-werror is passed. It shouldn't be a problem, as it's not like a new enumerator will appear out of nowhere. So it shouldn't cause a spurious build error in the future. Still, for correctness, we would ideally want to ask the compiler to enable -Wswitch at its default level (as if the user had passed -Wswitch on the command-line). There doesn't seem to be a way to do this. Change-Id: I50d66b348bf83de099c3c0879e2eb352d60540ba --- gdb/target/waitstatus.c | 9 ++++++++- gdb/target/waitstatus.h | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/gdb/target/waitstatus.c b/gdb/target/waitstatus.c index 0fbcec5b7c8..e2388aa80b8 100644 --- a/gdb/target/waitstatus.c +++ b/gdb/target/waitstatus.c @@ -29,9 +29,14 @@ target_waitstatus::to_string () const ("status->kind = %s", target_waitkind_str (this->kind ())); /* Make sure the compiler warns if a new TARGET_WAITKIND enumerator is added - but not handled here. */ + but not handled here. + + GCC 4.8's "diagnostic push/pop" seems broken, it leaves -Werror=switch + enabled after the pop. Skip it for GCC < 5. */ DIAGNOSTIC_PUSH +#if (defined(__GNUC__) && __GNUC__ >= 5) || defined(__clang__) DIAGNOSTIC_ERROR_SWITCH +#endif switch (this->kind ()) { case TARGET_WAITKIND_EXITED: @@ -63,7 +68,9 @@ DIAGNOSTIC_ERROR_SWITCH case TARGET_WAITKIND_THREAD_CREATED: return str; } +#if (defined(__GNUC__) && __GNUC__ >= 5) || defined(__clang__) DIAGNOSTIC_POP +#endif gdb_assert_not_reached ("invalid target_waitkind value: %d", (int) this->kind ()); diff --git a/gdb/target/waitstatus.h b/gdb/target/waitstatus.h index 5b537354184..59014a37362 100644 --- a/gdb/target/waitstatus.h +++ b/gdb/target/waitstatus.h @@ -108,9 +108,14 @@ static inline const char * target_waitkind_str (target_waitkind kind) { /* Make sure the compiler warns if a new TARGET_WAITKIND enumerator is added - but not handled here. */ + but not handled here. + + GCC 4.8's "diagnostic push/pop" seems broken, it leaves -Werror=switch + enabled after the pop. Skip it for GCC < 5. */ DIAGNOSTIC_PUSH +#if (defined(__GNUC__) && __GNUC__ >= 5) || defined(__clang__) DIAGNOSTIC_ERROR_SWITCH +#endif switch (kind) { case TARGET_WAITKIND_EXITED: @@ -146,7 +151,9 @@ DIAGNOSTIC_ERROR_SWITCH case TARGET_WAITKIND_THREAD_EXITED: return "THREAD_EXITED"; }; +#if (defined(__GNUC__) && __GNUC__ >= 5) || defined(__clang__) DIAGNOSTIC_POP +#endif gdb_assert_not_reached ("invalid target_waitkind value: %d\n", (int) kind); } -- 2.33.1