[Mlir-commits] [mlir] a5621e2 - [mlir][spirv] Use type dyn_cast when scanning spv.GlobalVariable

Lei Zhang llvmlistbot at llvm.org
Sun Aug 29 09:08:20 PDT 2021


Author: Lei Zhang
Date: 2021-08-29T12:01:19-04:00
New Revision: a5621e26dbc90be3d5af164978f6fcc398f0a1d1

URL: https://github.com/llvm/llvm-project/commit/a5621e26dbc90be3d5af164978f6fcc398f0a1d1
DIFF: https://github.com/llvm/llvm-project/commit/a5621e26dbc90be3d5af164978f6fcc398f0a1d1.diff

LOG: [mlir][spirv] Use type dyn_cast when scanning spv.GlobalVariable

This avoids crashes when there are spv.GlobalVariable without
pointer type.

Added: 
    

Modified: 
    mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp b/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp
index 9097ef578abf..76abf15b92b6 100644
--- a/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp
+++ b/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp
@@ -700,7 +700,10 @@ static spirv::PointerType getPushConstantStorageType(unsigned elementCount,
 static spirv::GlobalVariableOp getPushConstantVariable(Block &body,
                                                        unsigned elementCount) {
   for (auto varOp : body.getOps<spirv::GlobalVariableOp>()) {
-    auto ptrType = varOp.type().cast<spirv::PointerType>();
+    auto ptrType = varOp.type().dyn_cast<spirv::PointerType>();
+    if (!ptrType)
+      continue;
+
     // Note that Vulkan requires "There must be no more than one push constant
     // block statically used per shader entry point." So we should always reuse
     // the existing one.


        


More information about the Mlir-commits mailing list