spirv-val: Use more specific term 'switch header' in error message (#5048)

* spirv-val: Add tests for OpSwitch directly breaking/continuing outer loop

These are not valid, tests verify the validator catches the issue.
This commit is contained in:
Caio Oliveira 2023-01-09 15:39:02 -08:00 коммит произвёл GitHub
Родитель d87f61605b
Коммит f62e121b0d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 101 добавлений и 1 удалений

Просмотреть файл

@ -560,7 +560,7 @@ spv_result_t StructuredSwitchChecks(ValidationState_t& _, Function* function,
target_block->structurally_reachable() &&
!header->structurally_dominates(*target_block)) {
return _.diag(SPV_ERROR_INVALID_CFG, header->label())
<< "Selection header " << _.getIdName(header->id())
<< "Switch header " << _.getIdName(header->id())
<< " does not structurally dominate its case construct "
<< _.getIdName(target);
}

Просмотреть файл

@ -2064,6 +2064,106 @@ OpFunctionEnd
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
}
TEST_F(ValidateCFG, OpSwitchTargetCannotBeOuterLoopMergeBlock) {
std::string text = R"(
OpCapability Shader
OpCapability Linkage
OpMemoryModel Logical GLSL450
%1 = OpTypeVoid
%2 = OpTypeFunction %1
%3 = OpTypeBool
%4 = OpUndef %3
%5 = OpTypeInt 32 0
%6 = OpConstant %5 0
%7 = OpFunction %1 None %2
%8 = OpLabel
OpBranch %9
%9 = OpLabel
OpLoopMerge %10 %11 None
OpBranch %12
%12 = OpLabel
OpSelectionMerge %13 None
OpSwitch %6 %13 0 %10 1 %14
%14 = OpLabel
OpBranch %13
%13 = OpLabel
OpBranch %11
%11 = OpLabel
OpBranch %9
%10 = OpLabel
OpReturn
OpFunctionEnd
)";
CompileSuccessfully(text);
ASSERT_EQ(SPV_ERROR_INVALID_CFG, ValidateInstructions());
EXPECT_THAT(
getDiagnosticString(),
HasSubstr(
"Switch header '12[%12]' does not structurally dominate its case construct '10[%10]'\n"
" %12 = OpLabel"));
}
TEST_F(ValidateCFG, OpSwitchTargetCannotBeOuterLoopContinueBlock) {
std::string text = R"(
OpCapability Shader
OpCapability Linkage
OpMemoryModel Logical GLSL450
%1 = OpTypeVoid
%2 = OpTypeFunction %1
%3 = OpTypeBool
%4 = OpUndef %3
%5 = OpTypeInt 32 0
%6 = OpConstant %5 0
%7 = OpFunction %1 None %2
%8 = OpLabel
OpBranch %9
%9 = OpLabel
OpLoopMerge %10 %11 None
OpBranch %12
%12 = OpLabel
OpSelectionMerge %13 None
OpSwitch %6 %13 0 %11 1 %14
%14 = OpLabel
OpBranch %13
%13 = OpLabel
OpBranch %11
%11 = OpLabel
OpBranch %9
%10 = OpLabel
OpReturn
OpFunctionEnd
)";
CompileSuccessfully(text);
ASSERT_EQ(SPV_ERROR_INVALID_CFG, ValidateInstructions());
EXPECT_THAT(
getDiagnosticString(),
HasSubstr(
"Switch header '12[%12]' does not structurally dominate its case construct '11[%11]'\n"
" %12 = OpLabel"));
}
TEST_F(ValidateCFG, WrongOperandList) {
std::string text = R"(
OpCapability Shader