Fix calculation of case fall through (#1965)

Fixes #1959

* Code erroneously concluded that the target's fall through was itself
* Added a test
This commit is contained in:
alan-baker 2018-10-10 13:25:48 -04:00 committed by GitHub
parent 4e266f775a
commit bc09f53c96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 1 deletions

View File

@ -336,7 +336,9 @@ spv_result_t FindCaseFallThrough(
}
if (*case_fall_through == 0u) {
if (target_block != block) {
*case_fall_through = block->id();
}
} else if (*case_fall_through != block->id()) {
// Case construct has at most one branch to another case construct.
return _.diag(SPV_ERROR_INVALID_CFG, target_block->label())

View File

@ -1777,6 +1777,40 @@ OpFunctionEnd
" OpSwitch %uint_0 %10 0 %11 1 %12 2 %13"));
}
TEST_F(ValidateCFG, GoodUnreachableSwitch) {
const std::string text = R"(
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %2 "main"
OpExecutionMode %2 OriginUpperLeft
%3 = OpTypeVoid
%4 = OpTypeFunction %3
%5 = OpTypeBool
%6 = OpConstantTrue %5
%7 = OpTypeInt 32 1
%9 = OpConstant %7 0
%2 = OpFunction %3 None %4
%10 = OpLabel
OpSelectionMerge %11 None
OpBranchConditional %6 %12 %13
%12 = OpLabel
OpReturn
%13 = OpLabel
OpReturn
%11 = OpLabel
OpSelectionMerge %14 None
OpSwitch %9 %14 0 %15
%15 = OpLabel
OpBranch %14
%14 = OpLabel
OpReturn
OpFunctionEnd
)";
CompileSuccessfully(text);
EXPECT_THAT(SPV_SUCCESS, ValidateInstructions());
}
TEST_F(ValidateCFG, InvalidCaseExit) {
const std::string text = R"(
OpCapability Shader