* [PATCH] Ignore warning about using different types of enums in switch
@ 2017-12-12 21:37 Simon Marchi
2017-12-30 4:33 ` Simon Marchi
0 siblings, 1 reply; 2+ messages in thread
From: Simon Marchi @ 2017-12-12 21:37 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
When compiling with clang 6, I see a bunch of warnings like this:
/home/emaisin/src/binutils-gdb/gdb/amd64-linux-tdep.c:1427:8: error: comparison of two values with different enumeration types in switch statement ('enum amd64_syscall' and 'amd
64_x32_syscall') [-Werror,-Wenum-compare-switch]
case amd64_x32_sys_move_pages:
^~~~~~~~~~~~~~~~~~~~~~~~
In this switch, we indeed use enumerators of both types
amd64_x32_syscall and amd64_syscall. This is done on purpose, and the
enum values are chosen so that they are complementary.
I think it's still a useful warning, so I chose to ignore just that
particular case.
gdb/ChangeLog:
* common/diagnostics.h
(DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES): New macro.
* amd64-linux-tdep.c: Use it.
---
gdb/amd64-linux-tdep.c | 5 +++++
gdb/common/diagnostics.h | 5 +++++
2 files changed, 10 insertions(+)
diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c
index 87f09a4..1817456 100644
--- a/gdb/amd64-linux-tdep.c
+++ b/gdb/amd64-linux-tdep.c
@@ -363,6 +363,9 @@ amd64_all_but_ip_registers_record (struct regcache *regcache)
static enum gdb_syscall
amd64_canonicalize_syscall (enum amd64_syscall syscall_number)
{
+ DIAGNOSTIC_PUSH
+ DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
+
switch (syscall_number) {
case amd64_sys_read:
case amd64_x32_sys_read:
@@ -1430,6 +1433,8 @@ amd64_canonicalize_syscall (enum amd64_syscall syscall_number)
default:
return gdb_sys_no_syscall;
}
+
+ DIAGNOSTIC_POP
}
/* Parse the arguments of current system call instruction and record
diff --git a/gdb/common/diagnostics.h b/gdb/common/diagnostics.h
index d6ab698..30c0fd6 100644
--- a/gdb/common/diagnostics.h
+++ b/gdb/common/diagnostics.h
@@ -38,6 +38,8 @@
DIAGNOSTIC_IGNORE ("-Wdeprecated-register")
# define DIAGNOSTIC_IGNORE_UNUSED_FUNCTION \
DIAGNOSTIC_IGNORE ("-Wunused-function")
+# define DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES \
+ DIAGNOSTIC_IGNORE ("-Wenum-compare-switch")
#elif defined (__GNUC__) /* GCC */
@@ -45,12 +47,15 @@
# define DIAGNOSTIC_IGNORE_DEPRECATED_REGISTER
# define DIAGNOSTIC_IGNORE_UNUSED_FUNCTION \
DIAGNOSTIC_IGNORE ("-Wunused-function")
+# define DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
#else /* Other compilers */
# define DIAGNOSTIC_IGNORE_SELF_MOVE
# define DIAGNOSTIC_IGNORE_DEPRECATED_REGISTER
# define DIAGNOSTIC_IGNORE_UNUSED_FUNCTION
+# define DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
+
#endif
#endif /* COMMON_DIAGNOSTICS_H */
--
2.7.4
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Ignore warning about using different types of enums in switch
2017-12-12 21:37 [PATCH] Ignore warning about using different types of enums in switch Simon Marchi
@ 2017-12-30 4:33 ` Simon Marchi
0 siblings, 0 replies; 2+ messages in thread
From: Simon Marchi @ 2017-12-30 4:33 UTC (permalink / raw)
To: Simon Marchi; +Cc: gdb-patches
On 2017-12-12 16:37, Simon Marchi wrote:
> When compiling with clang 6, I see a bunch of warnings like this:
>
> /home/emaisin/src/binutils-gdb/gdb/amd64-linux-tdep.c:1427:8: error:
> comparison of two values with different enumeration types in switch
> statement ('enum amd64_syscall' and 'amd
> 64_x32_syscall') [-Werror,-Wenum-compare-switch]
> case amd64_x32_sys_move_pages:
> ^~~~~~~~~~~~~~~~~~~~~~~~
>
> In this switch, we indeed use enumerators of both types
> amd64_x32_syscall and amd64_syscall. This is done on purpose, and the
> enum values are chosen so that they are complementary.
>
> I think it's still a useful warning, so I chose to ignore just that
> particular case.
>
> gdb/ChangeLog:
>
> * common/diagnostics.h
> (DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES): New macro.
> * amd64-linux-tdep.c: Use it.
> ---
> gdb/amd64-linux-tdep.c | 5 +++++
> gdb/common/diagnostics.h | 5 +++++
> 2 files changed, 10 insertions(+)
>
> diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c
> index 87f09a4..1817456 100644
> --- a/gdb/amd64-linux-tdep.c
> +++ b/gdb/amd64-linux-tdep.c
> @@ -363,6 +363,9 @@ amd64_all_but_ip_registers_record (struct regcache
> *regcache)
> static enum gdb_syscall
> amd64_canonicalize_syscall (enum amd64_syscall syscall_number)
> {
> + DIAGNOSTIC_PUSH
> + DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
> +
> switch (syscall_number) {
> case amd64_sys_read:
> case amd64_x32_sys_read:
> @@ -1430,6 +1433,8 @@ amd64_canonicalize_syscall (enum amd64_syscall
> syscall_number)
> default:
> return gdb_sys_no_syscall;
> }
> +
> + DIAGNOSTIC_POP
> }
>
> /* Parse the arguments of current system call instruction and record
> diff --git a/gdb/common/diagnostics.h b/gdb/common/diagnostics.h
> index d6ab698..30c0fd6 100644
> --- a/gdb/common/diagnostics.h
> +++ b/gdb/common/diagnostics.h
> @@ -38,6 +38,8 @@
> DIAGNOSTIC_IGNORE ("-Wdeprecated-register")
> # define DIAGNOSTIC_IGNORE_UNUSED_FUNCTION \
> DIAGNOSTIC_IGNORE ("-Wunused-function")
> +# define DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES \
> + DIAGNOSTIC_IGNORE ("-Wenum-compare-switch")
>
> #elif defined (__GNUC__) /* GCC */
>
> @@ -45,12 +47,15 @@
> # define DIAGNOSTIC_IGNORE_DEPRECATED_REGISTER
> # define DIAGNOSTIC_IGNORE_UNUSED_FUNCTION \
> DIAGNOSTIC_IGNORE ("-Wunused-function")
> +# define DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
>
> #else /* Other compilers */
>
> # define DIAGNOSTIC_IGNORE_SELF_MOVE
> # define DIAGNOSTIC_IGNORE_DEPRECATED_REGISTER
> # define DIAGNOSTIC_IGNORE_UNUSED_FUNCTION
> +# define DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
> +
> #endif
>
> #endif /* COMMON_DIAGNOSTICS_H */
I pushed this one.
Simon
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-12-30 4:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-12 21:37 [PATCH] Ignore warning about using different types of enums in switch Simon Marchi
2017-12-30 4:33 ` Simon Marchi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).