libc: enable -Wimplicit-fallthrough

libc had some -Wimplicit-fallthrough warnings. They all seem to be
benign. We're trying to enable this flag globally, so we need to
annotate these breaks here.

Bug: 112564944
Test: Builds
Change-Id: I5afae694cc4cf26ad1a61e2c8ae91f00cda7c733
diff --git a/libc/Android.bp b/libc/Android.bp
index 1f95ce8..7356c64 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -41,6 +41,7 @@
     "-Wno-deprecated-declarations",
     "-Wno-gcc-compat",
     "-Wframe-larger-than=2048",
+    "-Wimplicit-fallthrough",
 
     // Try to catch typical 32-bit assumptions that break with 64-bit pointers.
     "-Werror=pointer-to-int-cast",
diff --git a/libc/bionic/fdsan.cpp b/libc/bionic/fdsan.cpp
index 43d8831..0f17184 100644
--- a/libc/bionic/fdsan.cpp
+++ b/libc/bionic/fdsan.cpp
@@ -189,6 +189,7 @@
     case ANDROID_FDSAN_ERROR_LEVEL_WARN_ONCE:
       atomic_compare_exchange_strong(&fd_table->error_level, &error_level,
                                      ANDROID_FDSAN_ERROR_LEVEL_DISABLED);
+      __BIONIC_FALLTHROUGH;
     case ANDROID_FDSAN_ERROR_LEVEL_WARN_ALWAYS:
       // DEBUGGER_SIGNAL
       raise(__SIGRTMIN + 3);
diff --git a/libc/private/bionic_macros.h b/libc/private/bionic_macros.h
index 979a704..0a36cdb 100644
--- a/libc/private/bionic_macros.h
+++ b/libc/private/bionic_macros.h
@@ -94,4 +94,12 @@
 
 #define arraysize(array) (sizeof(ArraySizeHelper(array)))
 
+// Used to inform clang's -Wimplicit-fallthrough that a fallthrough is intended. There's no way to
+// silence (or enable, apparently) -Wimplicit-fallthrough in C yet.
+#ifdef __cplusplus
+#define __BIONIC_FALLTHROUGH [[clang::fallthrough]]
+#else
+#define __BIONIC_FALLTHROUGH
+#endif
+
 #endif // _BIONIC_MACROS_H_
diff --git a/libc/stdio/printf_common.h b/libc/stdio/printf_common.h
index 9b7c329..ad4fe35 100644
--- a/libc/stdio/printf_common.h
+++ b/libc/stdio/printf_common.h
@@ -48,6 +48,8 @@
 #include <unistd.h>
 #include <wchar.h>
 
+#include <private/bionic_macros.h>
+
 #include "fvwrite.h"
 #include "gdtoa.h"
 #include "local.h"
@@ -472,7 +474,7 @@
         goto rflag;
       case 'C':
         flags |= LONGINT;
-        /*FALLTHROUGH*/
+        __BIONIC_FALLTHROUGH;
       case 'c':
         if (flags & LONGINT)
           ADDTYPE(T_WINT);
@@ -481,7 +483,7 @@
         break;
       case 'D':
         flags |= LONGINT;
-        /*FALLTHROUGH*/
+        __BIONIC_FALLTHROUGH;
       case 'd':
       case 'i':
         ADDSARG();
@@ -503,7 +505,7 @@
         __fortify_fatal("%%n not allowed on Android");
       case 'O':
         flags |= LONGINT;
-        /*FALLTHROUGH*/
+        __BIONIC_FALLTHROUGH;
       case 'o':
         ADDUARG();
         break;
@@ -512,13 +514,13 @@
         break;
       case 'S':
         flags |= LONGINT;
-        /*FALLTHROUGH*/
+        __BIONIC_FALLTHROUGH;
       case 's':
         ADDTYPE((flags & LONGINT) ? TP_WCHAR : TP_CHAR);
         break;
       case 'U':
         flags |= LONGINT;
-        /*FALLTHROUGH*/
+        __BIONIC_FALLTHROUGH;
       case 'u':
       case 'X':
       case 'x':
diff --git a/libc/stdio/vfprintf.cpp b/libc/stdio/vfprintf.cpp
index 7a67868..a14963e 100644
--- a/libc/stdio/vfprintf.cpp
+++ b/libc/stdio/vfprintf.cpp
@@ -206,7 +206,7 @@
         if (width >= 0) goto rflag;
         if (width == INT_MIN) goto overflow;
         width = -width;
-        /* FALLTHROUGH */
+        __BIONIC_FALLTHROUGH;
       case '-':
         flags |= LADJUST;
         goto rflag;
