From 5f99fc33cd96d1425ebadd34529735f7ac5f2d94 Mon Sep 17 00:00:00 2001 From: Dejan Mircevski Date: Fri, 29 Jan 2016 16:49:40 -0500 Subject: [PATCH] Forbid Generic variables. --- source/validate_instruction.cpp | 3 +++ test/Validate.Capability.cpp | 3 --- test/Validate.Storage.cpp | 30 ++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/source/validate_instruction.cpp b/source/validate_instruction.cpp index 7c1c1c7..f89e64b 100644 --- a/source/validate_instruction.cpp +++ b/source/validate_instruction.cpp @@ -490,6 +490,9 @@ spv_result_t InstructionPass(ValidationState_t& _, case SpvOpVariable: { const SpvStorageClass storage_class = static_cast(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) { diff --git a/test/Validate.Capability.cpp b/test/Validate.Capability.cpp index 9473229..f32bd56 100644 --- a/test/Validate.Capability.cpp +++ b/test/Validate.Capability.cpp @@ -382,9 +382,6 @@ 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()), make_pair(" %intt = OpTypeInt 32 0\n" diff --git a/test/Validate.Storage.cpp b/test/Validate.Storage.cpp index 5607acd..9d4a078 100644 --- a/test/Validate.Storage.cpp +++ b/test/Validate.Storage.cpp @@ -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()); +} } -- 2.7.4