]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Add GCC7 -Wimplicit-fallthrough support/fixes.
authorMark Wielaard <mjw@redhat.com>
Wed, 2 Nov 2016 12:29:26 +0000 (13:29 +0100)
committerMark Wielaard <mjw@redhat.com>
Thu, 10 Nov 2016 10:59:00 +0000 (11:59 +0100)
GCC7 will have a new -Wimplicit-fallthrough warning. It did catch one
small buglet in elflint option procession. So it seems useful to enable
to make sure all swatch case fallthroughs are deliberate.

Add configure check to detect whether gcc support -Wimplicit-fallthrough
and enable it. Add fixes and explicit fallthrough comments where necessary.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
25 files changed:
ChangeLog
backends/ChangeLog
backends/i386_regs.c
backends/i386_retval.c
backends/linux-core-note.c
backends/m68k_retval.c
backends/ppc_regs.c
backends/x86_64_regs.c
config/ChangeLog
config/eu.am
configure.ac
libcpu/ChangeLog
libcpu/i386_disasm.c
libdw/ChangeLog
libdw/cfi.c
libdw/encoded-value.h
libdwfl/dwfl_report_elf.c
src/ChangeLog
src/addr2line.c
src/elfcompress.c
src/elflint.c
src/objdump.c
tests/ChangeLog
tests/backtrace-data.c
tests/backtrace.c

index 8d615721595437ff387c1a8cfdf80d7db660295f..f21421f944272e3fe71cb4909c4d659ac1520e3d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,9 @@
-2015-10-11  Akihiko Odaki  <akihiko.odaki.4i@stu.hosei.ac.jp>
+2016-11-02  Mark Wielaard  <mjw@redhat.com>
+
+       * configure.ac: Add check for whether gcc accepts
+       -Wimplict-fallthrough.
+
+2016-10-11  Akihiko Odaki  <akihiko.odaki.4i@stu.hosei.ac.jp>
 
        * configure.ac: Add memrchr, rawmemchr and powerof2 checks.
 
index 53d2908119e61b5ef99b7fdb9c1ac8418c223b76..1c561b50183b8e2b86add4cdc8e55b0f92402683 100644 (file)
@@ -1,3 +1,14 @@
+2016-11-02  Mark Wielaard  <mjw@redhat.com>
+
+       * i386_regs.c (i386_register_info): Add fallthrough comment.
+       * i386_retval.c (i386_return_value_location): Move fallthrough
+       comment.
+       * linux-core-note.c (core_note): Adjust fallthrough comment.
+       * m68k_retval.c (m68k_return_value_location): Move fallthrough
+       comment.
+       * ppc_regs.c (ppc_register_info): Add fallthrough comment.
+       * x86_64_regs.c (x86_64_register_info): Likewise.
+
 2016-08-09  Jose E. Marchesi  <jose.marchesi@oracle.com>
 
        * sparc_attrs.c (sparc_check_object_attribute): Fix the
index fb8ded333d1df9a97e39af0abe656defe1b270be..fd963a62b465a181814caf6497bb42830e37382d 100644 (file)
@@ -92,6 +92,7 @@ i386_register_info (Ebl *ebl __attribute__ ((unused)),
     case 5:
     case 8:
       *type = DW_ATE_address;
+      /* Fallthrough */
     case 0 ... 3:
     case 6 ... 7:
       name[0] = 'e';
index 9da797d5ed52ed0124434c149c23ce75a2ef5530..4aa646fe7ddeae189bf8bd05223d4e647df1c20d 100644 (file)
@@ -122,9 +122,8 @@ i386_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
          return nloc_intreg;
        if (size <= 8)
          return nloc_intregpair;
-
-       /* Else fall through.  */
       }
+    /* Fallthrough */
 
     case DW_TAG_structure_type:
     case DW_TAG_class_type:
index a4ec0be07631676c304131df73b01d291a622e77..67638d7006ad7985d620188b59eb97639411716b 100644 (file)
@@ -225,8 +225,8 @@ EBLHOOK(core_note) (const GElf_Nhdr *nhdr, const char *name,
     case sizeof "CORE":
       if (memcmp (name, "CORE", nhdr->n_namesz) == 0)
        break;
-      /* Buggy old Linux kernels didn't terminate "LINUX".
-         Fall through.  */
+      /* Buggy old Linux kernels didn't terminate "LINUX".  */
+      /* Fall through. */
 
     case sizeof "LINUX":
       if (memcmp (name, "LINUX", nhdr->n_namesz) == 0)
index 2dd285a0718b303d45526102ea0953afa8f8f59f..c68ed02210e8bc1fd493fcd1d7bda91eee22490c 100644 (file)
@@ -134,10 +134,8 @@ m68k_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
          return nloc_intreg;
        if (size <= 8)
          return nloc_intregpair;
-
-       /* Else fall through.  */
       }
