Don't cast (1 << 31) to VkShaderStageFlagBits

That's undefined behavior that UBSAN will detect.
Upstream bug report:
https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/4689

Bug: 112606
Change-Id: I7acff90492f97fa007c7cab92a4b9f9e033c9215
Reviewed-on: https://fuchsia-review.googlesource.com/c/third_party/Vulkan-ValidationLayers/+/746005
Reviewed-by: Craig Stout <cstout@google.com>
diff --git a/layers/pipeline_state.cpp b/layers/pipeline_state.cpp
index 7a012e1..7f792c0 100644
--- a/layers/pipeline_state.cpp
+++ b/layers/pipeline_state.cpp
@@ -81,6 +81,12 @@
 
     for (uint32_t stage_idx = 0; stage_idx < 32; ++stage_idx) {
         bool stage_found = false;
+        // Only cast to a VkShaderStageFlagBits if the result could fit in that enum; otherwise
+        // that's undefined behavior. See
+        // https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/4689
+        if (!((1 << stage_idx) & VK_SHADER_STAGE_FLAG_BITS_MAX_ENUM)) {
+            continue;
+        }
         const auto stage = static_cast<VkShaderStageFlagBits>(1 << stage_idx);
         for (const auto &shader_stage : stages) {
             if (shader_stage.stage == stage) {