[mlir][spirv] Use type dyn_cast when scanning spv.GlobalVariable
authorLei Zhang <antiagainst@google.com>
Sun, 29 Aug 2021 16:01:19 +0000 (12:01 -0400)
committerLei Zhang <antiagainst@google.com>
Sun, 29 Aug 2021 16:01:19 +0000 (12:01 -0400)
This avoids crashes when there are spv.GlobalVariable without
pointer type.

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

index 9097ef5..76abf15 100644 (file)
@@ -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.