-
+      /* Fallthrough */
     case DW_TAG_structure_type:
     case DW_TAG_class_type:
     case DW_TAG_union_type:
index 4b92a9aa98c4b6686d45b175150535eb0de13002..bcf4f7a3e72f7232fc8041fead111ccb45b1ab53 100644 (file)
@@ -140,7 +140,7 @@ ppc_register_info (Ebl *ebl __attribute__ ((unused)),
     case 100:
       if (*bits == 32)
        return stpcpy (name, "mq") + 1 - name;
-
+      /* Fallthrough */
     case 102 ... 107:
       name[0] = 's';
       name[1] = 'p';
index 2172d9f1d2b41f25c7d60ffd3c5734fdc58b0fee..843044071145968fb6a48ff0472e4b43f4a3124c 100644 (file)
@@ -87,6 +87,7 @@ x86_64_register_info (Ebl *ebl __attribute__ ((unused)),
 
     case 6 ... 7:
       *type = DW_ATE_address;
+      /* Fallthrough */
     case 0 ... 5:
       name[0] = 'r';
       name[1] = baseregs[regno][0];
index 2ca25bc33ca9b729276cbd4cfe76486c5f6332fd..a18fa847caf00de596cdc4079007e09e567b8785 100644 (file)
@@ -1,3 +1,8 @@
+2016-11-02  Mark Wielaard  <mjw@redhat.com>
+
+       * eu.am: Check HAVE_IMPLICIT_FALLTHROUGH_WARNING.
+       (AM_CFLAGS): Add IMPLICIT_FALLTHROUGH_WARNING.
+
 2016-08-04  Mark Wielaard  <mjw@redhat.com>
 
        * elfutils.spec.in: Update for 0.167.
index 4998771dc115e90aa92193efbf3e6779963bba58..8fe1e259f9e234d9da046a620fe92be5d5703414 100644 (file)
@@ -61,10 +61,16 @@ else
 NULL_DEREFERENCE_WARNING=
 endif
 
+if HAVE_IMPLICIT_FALLTHROUGH_WARNING
+IMPLICIT_FALLTHROUGH_WARNING=-Wimplicit-fallthrough
+else
+IMPLICIT_FALLTHROUGH_WARNING=
+endif
+
 AM_CFLAGS = -std=gnu99 -Wall -Wshadow -Wformat=2 \
            -Wold-style-definition -Wstrict-prototypes \
            $(LOGICAL_OP_WARNING) $(DUPLICATED_COND_WARNING) \
-           $(NULL_DEREFERENCE_WARNING) \
+           $(NULL_DEREFERENCE_WARNING) $(IMPLICIT_FALLTHROUGH_WARNING) \
            $(if $($(*F)_no_Werror),,-Werror) \
            $(if $($(*F)_no_Wunused),,-Wunused -Wextra) \
            $(if $($(*F)_no_Wstack_usage),,$(STACK_USAGE_WARNING)) \
index c02d4c2a92fd96cec58610091bb382d5edb442c6..c55fb9b45595948d5f9c4634ac170007b79c5d06 100644 (file)
@@ -311,6 +311,16 @@ CFLAGS="$old_CFLAGS"])
 AM_CONDITIONAL(HAVE_NULL_DEREFERENCE_WARNING,
               [test "x$ac_cv_null_dereference" != "xno"])
 
