commit | bfe76c097f8b028441e807c3498232523675c0c8 | [log] [tgz] |
---|---|---|
author | John Bauman <jbauman@google.com> | Mon Oct 24 16:39:03 2022 +0000 |
committer | John Bauman <jbauman@google.com> | Tue Oct 25 21:52:31 2022 +0000 |
tree | 561e524cfc25aff496ff2c3186bf5c181eecfd95 | |
parent | 888bc6428ccb1eda957515c05b178ebe80a387ab [diff] |
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) {