restrict opcodes targeting OpDecorationGroup

This commit is contained in:
Jesus Carabano 2017-10-21 19:39:32 +03:00 committed by David Neto
parent 97990dc907
commit 13e6598947
2 changed files with 36 additions and 0 deletions

View File

@ -180,6 +180,27 @@ bool idUsage::isValid<SpvOpMemberDecorate>(const spv_instruction_t* inst,
return true;
}
template <>
bool idUsage::isValid<SpvOpDecorationGroup>(const spv_instruction_t* inst,
const spv_opcode_desc) {
auto decorationGroupIndex = 1;
auto decorationGroup = module_.FindDef(inst->words[decorationGroupIndex]);
for (auto pair : decorationGroup->uses()) {
auto use = pair.first;
if (use->opcode() != SpvOpDecorate &&
use->opcode() != SpvOpGroupDecorate &&
use->opcode() != SpvOpGroupMemberDecorate &&
use->opcode() != SpvOpName ) {
DIAG(decorationGroupIndex) << "Result id of OpDecorationGroup can only "
<< "be targeted by OpName, OpGroupDecorate, "
<< "OpDecorate, and OpGroupMemberDecorate";
return false;
}
}
return true;
}
template <>
bool idUsage::isValid<SpvOpGroupDecorate>(const spv_instruction_t* inst,
const spv_opcode_desc) {
@ -2362,6 +2383,7 @@ bool idUsage::isValid(const spv_instruction_t* inst) {
CASE(OpLine)
CASE(OpDecorate)
CASE(OpMemberDecorate)
CASE(OpDecorationGroup)
CASE(OpGroupDecorate)
CASE(OpGroupMemberDecorate)
TODO(OpExtInst)

View File

@ -218,6 +218,20 @@ TEST_F(ValidateIdWithMessage, OpGroupDecorateGood) {
CompileSuccessfully(spirv.c_str());
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
}
TEST_F(ValidateIdWithMessage, OpDecorationGroupBad) {
string spirv = kGLSL450MemoryModel + R"(
%1 = OpDecorationGroup
OpDecorate %1 Uniform
OpDecorate %1 GLSLShared
OpMemberDecorate %1 0 Constant
)";
CompileSuccessfully(spirv.c_str());
EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
EXPECT_THAT(getDiagnosticString(),
HasSubstr("Result id of OpDecorationGroup can only "
"be targeted by OpName, OpGroupDecorate, "
"OpDecorate, and OpGroupMemberDecorate"));
}
TEST_F(ValidateIdWithMessage, OpGroupDecorateDecorationGroupBad) {
string spirv = R"(
OpCapability Shader