SingleBlockImplicitTerminator: report the wrong terminator op found
authorAlex Zinenko <zinenko@google.com>
Mon, 22 Jul 2019 09:41:39 +0000 (02:41 -0700)
committerA. Unique TensorFlower <gardener@tensorflow.org>
Mon, 22 Jul 2019 09:42:06 +0000 (02:42 -0700)
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
mlir/test/IR/invalid.mlir

index 2f33475..4ab4996 100644 (file)
@@ -819,11 +819,14 @@ template <typename TerminatorOpType> struct SingleBlockImplicitTerminator {
         Block &block = region.front();
         if (block.empty())
           return failure();
-        if (isa<TerminatorOpType>(block.back()))
+        Operation &terminator = block.back();
+        if (isa<TerminatorOpType>(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 "
                   "'"
index 3b852c3..4250ab4 100644 (file)
@@ -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
   }