libdex: Enable -Wimplicit-fallthrough

This adds fallthrough annotations to this code, to make it compile
cleanly when given -Wimplicit-fallthrough. The intent is to enable this
warning for the Android platform after these uses are cleaned up.

This code runs on the host, rather than the device, so we can't rely on
the FALLTHROUGH_INTENDED macro provided by android-base here. Since
said macro is pretty trivial, duplicating it doesn't seem all that bad.

Bug: 112564944
Test: Builds
Change-Id: I9f49f15d5dd178a2d78a8092d5863a42369968c0
diff --git a/libdex/Android.bp b/libdex/Android.bp
index 63600c6..2a443b9 100644
--- a/libdex/Android.bp
+++ b/libdex/Android.bp
@@ -46,6 +46,7 @@
     cflags: [
         "-Wall",
         "-Werror",
+        "-Wimplicit-fallthrough",
     ],
     target: {
         android: {
diff --git a/libdex/DexFile.h b/libdex/DexFile.h
index b3dcca1..7fc7d05 100644
--- a/libdex/DexFile.h
+++ b/libdex/DexFile.h
@@ -33,6 +33,12 @@
 #ifndef LIBDEX_DEXFILE_H_
 #define LIBDEX_DEXFILE_H_
 
+/*
+ * Annotation to tell clang that we intend to fall through from one case to
+ * another in a switch. Sourced from android-base/macros.h.
+ */
+#define FALLTHROUGH_INTENDED [[clang::fallthrough]]
+
 #ifndef LOG_TAG
 # define LOG_TAG "libdex"
 #endif
diff --git a/libdex/DexSwapVerify.cpp b/libdex/DexSwapVerify.cpp
index 8836ab2..5d55fe4 100644
--- a/libdex/DexSwapVerify.cpp
+++ b/libdex/DexSwapVerify.cpp
@@ -617,7 +617,7 @@
                 ALOGE("Invalid use of void");
                 return false;
             }
-            // Fall through.
+            FALLTHROUGH_INTENDED;
         }
         case 'B':
         case 'C':
diff --git a/libdex/InstrUtils.cpp b/libdex/InstrUtils.cpp
index 9039f59..56f5dd8 100644
--- a/libdex/InstrUtils.cpp
+++ b/libdex/InstrUtils.cpp
@@ -619,10 +619,11 @@
                  * instruction, but it's labeled G in the spec.
                  */
                 pDec->arg[4] = INST_A(inst);
+                FALLTHROUGH_INTENDED;
             }
-            case 4: pDec->arg[3] = (regList >> 12) & 0x0f;
-            case 3: pDec->arg[2] = (regList >> 8) & 0x0f;
-            case 2: pDec->arg[1] = (regList >> 4) & 0x0f;
+            case 4: pDec->arg[3] = (regList >> 12) & 0x0f; FALLTHROUGH_INTENDED;
+            case 3: pDec->arg[2] = (regList >> 8) & 0x0f; FALLTHROUGH_INTENDED;
+            case 2: pDec->arg[1] = (regList >> 4) & 0x0f; FALLTHROUGH_INTENDED;
             case 1: pDec->vC = pDec->arg[0] = regList & 0x0f; break;
             case 0: break; // Valid, but no need to do anything.
             default: