diff --git a/mlir/lib/Dialect/SPIRV/SPIRVOps.cpp b/mlir/lib/Dialect/SPIRV/SPIRVOps.cpp --- a/mlir/lib/Dialect/SPIRV/SPIRVOps.cpp +++ b/mlir/lib/Dialect/SPIRV/SPIRVOps.cpp @@ -1955,8 +1955,13 @@ // SPIR-V spec: "Storage Class is the Storage Class of the memory holding the // object. It cannot be Generic. It must be the same as the Storage Class // operand of the Result Type." - if (varOp.storageClass() == spirv::StorageClass::Generic) - return varOp.emitOpError("storage class cannot be 'Generic'"); + // Also, Function storage class is reserved by spv.Variable. + auto storageClass = varOp.storageClass(); + if (storageClass == spirv::StorageClass::Generic || + storageClass == spirv::StorageClass::Function) { + return varOp.emitOpError("storage class cannot be '") + << stringifyStorageClass(storageClass) << "'"; + } if (auto init = varOp.getAttrOfType(kInitializerAttrName)) { diff --git a/mlir/test/Dialect/SPIRV/structure-ops.mlir b/mlir/test/Dialect/SPIRV/structure-ops.mlir --- a/mlir/test/Dialect/SPIRV/structure-ops.mlir +++ b/mlir/test/Dialect/SPIRV/structure-ops.mlir @@ -347,6 +347,13 @@ // ----- +spv.module Logical GLSL450 { + // expected-error @+1 {{storage class cannot be 'Function'}} + spv.globalVariable @var0 : !spv.ptr +} + +// ----- + spv.module Logical GLSL450 { spv.func @foo() "None" { // expected-error @+1 {{op must appear in a module-like op's block}}