+# -Wimplicit-fallthrough was added by GCC7
+AC_CACHE_CHECK([whether gcc accepts -Wimplicit-fallthrough], ac_cv_implicit_fallthrough, [dnl
+old_CFLAGS="$CFLAGS"
+CFLAGS="$CFLAGS -Wimplicit-fallthrough -Werror"
+AC_COMPILE_IFELSE([AC_LANG_SOURCE([])],
+                 ac_cv_implicit_fallthrough=yes, ac_cv_implicit_fallthrough=no)
+CFLAGS="$old_CFLAGS"])
+AM_CONDITIONAL(HAVE_IMPLICIT_FALLTHROUGH_WARNING,
+              [test "x$ac_cv_implicit_fallthrough" != "xno"])
+
 dnl Check if we have argp available from our libc
 AC_LINK_IFELSE(
        [AC_LANG_PROGRAM(
index fff1d96a8ecb8d0d237d413c649536991e176bcc..79110c22135561f023ae7221b5c225fdd661d406 100644 (file)
@@ -1,4 +1,8 @@
-2015-10-11  Akihiko Odaki  <akihiko.odaki.4i@stu.hosei.ac.jp>
+2016-11-02  Mark Wielaard  <mjw@redhat.com>
+
+       * i386_disasm.c (i386_disasm): Add fallthrough comment.
+
+2016-10-11  Akihiko Odaki  <akihiko.odaki.4i@stu.hosei.ac.jp>
 
        * i386_lex.l: Remove system.h include, add libeu.h include.
        * i386_parse.y: Remove sys/param.h include, add libeu.h include.
index 699dd6199f5c591540d92bd1dd088c2c44ac83aa..831afbe20166baf912aca2582f57748ac812bd2b 100644 (file)
@@ -819,7 +819,7 @@ i386_disasm (Ebl *ebl __attribute__((unused)),
                              ++param_start;
                              break;
                            }
-
+                         /* Fallthrough */
                        default:
                          assert (! "INVALID not handled");
                        }
index c2f25ea625ad2a5f594ea4f5183ce7f5d23151d8..cc92f1634b58a0d5a8b3ee9eb0776b6986a3a913 100644 (file)
@@ -1,4 +1,12 @@
-2015-10-11  Akihiko Odaki  <akihiko.odaki.4i@stu.hosei.ac.jp>
+2016-11-02  Mark Wielaard  <mjw@redhat.com>
+
+       * cfi.c (execute_cfi): Add fallthrough comments.
+       * encoded-value.h (encoded_value_size): Add explicit return instead
+       of relying on fallthrough.
+       * dwfl_report_elf.c (__libdwfl_elf_address_range): Add fallthrough
+       comment.
+
+2016-10-11  Akihiko Odaki  <akihiko.odaki.4i@stu.hosei.ac.jp>
 
        * dwarf_getpubnames.c: Remove sys/param.h include, add system.h.
        * libdw_alloc.c: Likewise.
index 1fd668d79e3da0ab1be729b9ea15b096c16f4896..daa845f359d046527c118a2834188afa9aaadd4a 100644 (file)
@@ -138,6 +138,7 @@ execute_cfi (Dwarf_CFI *cache,
 
        case DW_CFA_advance_loc1:
          operand = *program++;
+         /* Fallthrough */
        case DW_CFA_advance_loc + 0 ... DW_CFA_advance_loc + CFI_PRIMARY_MAX:
        advance_loc:
          loc += operand * cie->code_alignment_factor;
@@ -300,6 +301,7 @@ execute_cfi (Dwarf_CFI *cache,
 
        case DW_CFA_restore_extended:
          get_uleb128 (operand, program, end);
+         /* Fallthrough */
        case DW_CFA_restore + 0 ... DW_CFA_restore + CFI_PRIMARY_MAX:
 
          if (unlikely (abi_cfi) && likely (opcode == DW_CFA_restore))
index 48d868fb6a785673a3a56b007684726d6ec02852..f0df4cec3e2753d961c6ed832f57ac46a97ad1db 100644 (file)
@@ -64,6 +64,7 @@ encoded_value_size (const Elf_Data *data, const unsigned char e_ident[],
            if (*end++ & 0x80u)
              return end - p;
        }
+      return 0;
 
     default:
       return 0;
index 1c6e401d1ccd3aaa1d289a51e45f5c4c5078de7e..73a5511a8012cb3f330d04d305a9b977250d04dd 100644 (file)
@@ -170,7 +170,7 @@ __libdwfl_elf_address_range (Elf *elf, GElf_Addr base, bool add_p_vaddr,
       /* An assigned base address is meaningless for these.  */
       base = 0;
       add_p_vaddr = true;
-
+      /* Fallthrough. */
     case ET_DYN:
     default:;
       size_t phnum;
index ee67cffcdadd257920c0b4b6d33b0aaf50cab0f8..b2909b65e56cb9008437310546bd8bef771b068a 100644 (file)
@@ -1,3 +1,11 @@
+2016-11-02  Mark Wielaard  <mjw@redhat.com>
+
+       * addr2line.c (handle_address): Add fallthrough comment.
+       * elfcompress.c (parse_opt): Adjust fallthrough comment.
+       * elflint.c (parse_opt): Add missing break after 'd' case.
+       (check_sections): Add fallthrough comments.
+       * objdump.c (parse_opt): Add explantion for fallthrough comment.
+
 2016-10-22  Kevin Cernekee  <cernekee@chromium.org>
 
        * unstrip.c: Fix "invalid string offset" error caused by using the
index 0ce854f6a911123263459491ac5b5c55ffda6d03..bea24aeacf170434863c498e79c0879faa14dbdf 100644 (file)
@@ -632,6 +632,7 @@ handle_address (const char *string, Dwfl *dwfl)
        case 1:
          addr = 0;
          j = i;
+         /* Fallthrough */
        case 2:
          if (string[j] != '\0')
            break;
index 7392cb763d77d04d93d188787568b7b4c22f48d2..82ab96559aeabbead449224861369f7157cb491c 100644 (file)
@@ -155,7 +155,8 @@ parse_opt (int key, char *arg __attribute__ ((unused)),
        argp_error (state,
                    N_("Only one input file allowed together with '-o'"));
       /* We only use this for checking the number of arguments, we don't
-        actually want to consume them, so fallthrough.  */
+        actually want to consume them.  */
+      /* Fallthrough */
     default:
       return ARGP_ERR_UNKNOWN;
     }
index 8b52ee2b1912a52875884ced6cc0c094fbc2c507..b304a3091ba80df77c5bc0ab8a6cb2deca6c0616 100644 (file)
@@ -210,6 +210,7 @@ parse_opt (int key, char *arg __attribute__ ((unused)),
 
     case 'd':
       is_debuginfo = true;
+      break;
 
     case ARGP_gnuld:
       gnuld = true;
@@ -3963,6 +3964,7 @@ section [%2zu] '%s': merge flag set but entry size is zero\n"),
            case SHT_NOBITS:
              if (is_debuginfo)
                break;
+             /* Fallthrough */
            default:
              ERROR (gettext ("\
 section [%2zu] '%s' has unexpected type %d for an executable section\n"),
@@ -4305,7 +4307,7 @@ section [%2d] '%s': unknown core file note type %" PRIu32
            if (nhdr.n_namesz == sizeof "Linux"
                && !memcmp (data->d_buf + name_offset, "Linux", sizeof "Linux"))
              break;
-
+           /* Fallthrough */
          default:
            if (shndx == 0)
              ERROR (gettext ("\
index 1afcd573b9e56ce681d3fa948572fcaf53dccfc5..f84513ca22b22cb7eff5a6d3e737556fffd6bf66 100644 (file)
@@ -234,7 +234,9 @@ parse_opt (int key, char *arg,
                     program_invocation_short_name);
          exit (EXIT_FAILURE);
        }
-
+      /* We only use this for checking the number of arguments, we don't
+        actually want to consume them.  */
+      /* Fallthrough */
     default:
       return ARGP_ERR_UNKNOWN;
     }
index 3d34778bda3981e6cf323c4df7bfc14192b28318..5a9d5372afba8b301e481a00257e59afd15f7169 100644 (file)
@@ -1,3 +1,8 @@
+2016-11-02  Mark Wielaard  <mjw@redhat.com>
+
+       * backtrace-data.c (thread_callback): Add explicit break after error.
+       * backtrace.c (callback_verify): Change PASSTHRU to FALLTHRU.
+
 2016-10-22  Kevin Cernekee  <cernekee@chromium.org>
 
        * Makefile.am (TESTS): Add run-unstrip-test4.sh.
index bc5ceba0dd2200d8fc9a8114c50b1e23f2de43d5..b7158dae8fb8062ad892dfadd525cbc1aab5fc59 100644 (file)
@@ -250,6 +250,7 @@ thread_callback (Dwfl_Thread *thread, void *thread_arg __attribute__ ((unused)))
       break;
     case -1:
       error (1, 0, "dwfl_thread_getframes: %s", dwfl_errmsg (-1));
+      break;
     default:
       abort ();
     }
index 2440ab34e7173388922f7821534d7322306ce05f..1ff6353c2d6f1fa595ad835ff71527d03e613df7 100644 (file)
@@ -123,7 +123,7 @@ callback_verify (pid_t tid, unsigned frameno, Dwarf_Addr pc,
          assert (symname2 == NULL || strcmp (symname2, "jmp") != 0);
          break;
        }
-      /* PASSTHRU */
+      /* FALLTHRU */
     case 4:
       assert (symname != NULL && strcmp (symname, "stdarg") == 0);
       break;