Ignore warning about using different types of enums in switch
authorSimon Marchi <simon.marchi@ericsson.com>
Sat, 30 Dec 2017 04:32:13 +0000 (23:32 -0500)
committerSimon Marchi <simon.marchi@ericsson.com>
Sat, 30 Dec 2017 04:32:29 +0000 (23:32 -0500)
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 (amd64_canonicalize_syscall): Use it.

gdb/ChangeLog
gdb/amd64-linux-tdep.c
gdb/common/diagnostics.h

index bba278e1d665c1fdc3c96250d6292771fb03654b..9cc060e6d969c7a73061995b89a90174290ff786 100644 (file)
@@ -1,3 +1,9 @@
+2017-12-29  Simon Marchi  <simon.marchi@ericsson.com>
+
+       * common/diagnostics.h
+       (DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES): New macro.
+       * amd64-linux-tdep.c (amd64_canonicalize_syscall): Use it.
+
 2017-12-29  Simon Marchi  <simon.marchi@ericsson.com>
 
        * linux-thread-db.c (thread_db_detach): Remove call to
index 87f09a4542bfb26d3068f91ec91a6170c363bdd0..181745657e244d9888d2e18c7fb7662f548e22f3 100644 (file)
@@ -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
index d6ab69891656dd7217e5e2f22a282b272ceb9843..30c0fd6172a16a5f05bebfa4889855dfc5336be9 100644 (file)
@@ -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 */
 
 # 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 */
This page took 0.057584 seconds and 4 git commands to generate.