Add validation check for arrays of void type. (#1880)

In the definition of an array
(https://www.khronos.org/registry/spir-v/specs/1.2/SPIRV.html#Array),
it specfically mentions that array elements have non-void type.  I've
added a check for that in this PR.

http://crbug.com/879016
This commit is contained in:
Steven Perron 2018-09-10 09:21:32 -04:00 committed by GitHub
parent 40a68547dc
commit f62d7978fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 0 deletions

View File

@ -99,6 +99,13 @@ spv_result_t ValidateTypeArray(ValidationState_t& _, const Instruction* inst) {
<< "OpTypeArray Element Type <id> '" << _.getIdName(element_type_id)
<< "' is not a type.";
}
if (element_type->opcode() == SpvOpTypeVoid) {
return _.diag(SPV_ERROR_INVALID_ID, inst)
<< "OpTypeArray Element Type <id> '" << _.getIdName(element_type_id)
<< "' is a void type.";
}
const auto length_index = 2;
const auto length_id = inst->GetOperandAs<uint32_t>(length_index);
const auto length = _.FindDef(length_id);
@ -147,6 +154,13 @@ spv_result_t ValidateTypeRuntimeArray(ValidationState_t& _,
<< "OpTypeRuntimeArray Element Type <id> '"
<< _.getIdName(element_id) << "' is not a type.";
}
if (element_type->opcode() == SpvOpTypeVoid) {
return _.diag(SPV_ERROR_INVALID_ID, inst)
<< "OpTypeRuntimeArray Element Type <id> '"
<< _.getIdName(element_id) << "' is a void type.";
}
return SPV_SUCCESS;
}

View File

@ -637,6 +637,32 @@ TEST_F(ValidateData, vulkan_disallow_free_fp_rounding_mode) {
}
}
TEST_F(ValidateData, void_array) {
std::string str = header + R"(
%void = OpTypeVoid
%int = OpTypeInt 32 0
%int_5 = OpConstant %int 5
%array = OpTypeArray %void %int_5
)";
CompileSuccessfully(str.c_str());
ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
EXPECT_THAT(getDiagnosticString(),
HasSubstr("OpTypeArray Element Type <id> '1' is a void type."));
}
TEST_F(ValidateData, void_runtime_array) {
std::string str = header + R"(
%void = OpTypeVoid
%array = OpTypeRuntimeArray %void
)";
CompileSuccessfully(str.c_str());
ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
EXPECT_THAT(
getDiagnosticString(),
HasSubstr("OpTypeRuntimeArray Element Type <id> '1' is a void type."));
}
} // namespace
} // namespace val
} // namespace spvtools