Forbid Generic variables.
authorDejan Mircevski <deki@google.com>
Fri, 29 Jan 2016 21:49:40 +0000 (16:49 -0500)
committerDejan Mircevski <deki@google.com>
Fri, 29 Jan 2016 22:08:41 +0000 (17:08 -0500)
source/validate_instruction.cpp
test/Validate.Capability.cpp
test/Validate.Storage.cpp

index 7c1c1c7..f89e64b 100644 (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) {
index 9473229..f32bd56 100644 (file)
@@ -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"
index 5607acd..9d4a078 100644 (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());
+}
 }