Skip to content

Commit

Permalink
Do not check structurally unreachable continue target predecessors
Browse files Browse the repository at this point in the history
Fixes KhronosGroup#5784

* Rules only apply to structurally reachable blocks
  • Loading branch information
alan-baker committed Sep 11, 2024
1 parent d160e17 commit aee50fd
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
3 changes: 3 additions & 0 deletions source/val/validate_cfg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,9 @@ spv_result_t StructuredControlFlowChecks(
const auto* continue_target = next_inst.block();
if (header->id() != continue_id) {
for (auto pred : *continue_target->predecessors()) {
if (!pred->structurally_reachable()) {
continue;
}
// Ignore back-edges from within the continue construct.
bool is_back_edge = false;
for (auto back_edge : back_edges) {
Expand Down
37 changes: 37 additions & 0 deletions test/val/val_cfg_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5118,6 +5118,43 @@ OpFunctionEnd
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
}

TEST_F(ValidateCFG, StructurallyUnreachableContinuePredecessor) {
const std::string text = R"(
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main"
OpExecutionMode %main OriginUpperLeft
OpSource ESSL 310
OpName %main "main"
%void = OpTypeVoid
%3 = OpTypeFunction %void
%int = OpTypeInt 32 1
%int_1 = OpConstant %int 1
%int_n7 = OpConstant %int -7
%bool = OpTypeBool
%main = OpFunction %void None %3
%8 = OpLabel
OpBranch %9
%9 = OpLabel
%10 = OpPhi %int %int_1 %8 %int_n7 %15
%12 = OpSGreaterThan %bool %10 %int_n7
OpLoopMerge %13 %15 None
OpBranchConditional %12 %14 %13
%14 = OpLabel
OpBranch %15
%15 = OpLabel
OpBranch %9
%17 = OpLabel
OpBranch %15
%13 = OpLabel
OpReturn
OpFunctionEnd
)";

CompileSuccessfully(text);
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
}

} // namespace
} // namespace val
} // namespace spvtools

0 comments on commit aee50fd

Please sign in to comment.