Skip to content

Commit 380275e

Browse files
authored
Do not check structurally unreachable continue target predecessors (#5800)
Fixes #5784 * Rules only apply to structurally reachable blocks
1 parent d160e17 commit 380275e

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

source/val/validate_cfg.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,9 @@ spv_result_t StructuredControlFlowChecks(
839839
const auto* continue_target = next_inst.block();
840840
if (header->id() != continue_id) {
841841
for (auto pred : *continue_target->predecessors()) {
842+
if (!pred->structurally_reachable()) {
843+
continue;
844+
}
842845
// Ignore back-edges from within the continue construct.
843846
bool is_back_edge = false;
844847
for (auto back_edge : back_edges) {

test/val/val_cfg_test.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5118,6 +5118,43 @@ OpFunctionEnd
51185118
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
51195119
}
51205120

5121+
TEST_F(ValidateCFG, StructurallyUnreachableContinuePredecessor) {
5122+
const std::string text = R"(
5123+
OpCapability Shader
5124+
OpMemoryModel Logical GLSL450
5125+
OpEntryPoint Fragment %main "main"
5126+
OpExecutionMode %main OriginUpperLeft
5127+
OpSource ESSL 310
5128+
OpName %main "main"
5129+
%void = OpTypeVoid
5130+
%3 = OpTypeFunction %void
5131+
%int = OpTypeInt 32 1
5132+
%int_1 = OpConstant %int 1
5133+
%int_n7 = OpConstant %int -7
5134+
%bool = OpTypeBool
5135+
%main = OpFunction %void None %3
5136+
%8 = OpLabel
5137+
OpBranch %9
5138+
%9 = OpLabel
5139+
%10 = OpPhi %int %int_1 %8 %int_n7 %15
5140+
%12 = OpSGreaterThan %bool %10 %int_n7
5141+
OpLoopMerge %13 %15 None
5142+
OpBranchConditional %12 %14 %13
5143+
%14 = OpLabel
5144+
OpBranch %15
5145+
%15 = OpLabel
5146+
OpBranch %9
5147+
%17 = OpLabel
5148+
OpBranch %15
5149+
%13 = OpLabel
5150+
OpReturn
5151+
OpFunctionEnd
5152+
)";
5153+
5154+
CompileSuccessfully(text);
5155+
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
5156+
}
5157+
51215158
} // namespace
51225159
} // namespace val
51235160
} // namespace spvtools

0 commit comments

Comments
 (0)