From 67515e8d7a3bf5bcaa8475890eea3c63d7ea732c Mon Sep 17 00:00:00 2001 From: Sean Silva Date: Tue, 3 Dec 2019 11:23:48 -0800 Subject: Verifier: Better error message in case of successor operand mismatch. In particular, print the successor number in the diagnostic. PiperOrigin-RevId: 283585084 --- mlir/lib/IR/Operation.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'mlir/lib') diff --git a/mlir/lib/IR/Operation.cpp b/mlir/lib/IR/Operation.cpp index f0ebd59ab9f..d079033e39b 100644 --- a/mlir/lib/IR/Operation.cpp +++ b/mlir/lib/IR/Operation.cpp @@ -901,18 +901,21 @@ LogicalResult OpTrait::impl::verifySameOperandsAndResultType(Operation *op) { return success(); } -static LogicalResult verifyBBArguments(Operation::operand_range operands, - Block *destBB, Operation *op) { - unsigned operandCount = std::distance(operands.begin(), operands.end()); +static LogicalResult verifySuccessor(Operation *op, unsigned succNo) { + Operation::operand_range operands = op->getSuccessorOperands(succNo); + unsigned operandCount = op->getNumSuccessorOperands(succNo); + Block *destBB = op->getSuccessor(succNo); if (operandCount != destBB->getNumArguments()) return op->emitError() << "branch has " << operandCount - << " operands, but target block has " + << " operands for successor #" << succNo + << ", but target block has " << destBB->getNumArguments(); auto operandIt = operands.begin(); for (unsigned i = 0, e = operandCount; i != e; ++i, ++operandIt) { if ((*operandIt)->getType() != destBB->getArgument(i)->getType()) - return op->emitError() << "type mismatch in bb argument #" << i; + return op->emitError() << "type mismatch for bb argument #" << i + << " of successor #" << succNo; } return success(); @@ -926,7 +929,7 @@ static LogicalResult verifyTerminatorSuccessors(Operation *op) { auto *succ = op->getSuccessor(i); if (succ->getParent() != parent) return op->emitError("reference to block defined in another region"); - if (failed(verifyBBArguments(op->getSuccessorOperands(i), succ, op))) + if (failed(verifySuccessor(op, i))) return failure(); } return success(); -- cgit v1.2.3