Forbid Generic variables.

This commit is contained in:
Dejan Mircevski 2016-01-29 16:49:40 -05:00
parent 7dbfdda609
commit 5f99fc33cd
3 changed files with 33 additions and 3 deletions

View File

@ -490,6 +490,9 @@ spv_result_t InstructionPass(ValidationState_t& _,
case SpvOpVariable: {
const SpvStorageClass storage_class =
static_cast<SpvStorageClass>(inst->words[inst->operands[2].offset]);
if (storage_class == SpvStorageClassGeneric)
return _.diag(SPV_ERROR_INVALID_BINARY)
<< "OpVariable storage class cannot be Generic";
spvCheckReturn(StorageClassCapabilityCheck(_, storage_class));
if (_.getLayoutSection() == kLayoutFunctionDefinitions) {

View File

@ -381,9 +381,6 @@ make_pair(" %intt = OpTypeInt 32 0\n"
make_pair(" %intt = OpTypeInt 32 0\n"
" %ptrt = OpTypePointer Private %intt\n"
" %var = OpVariable %ptrt Private\n", ShaderDependencies()),
make_pair(" %intt = OpTypeInt 32 0\n"
" %ptrt = OpTypePointer Generic %intt\n"
" %var = OpVariable %ptrt Generic\n", KernelDependencies()),
make_pair(" %intt = OpTypeInt 32 0\n"
" %ptrt = OpTypePointer PushConstant %intt\n"
" %var = OpVariable %ptrt PushConstant\n", ShaderDependencies()),

View File

@ -141,4 +141,34 @@ INSTANTIATE_TEST_CASE_P(MatrixOp, ValidateStorage,
"AtomicCounter",
"Image"));
// clang-format on
TEST_F(ValidateStorage, GenericVariableOutsideFunction) {
const auto str = R"(
OpCapability Kernel
OpMemoryModel Logical OpenCL
%intt = OpTypeInt 32 1
%ptrt = OpTypePointer Function %intt
%var = OpVariable %ptrt Generic
)";
CompileSuccessfully(str);
ASSERT_EQ(SPV_ERROR_INVALID_BINARY, ValidateInstructions());
}
TEST_F(ValidateStorage, GenericVariableInsideFunction) {
const auto str = R"(
OpCapability Shader
OpMemoryModel Logical GLSL450
%intt = OpTypeInt 32 1
%voidt = OpTypeVoid
%vfunct = OpTypeFunction %voidt
%ptrt = OpTypePointer Function %intt
%func = OpFunction %voidt None %vfunct
%funcl = OpLabel
%var = OpVariable %ptrt Generic
OpReturn
OpFunctionEnd
)";
CompileSuccessfully(str);
ASSERT_EQ(SPV_ERROR_INVALID_BINARY, ValidateInstructions());
}
}