sim: add default cases to two switches in sim-options.c
authorSimon Marchi <simon.marchi@polymtl.ca>
Sun, 2 May 2021 15:04:58 +0000 (11:04 -0400)
committerSimon Marchi <simon.marchi@polymtl.ca>
Sun, 2 May 2021 15:04:58 +0000 (11:04 -0400)
This is the next compilation error I hit when I build all targets with
Clang:

    /home/simark/src/binutils-gdb/sim/aarch64/../common/sim-options.c:234:12: error: no case matching constant switch condition '0' [-Werror]                                                                    switch (WITH_ENVIRONMENT)
                      ^~~~~~~~~~~~~~~~                                                                                                                                                                 ./config.h:215:26: note: expanded from macro 'WITH_ENVIRONMENT'
    #define WITH_ENVIRONMENT ALL_ENVIRONMENT                                                                                                                                                                                    ^~~~~~~~~~~~~~~
    /home/simark/src/binutils-gdb/sim/aarch64/../common/sim-options.c:276:15: error: no case matching constant switch condition '0' [-Werror]                                                                switch (WITH_ALIGNMENT)
                  ^~~~~~~~~~~~~~                                                                                                                                                                       /home/simark/src/binutils-gdb/sim/aarch64/../common/sim-config.h:220:24: note: expanded from macro 'WITH_ALIGNMENT'
    #define WITH_ALIGNMENT 0
                           ^

This is a little bit special because these are switches on compile-time
value.  But regardless, the idea is that we logically can't reach the
switches if WITH_ENVIRONMENT == 0 or WITH_ALIGNMENT == 0, so the code is
correct.

In addition to getting rid of the compiler warning, adding default cases
to these switches ensure that if we do get in an unexpected situation,
it is caught.  In GDB, I'd use gdb_assert_not_reached, I don't know if
there is something similar in sim so I went with abort.

sim/common/ChangeLog:

* sim-options.c (standard_option_handler): Add default cases to
switches.

Change-Id: Ie237d67a201caa6b72de0d17cc815193417156b6

sim/common/ChangeLog
sim/common/sim-options.c

index 4aeae9c9209cc5ed2985626af10c5836a7140a4b..fd9a5dd70ff0e7447596982b6764c4574f539712 100644 (file)
@@ -1,3 +1,8 @@
+2021-05-02  Simon Marchi  <simon.marchi@polymtl.ca>
+
+       * sim-options.c (standard_option_handler): Add default cases to
+       switches.
+
 2021-05-02  Mike Frysinger  <vapier@gentoo.org>
 
        * callback.c (os_error): Change __attribute__((noreturn)) to
index 1522cac9379fec0a998f00240052f6db1045fe7d..1efb21fc62b8c7be4e12b3de9862e52d350c605f 100644 (file)
@@ -236,6 +236,7 @@ standard_option_handler (SIM_DESC sd, sim_cpu *cpu, int opt,
            case USER_ENVIRONMENT: type = "user"; break;
            case VIRTUAL_ENVIRONMENT: type = "virtual"; break;
            case OPERATING_ENVIRONMENT: type = "operating"; break;
+           default: abort ();
            }
          sim_io_eprintf (sd, "Simulator compiled for the %s environment only.\n",
                          type);
@@ -284,6 +285,7 @@ standard_option_handler (SIM_DESC sd, sim_cpu *cpu, int opt,
        case FORCED_ALIGNMENT:
          sim_io_eprintf (sd, "Simulator compiled for forced alignment only.\n");
          break;
+       default: abort ();
        }
       return SIM_RC_FAIL;