Miscellaneous build fixes for WebKit

Add a USE_SYSTEM_EGL define to allow compilation on Unix systems
without X11.

Feature detect __popcnt using Microsoft-specific _MSC_VER rather than
_M_X64/_M_IX86, which can be set by the Dinkumware stdlib on
non-Microsoft systems.

Apple's clang is too old to have -Wextra-semi-stmt

Ran generate_parser.sh using Cygwin64 bison 3.0.4, flex 2.6.4

Bug: 3439
Change-Id: Ie0d01a112a17f70ef60c120063a958b8f1a094f4
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1759135
Commit-Queue: James Darpinian <jdarpinian@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Kenneth Russell <kbr@chromium.org>
diff --git a/include/EGL/eglplatform.h b/include/EGL/eglplatform.h
index 543f8e5..bfd9bd6 100644
--- a/include/EGL/eglplatform.h
+++ b/include/EGL/eglplatform.h
@@ -110,7 +110,7 @@
 typedef struct egl_native_pixmap_t*     EGLNativePixmapType;
 typedef struct ANativeWindow*           EGLNativeWindowType;
 
-#elif defined(USE_OZONE)
+#elif defined(USE_OZONE) || defined(USE_SYSTEM_EGL)
 
 typedef intptr_t EGLNativeDisplayType;
 typedef intptr_t EGLNativePixmapType;
diff --git a/src/common/mathutil.h b/src/common/mathutil.h
index 003eba2..09b0dd0 100644
--- a/src/common/mathutil.h
+++ b/src/common/mathutil.h
@@ -979,7 +979,7 @@
 }
 
 // Count the 1 bits.
-#if defined(_M_IX86) || defined(_M_X64)
+#if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))
 #    define ANGLE_HAS_BITCOUNT_32
 inline int BitCount(uint32_t bits)
 {
diff --git a/src/compiler/preprocessor/Tokenizer.cpp b/src/compiler/preprocessor/Tokenizer.cpp
index c667e68..ce98877 100644
--- a/src/compiler/preprocessor/Tokenizer.cpp
+++ b/src/compiler/preprocessor/Tokenizer.cpp
@@ -699,7 +699,12 @@
 #endif
 #if defined(__clang__)
 // Flex uses `/*FALLTHROUGH*/` instead of dedicated statements.
-#    pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
+#    pragma clang diagnostic ignored "-Wimplicit-fallthrough"
+#    if defined(__APPLE__)
+// Older clang versions don't have -Wextra-semi-stmt, and detecting Apple clang versions is
+// difficult because they use different yet overlapping version numbers vs. regular clang.
+#        pragma clang diagnostic ignored "-Wunknown-warning-option"
+#    endif
 // Flex isn't semi-colon clean.
 #    pragma clang diagnostic ignored "-Wextra-semi-stmt"
 #    pragma clang diagnostic ignored "-Wunreachable-code"
diff --git a/src/compiler/preprocessor/Tokenizer.l b/src/compiler/preprocessor/Tokenizer.l
index d141b56..145406b 100644
--- a/src/compiler/preprocessor/Tokenizer.l
+++ b/src/compiler/preprocessor/Tokenizer.l
@@ -40,7 +40,12 @@
 #endif
 #if defined(__clang__)
 // Flex uses `/*FALLTHROUGH*/` instead of dedicated statements.
-#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
+#pragma clang diagnostic ignored "-Wimplicit-fallthrough"
+#if defined(__APPLE__)
+// Older clang versions don't have -Wextra-semi-stmt, and detecting Apple clang versions is
+// difficult because they use different yet overlapping version numbers vs. regular clang.
+#pragma clang diagnostic ignored "-Wunknown-warning-option"
+#endif
 // Flex isn't semi-colon clean.
 #pragma clang diagnostic ignored "-Wextra-semi-stmt"
 #pragma clang diagnostic ignored "-Wunreachable-code"
diff --git a/src/compiler/translator/glslang.l b/src/compiler/translator/glslang.l
index d2e5c24..a3e939f 100644
--- a/src/compiler/translator/glslang.l
+++ b/src/compiler/translator/glslang.l
@@ -39,7 +39,12 @@
 #pragma warning(disable: 4702)
 #endif
 #if defined(__clang__)
-#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
+#pragma clang diagnostic ignored "-Wimplicit-fallthrough"
+#if defined(__APPLE__)
+// Older clang versions don't have -Wextra-semi-stmt, and detecting Apple clang versions is
+// difficult because they use different yet overlapping version numbers vs. regular clang.
+#pragma clang diagnostic ignored "-Wunknown-warning-option"
+#endif
 // Flex isn't semi-colon clean.
 #pragma clang diagnostic ignored "-Wextra-semi-stmt"
 #pragma clang diagnostic ignored "-Wunreachable-code"
diff --git a/src/compiler/translator/glslang_lex.cpp b/src/compiler/translator/glslang_lex.cpp
index 30b5127..ba04ab9 100644
--- a/src/compiler/translator/glslang_lex.cpp
+++ b/src/compiler/translator/glslang_lex.cpp
@@ -24,7 +24,12 @@
 #pragma warning(disable: 4702)
 #endif
 #if defined(__clang__)
-#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
+#pragma clang diagnostic ignored "-Wimplicit-fallthrough"
+#if defined(__APPLE__)
+// Older clang versions don't have -Wextra-semi-stmt, and detecting Apple clang versions is
+// difficult because they use different yet overlapping version numbers vs. regular clang.
+#pragma clang diagnostic ignored "-Wunknown-warning-option"
+#endif
 // Flex isn't semi-colon clean.
 #pragma clang diagnostic ignored "-Wextra-semi-stmt"
 #pragma clang diagnostic ignored "-Wunreachable-code"
diff --git a/src/libANGLE/VertexArray.cpp b/src/libANGLE/VertexArray.cpp
index 2cb57ef..b162082 100644
--- a/src/libANGLE/VertexArray.cpp
+++ b/src/libANGLE/VertexArray.cpp
@@ -148,7 +148,7 @@
 {
     bool isBound           = context->isCurrentVertexArray(this);
     bool anyBufferDetached = false;
-    for (size_t bindingIndex = 0; bindingIndex < gl::MAX_VERTEX_ATTRIB_BINDINGS; ++bindingIndex)
+    for (uint32_t bindingIndex = 0; bindingIndex < gl::MAX_VERTEX_ATTRIB_BINDINGS; ++bindingIndex)
     {
         VertexBinding &binding = mState.mVertexBindings[bindingIndex];
         if (binding.getBuffer().id() == bufferName)
@@ -167,8 +167,11 @@
             }
             else
             {
+                static_assert(gl::MAX_VERTEX_ATTRIB_BINDINGS < 8 * sizeof(uint32_t),
+                              "Not enough bits in bindingIndex");
+                // The redundant uint32_t cast here is required to avoid a warning on MSVC.
                 ASSERT(binding.getBoundAttributesMask() ==
-                       AttributesMask(static_cast<size_t>(1) << bindingIndex));
+                       AttributesMask(static_cast<uint32_t>(1 << bindingIndex)));
                 setDirtyAttribBit(bindingIndex, DIRTY_ATTRIB_POINTER);
             }