mirror of
https://github.com/KhronosGroup/SPIRV-Tools
synced 2024-12-25 17:21:06 +00:00
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:
parent
40a68547dc
commit
f62d7978fc
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user