[Mlir-commits] [mlir] eecce28 - Fix PDL verifiers to be resilient to invalid IR

Mehdi Amini llvmlistbot at llvm.org
Fri Jan 6 11:35:48 PST 2023


Author: Mehdi Amini
Date: 2023-01-06T19:35:37Z
New Revision: eecce28dedfc1f3270584d8534a524f2c4e987d1

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

LOG: Fix PDL verifiers to be resilient to invalid IR

This would cause a crash when calling `dump()` on an operation that
didn't have a parent yet.

Added: 
    

Modified: 
    mlir/lib/Dialect/PDL/IR/PDL.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/PDL/IR/PDL.cpp b/mlir/lib/Dialect/PDL/IR/PDL.cpp
index 49692f62ac9bb..7778d943587d5 100644
--- a/mlir/lib/Dialect/PDL/IR/PDL.cpp
+++ b/mlir/lib/Dialect/PDL/IR/PDL.cpp
@@ -48,7 +48,7 @@ static bool hasBindingUse(Operation *op) {
 /// is used by a "binding" operation. On failure, emits an error.
 static LogicalResult verifyHasBindingUse(Operation *op) {
   // If the parent is not a pattern, there is nothing to do.
-  if (!isa<PatternOp>(op->getParentOp()))
+  if (!llvm::isa_and_nonnull<PatternOp>(op->getParentOp()))
     return success();
   if (hasBindingUse(op))
     return success();
@@ -265,7 +265,7 @@ static LogicalResult verifyResultTypesAreInferrable(OperationOp op,
 }
 
 LogicalResult OperationOp::verify() {
-  bool isWithinRewrite = isa<RewriteOp>((*this)->getParentOp());
+  bool isWithinRewrite = isa_and_nonnull<RewriteOp>((*this)->getParentOp());
   if (isWithinRewrite && !getOpName())
     return emitOpError("must have an operation name when nested within "
                        "a `pdl.rewrite`");


        


More information about the Mlir-commits mailing list