[Mlir-commits] [mlir] b948a9f - [mlir][spirv] Check GlobalVariableOp result to be of pointer types
Lei Zhang
llvmlistbot at llvm.org
Wed Nov 30 16:13:52 PST 2022
Author: Lei Zhang
Date: 2022-11-30T19:07:30-05:00
New Revision: b948a9f40ffec7d8128a44d304cfe7305b9f051c
URL: https://github.com/llvm/llvm-project/commit/b948a9f40ffec7d8128a44d304cfe7305b9f051c
DIFF: https://github.com/llvm/llvm-project/commit/b948a9f40ffec7d8128a44d304cfe7305b9f051c.diff
LOG: [mlir][spirv] Check GlobalVariableOp result to be of pointer types
Querying the storage class in the verifier will assume the result
type is of pointer types. We need to check that's true first to
make sure it won't crash.
Reviewed By: kuhar
Differential Revision: https://reviews.llvm.org/D139053
Added:
Modified:
mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
mlir/test/Dialect/SPIRV/IR/structure-ops.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp b/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
index 9a509796e5c19..6bb25a9fafbfe 100644
--- a/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
+++ b/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
@@ -2672,6 +2672,9 @@ void spirv::GlobalVariableOp::print(OpAsmPrinter &printer) {
}
LogicalResult spirv::GlobalVariableOp::verify() {
+ if (!getType().isa<spirv::PointerType>())
+ 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
index 37249de66105c..17305f9c1f1c8 100644
--- 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 {
// -----
+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<f32, Private>
More information about the Mlir-commits
mailing list