mirror of
https://github.com/KhronosGroup/SPIRV-Tools
synced 2024-12-25 17:21:06 +00:00
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:
parent
4e266f775a
commit
bc09f53c96
@ -336,7 +336,9 @@ spv_result_t FindCaseFallThrough(
|
||||
}
|
||||
|
||||
if (*case_fall_through == 0u) {
|
||||
*case_fall_through = block->id();
|
||||
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())
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user