@@ -305,7 +305,7 @@
         goto rflag;
       case 'C':
         flags |= LONGINT;
-        /*FALLTHROUGH*/
+        __BIONIC_FALLTHROUGH;
       case 'c':
         if (flags & LONGINT) {
           mbstate_t mbs;
@@ -327,7 +327,7 @@
         break;
       case 'D':
         flags |= LONGINT;
-        /*FALLTHROUGH*/
+        __BIONIC_FALLTHROUGH;
       case 'd':
       case 'i':
         _umax = SARG();
@@ -453,7 +453,7 @@
         __fortify_fatal("%%n not allowed on Android");
       case 'O':
         flags |= LONGINT;
-        /*FALLTHROUGH*/
+        __BIONIC_FALLTHROUGH;
       case 'o':
         _umax = UARG();
         base = OCT;
@@ -473,7 +473,7 @@
         goto nosign;
       case 'S':
         flags |= LONGINT;
-        /*FALLTHROUGH*/
+        __BIONIC_FALLTHROUGH;
       case 's':
         if (flags & LONGINT) {
           wchar_t* wcp;
@@ -505,7 +505,7 @@
         break;
       case 'U':
         flags |= LONGINT;
-        /*FALLTHROUGH*/
+        __BIONIC_FALLTHROUGH;
       case 'u':
         _umax = UARG();
         base = DEC;
diff --git a/libc/stdio/vfscanf.cpp b/libc/stdio/vfscanf.cpp
index 0fcdbed..6fb49c9 100644
--- a/libc/stdio/vfscanf.cpp
+++ b/libc/stdio/vfscanf.cpp
@@ -43,6 +43,7 @@
 
 #include <private/bionic_ctype.h>
 #include <private/bionic_fortify.h>
+#include <private/bionic_macros.h>
 #include <private/bionic_mbstate.h>
 
 #define BUF 513 /* Maximum length of numeric string. */
@@ -189,7 +190,7 @@
        */
       case 'D': /* compat */
         flags |= LONG;
-        /* FALLTHROUGH */
+        __BIONIC_FALLTHROUGH;
       case 'd':
         c = CT_INT;
         base = 10;
@@ -202,7 +203,7 @@
 
       case 'O': /* compat */
         flags |= LONG;
-        /* FALLTHROUGH */
+        __BIONIC_FALLTHROUGH;
       case 'o':
         c = CT_INT;
         flags |= UNSIGNED;
diff --git a/libc/stdio/vfwprintf.cpp b/libc/stdio/vfwprintf.cpp
index ae0b62f..1c3b80d 100644
--- a/libc/stdio/vfwprintf.cpp
+++ b/libc/stdio/vfwprintf.cpp
@@ -195,7 +195,7 @@
         if (width >= 0) goto rflag;
         if (width == INT_MIN) goto overflow;
         width = -width;
-        /* FALLTHROUGH */
+        __BIONIC_FALLTHROUGH;
       case '-':
         flags |= LADJUST;
         goto rflag;
@@ -294,7 +294,7 @@
         goto rflag;
       case 'C':
         flags |= LONGINT;
-        /*FALLTHROUGH*/
+        __BIONIC_FALLTHROUGH;
       case 'c':
         if (flags & LONGINT)
           *(cp = buf) = (wchar_t)GETARG(wint_t);
@@ -305,7 +305,7 @@
         break;
       case 'D':
         flags |= LONGINT;
-        /*FALLTHROUGH*/
+        __BIONIC_FALLTHROUGH;
       case 'd':
       case 'i':
         _umax = SARG();
@@ -438,7 +438,7 @@
         __fortify_fatal("%%n not allowed on Android");
       case 'O':
         flags |= LONGINT;
-        /*FALLTHROUGH*/
+        __BIONIC_FALLTHROUGH;
       case 'o':
         _umax = UARG();
         base = OCT;
@@ -458,7 +458,7 @@
         goto nosign;
       case 'S':
         flags |= LONGINT;
-        /*FALLTHROUGH*/
+        __BIONIC_FALLTHROUGH;
       case 's':
         if (flags & LONGINT) {
           if ((cp = GETARG(wchar_t*)) == nullptr) cp = const_cast<wchar_t*>(L"(null)");
@@ -486,7 +486,7 @@
         break;
       case 'U':
         flags |= LONGINT;
-        /*FALLTHROUGH*/
+        __BIONIC_FALLTHROUGH;
       case 'u':
         _umax = UARG();
         base = DEC;