diff --git a/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp b/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp --- a/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp +++ b/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp @@ -2672,6 +2672,9 @@ } LogicalResult spirv::GlobalVariableOp::verify() { + if (!getType().isa()) + return emitOpError("result must be of a !spv.ptr type"); + // 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." diff --git a/mlir/test/Dialect/SPIRV/IR/structure-ops.mlir b/mlir/test/Dialect/SPIRV/IR/structure-ops.mlir --- a/mlir/test/Dialect/SPIRV/IR/structure-ops.mlir +++ b/mlir/test/Dialect/SPIRV/IR/structure-ops.mlir @@ -369,6 +369,13 @@ // ----- +spirv.module Logical GLSL450 { + // expected-error @+1 {{result must be of a !spv.ptr type}} + "spirv.GlobalVariable"() {sym_name = "var0", type = none} : () -> () +} + +// ----- + spirv.module Logical GLSL450 { // expected-error @+1 {{op initializer must be result of a spirv.SpecConstant or spirv.GlobalVariable op}} spirv.GlobalVariable @var0 initializer(@var1) : !spirv.ptr