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) {
" %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"
"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());
+}
}