Prepare for -Wimplicit-fallthrough in ANGLE.

Disable the warning for flex-generated output, which contains
lots of intentional fallthrough.

Fixes a bug where GL_SAMPLE_ALPHA_TO_ONE_EXT would fall through
to GL_COVERAGE_MODULATION_CHROMIUM and hence behave like that.

Fixes a bug in the D3D9 state management where invalidating
DIRTY_BIT_POLYGON_OFFSET would also invalidate the stencil bits.

One somewhat common incorrect pattern in ANGLE is nested switch
statements that look like so:

  switch (a) {
    case a1:
      switch (b) {
        case b1:
          ...
          break;
      }
    case a2:
      ...
  }

The assumption here seems to be that the breakk exits the outer
case (here a1), while it in fact only exits the inner switch,
so that we fall through to a2.  In most places, I fixed this
by adding an explicit `break` after the inner switch.

This fixes a bug wher GL_PATH_JOIN_STYLE_CHROMIUM would fall through to
GL_PATH_MITER_LIMIT_CHROMIUM in validation (but since the join style
enum is always > 0, this happened to not have an effect in practice).

This also fixes 87 bugs in GetLoadFunctionsMap() where invalid
values would previously return an unrelated function map instead
of the empty load function map.

Bug: chromium:810767
Change-Id: Ib51388c73fbfc229160e2c10f8fb9364cc7c996c
Reviewed-on: https://chromium-review.googlesource.com/911529
Commit-Queue: Nico Weber <thakis@chromium.org>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
diff --git a/src/compiler/preprocessor/Tokenizer.cpp b/src/compiler/preprocessor/Tokenizer.cpp
index d8a9b9a..8eacea8 100644
--- a/src/compiler/preprocessor/Tokenizer.cpp
+++ b/src/compiler/preprocessor/Tokenizer.cpp
@@ -911,6 +911,10 @@
 #elif defined(_MSC_VER)
 #pragma warning(disable: 4244)
 #endif
+#if defined(__clang__)
+// Flex uses `/*FALLTHROUGH*/` instead of dedicated statements.
+#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
+#endif
 
 // Workaround for flex using the register keyword, deprecated in C++11.
 #ifdef __cplusplus
diff --git a/src/compiler/preprocessor/Tokenizer.l b/src/compiler/preprocessor/Tokenizer.l
index 096812d..5580138 100644
--- a/src/compiler/preprocessor/Tokenizer.l
+++ b/src/compiler/preprocessor/Tokenizer.l
@@ -38,6 +38,10 @@
 #elif defined(_MSC_VER)
 #pragma warning(disable: 4244)
 #endif
+#if defined(__clang__)
+// Flex uses `/*FALLTHROUGH*/` instead of dedicated statements.
+#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
+#endif
 
 // Workaround for flex using the register keyword, deprecated in C++11.
 #ifdef __cplusplus
diff --git a/src/compiler/translator/ASTMetadataHLSL.cpp b/src/compiler/translator/ASTMetadataHLSL.cpp
index 055408d..232a958 100644
--- a/src/compiler/translator/ASTMetadataHLSL.cpp
+++ b/src/compiler/translator/ASTMetadataHLSL.cpp
@@ -105,6 +105,7 @@
                 case EOpDFdy:
                 case EOpFwidth:
                     onGradient();
+                    break;
                 default:
                     break;
             }
diff --git a/src/compiler/translator/EmulatePrecision.cpp b/src/compiler/translator/EmulatePrecision.cpp
index d3acfbd..0219d7a 100644
--- a/src/compiler/translator/EmulatePrecision.cpp
+++ b/src/compiler/translator/EmulatePrecision.cpp
@@ -6,6 +6,7 @@
 
 #include "compiler/translator/EmulatePrecision.h"
 
+#include "common/angle_fallthrough.h"
 #include "compiler/translator/FunctionLookup.h"
 
 #include <memory>
@@ -639,6 +640,7 @@
             {
                 break;
             }
+            ANGLE_FALLTHROUGH;
         default:
             TIntermNode *parent = getParentNode();
             if (canRoundFloat(node->getType()) && ParentUsesResult(parent, node) &&
diff --git a/src/compiler/translator/IntermNode.cpp b/src/compiler/translator/IntermNode.cpp
index c40a093..dca3bc7 100644
--- a/src/compiler/translator/IntermNode.cpp
+++ b/src/compiler/translator/IntermNode.cpp
@@ -1588,6 +1588,7 @@
             {
                 return true;
             }
+            break;
         }
         default:
             break;
diff --git a/src/compiler/translator/ParseContext.cpp b/src/compiler/translator/ParseContext.cpp
index d912576..59de39d 100644
--- a/src/compiler/translator/ParseContext.cpp
+++ b/src/compiler/translator/ParseContext.cpp
@@ -4918,6 +4918,7 @@
                 unaryOpError(loc, GetOperatorString(op), child->getCompleteString());
                 return nullptr;
             }
+            break;
         // Operators for built-ins are already type checked against their prototype.
         default:
             break;
diff --git a/src/compiler/translator/glslang.l b/src/compiler/translator/glslang.l
index 549787a..da52369 100644
--- a/src/compiler/translator/glslang.l
+++ b/src/compiler/translator/glslang.l
@@ -26,9 +26,9 @@
 
 // Ignore errors in auto-generated code.
 #if defined(__GNUC__)
+#pragma GCC diagnostic ignored "-Wswitch-enum"
 #pragma GCC diagnostic ignored "-Wunused-function"
 #pragma GCC diagnostic ignored "-Wunused-variable"
-#pragma GCC diagnostic ignored "-Wswitch-enum"
 #elif defined(_MSC_VER)
 #pragma warning(disable: 4005)
 #pragma warning(disable: 4065)
@@ -38,6 +38,9 @@
 #pragma warning(disable: 4701)
 #pragma warning(disable: 4702)
 #endif
+#if defined(__clang__)
+#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
+#endif
 }
 
 %{
diff --git a/src/compiler/translator/glslang_lex.cpp b/src/compiler/translator/glslang_lex.cpp
index 2bf623f..4e60164 100644
--- a/src/compiler/translator/glslang_lex.cpp
+++ b/src/compiler/translator/glslang_lex.cpp
@@ -11,9 +11,9 @@
 
 // Ignore errors in auto-generated code.
 #if defined(__GNUC__)
+#pragma GCC diagnostic ignored "-Wswitch-enum"
 #pragma GCC diagnostic ignored "-Wunused-function"
 #pragma GCC diagnostic ignored "-Wunused-variable"
-#pragma GCC diagnostic ignored "-Wswitch-enum"
 #elif defined(_MSC_VER)
 #pragma warning(disable: 4005)
 #pragma warning(disable: 4065)
@@ -23,6 +23,9 @@
 #pragma warning(disable: 4701)
 #pragma warning(disable: 4702)
 #endif
+#if defined(__clang__)
+#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
+#endif