Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi via Gdb-patches <gdb-patches@sourceware.org>
To: gdb-patches@sourceware.org, binutils@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH 2/2] include, gdb: fix -Wswitch build errors with gcc 4.8
Date: Tue, 23 Nov 2021 16:14:37 -0500	[thread overview]
Message-ID: <20211123211437.3783065-2-simon.marchi@efficios.com> (raw)
In-Reply-To: <20211123211437.3783065-1-simon.marchi@efficios.com>

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


  reply	other threads:[~2021-11-23 21:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-23 21:14 [PATCH 1/2] gdb: replace pragmas with DIAGNOSTIC macros Simon Marchi via Gdb-patches
2021-11-23 21:14 ` Simon Marchi via Gdb-patches [this message]
2021-12-02  0:25   ` [PATCH 2/2] include, gdb: fix -Wswitch build errors with gcc 4.8 Tom de Vries via Gdb-patches
2021-12-02  2:45     ` Simon Marchi via Gdb-patches
     [not found] ` <ef91c0eb-4faf-225e-0549-38a08d65858b@suse.de>
2021-12-02  1:56   ` [PATCH 1/2] gdb: replace pragmas with DIAGNOSTIC macros Simon Marchi via Gdb-patches
2021-12-02  2:44     ` Simon Marchi via Gdb-patches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211123211437.3783065-2-simon.marchi@efficios.com \
    --to=gdb-patches@sourceware.org \
    --cc=binutils@sourceware.org \
    --cc=simon.marchi@efficios.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox