summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesus Carabano <jcaraban@abo.fi>2017-10-21 19:39:32 +0300
committerDavid Neto <dneto@google.com>2017-10-24 11:39:08 -0400
commit13e6598947845413b14a4bbe3469f9906f82cc63 (patch)
tree8ec5844b4bd2c0b65451bf220855b03eb962c37c
parent97990dc90739adfe0856b1fa1738818b90316cb0 (diff)
downloadSPIRV-Tools-13e6598947845413b14a4bbe3469f9906f82cc63.tar.gz
SPIRV-Tools-13e6598947845413b14a4bbe3469f9906f82cc63.tar.bz2
SPIRV-Tools-13e6598947845413b14a4bbe3469f9906f82cc63.zip
restrict opcodes targeting OpDecorationGroup
-rw-r--r--source/validate_id.cpp22
-rw-r--r--test/val/val_id_test.cpp14
2 files changed, 36 insertions, 0 deletions
diff --git a/source/validate_id.cpp b/source/validate_id.cpp
index a3ed893e..987b67b0 100644
--- a/source/validate_id.cpp
+++ b/source/validate_id.cpp
@@ -181,6 +181,27 @@ bool idUsage::isValid<SpvOpMemberDecorate>(const spv_instruction_t* inst,
}
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) {
auto decorationGroupIndex = 1;
@@ -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)
diff --git a/test/val/val_id_test.cpp b/test/val/val_id_test.cpp
index fd0c8a60..da997a31 100644
--- a/test/val/val_id_test.cpp
+++ b/test/val/val_id_test.cpp
@@ -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