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.
This commit is contained in:
Mehdi Amini 2023-01-06 19:34:28 +00:00
parent d3933a5d75
commit eecce28ded

View File

@ -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`");