Skip to content

Commit

Permalink
Fix PDL verifiers to be resilient to invalid IR
Browse files Browse the repository at this point in the history
This would cause a crash when calling `dump()` on an operation that
didn't have a parent yet.
  • Loading branch information
joker-eph committed Jan 6, 2023
1 parent d3933a5 commit eecce28
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions mlir/lib/Dialect/PDL/IR/PDL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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`");
Expand Down

0 comments on commit eecce28

Please sign in to comment.