From fa86c8991701edc02f1e861b4274abdefba4e2bb Mon Sep 17 00:00:00 2001 From: Alex Zinenko Date: Mon, 22 Jul 2019 02:41:39 -0700 Subject: [PATCH] SingleBlockImplicitTerminator: report the wrong terminator op found In the trait verifier of SingleBlockImplicitTerminator, report the name of the unexpected terminator op found in the end of the block in addition to the name of the expected terminator op. This may simplify debugging, especially in cases where the terminator is omitted for brevity and/or after a long series of conversions. PiperOrigin-RevId: 259287452 --- mlir/include/mlir/IR/OpDefinition.h | 7 +++++-- mlir/test/IR/invalid.mlir | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/mlir/include/mlir/IR/OpDefinition.h b/mlir/include/mlir/IR/OpDefinition.h index 2f33475..4ab4996 100644 --- a/mlir/include/mlir/IR/OpDefinition.h +++ b/mlir/include/mlir/IR/OpDefinition.h @@ -819,11 +819,14 @@ template struct SingleBlockImplicitTerminator { Block &block = region.front(); if (block.empty()) return failure(); - if (isa(block.back())) + Operation &terminator = block.back(); + if (isa(terminator)) continue; return op->emitOpError("expects regions to end with '" + - TerminatorOpType::getOperationName() + "'") + TerminatorOpType::getOperationName() + + "', found '" + + terminator.getName().getStringRef() + "'") .attachNote() << "in custom textual format, the absence of terminator implies " "'" diff --git a/mlir/test/IR/invalid.mlir b/mlir/test/IR/invalid.mlir index 3b852c3..4250ab4 100644 --- a/mlir/test/IR/invalid.mlir +++ b/mlir/test/IR/invalid.mlir @@ -434,7 +434,7 @@ func @return_type_mismatch() -> i32 { func @return_inside_loop() { affine.for %i = 1 to 100 { - // expected-error@-1 {{op expects regions to end with 'affine.terminator'}} + // expected-error@-1 {{op expects regions to end with 'affine.terminator', found 'std.return'}} // expected-note@-2 {{in custom textual format, the absence of terminator implies}} return } -- 2.7.4