[mlir][spirv] Check nullptr before usage to fix crash
authorLei Zhang <antiagainst@google.com>
Mon, 4 Apr 2022 21:19:44 +0000 (17:19 -0400)
committerLei Zhang <antiagainst@google.com>
Mon, 4 Apr 2022 21:20:00 +0000 (17:20 -0400)
Reviewed By: mravishankar, hanchung

Differential Revision: https://reviews.llvm.org/D123035

mlir/lib/Conversion/ArithmeticToSPIRV/ArithmeticToSPIRV.cpp

index 4350197..0170eda 100644 (file)
@@ -294,10 +294,11 @@ LogicalResult ConstantCompositeOpPattern::matchAndRewrite(
     return failure();
 
   auto dstElementsAttr = constOp.getValue().dyn_cast<DenseElementsAttr>();
-  ShapedType dstAttrType = dstElementsAttr.getType();
   if (!dstElementsAttr)
     return failure();
 
+  ShapedType dstAttrType = dstElementsAttr.getType();
+
   // If the composite type has more than one dimensions, perform linearization.
   if (srcType.getRank() > 1) {
     if (srcType.isa<RankedTensorType>()) {