diff options
| author | Sean Silva <silvasean@google.com> | 2019-12-03 11:23:48 -0800 |
|---|---|---|
| committer | A. Unique TensorFlower <gardener@tensorflow.org> | 2019-12-03 11:24:31 -0800 |
| commit | 67515e8d7a3bf5bcaa8475890eea3c63d7ea732c (patch) | |
| tree | c9637b99a96aa2b57c81b813c04f1847b1be8cd9 | |
| parent | 4741ec6af0d49cec5fb49a370244657c27ca033c (diff) | |
| download | bcm5719-llvm-67515e8d7a3bf5bcaa8475890eea3c63d7ea732c.tar.gz bcm5719-llvm-67515e8d7a3bf5bcaa8475890eea3c63d7ea732c.zip | |
Verifier: Better error message in case of successor operand mismatch.
In particular, print the successor number in the diagnostic.
PiperOrigin-RevId: 283585084
| -rw-r--r-- | mlir/lib/IR/Operation.cpp | 15 | ||||
| -rw-r--r-- | mlir/test/IR/invalid.mlir | 15 |
2 files changed, 23 insertions, 7 deletions
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(); diff --git a/mlir/test/IR/invalid.mlir b/mlir/test/IR/invalid.mlir index ed650290a90..d0714d55a26 100644 --- a/mlir/test/IR/invalid.mlir +++ b/mlir/test/IR/invalid.mlir @@ -362,7 +362,7 @@ func @argError() { func @br_mismatch() { ^bb0: %0:2 = "foo"() : () -> (i1, i17) - // expected-error @+1 {{branch has 2 operands, but target block has 1}} + // expected-error @+1 {{branch has 2 operands for successor #0, but target block has 1}} br ^bb1(%0#1, %0#0 : i17, i1) ^bb1(%x: i17): @@ -371,6 +371,19 @@ func @br_mismatch() { // ----- +func @succ_arg_type_mismatch() { +^bb0: + %0 = "getBool"() : () -> i1 + // expected-error @+1 {{type mismatch for bb argument #0 of successor #0}} + br ^bb1(%0 : i1) + +^bb1(%x: i32): + return +} + + +// ----- + // Test no nested vector. func @vectors(vector<1 x vector<1xi32>>, vector<2x4xf32>) // expected-error@-1 {{vector elements must be int or float type}} |

