[MLIR] Print function name when ReturnOp verification fails
authorRahul Joshi <jurahul@google.com>
Thu, 11 Jun 2020 00:22:30 +0000 (17:22 -0700)
committerRiver Riddle <riddleriver@gmail.com>
Thu, 11 Jun 2020 00:22:49 +0000 (17:22 -0700)
Summary:
- Print function name when ReturnOp verification fails
- This helps easily finding the invalid ReturnOp in an IR dump.

Differential Revision: https://reviews.llvm.org/D81513

mlir/lib/Dialect/StandardOps/IR/Ops.cpp
mlir/test/IR/invalid.mlir

index 47532c5..e3107d6 100644 (file)
@@ -2023,15 +2023,16 @@ static LogicalResult verify(ReturnOp op) {
   const auto &results = function.getType().getResults();
   if (op.getNumOperands() != results.size())
     return op.emitOpError("has ")
-           << op.getNumOperands()
-           << " operands, but enclosing function returns " << results.size();
+           << op.getNumOperands() << " operands, but enclosing function (@"
+           << function.getName() << ") returns " << results.size();
 
   for (unsigned i = 0, e = results.size(); i != e; ++i)
     if (op.getOperand(i).getType() != results[i])
       return op.emitError()
              << "type of return operand " << i << " ("
              << op.getOperand(i).getType()
-             << ") doesn't match function result type (" << results[i] << ")";
+             << ") doesn't match function result type (" << results[i] << ")"
+             << " in function @" << function.getName();
 
   return success();
 }
index 9af96f2..f075215 100644 (file)
@@ -335,13 +335,13 @@ func @malformed_type(%a : intt) { // expected-error {{expected non-function type
 
 func @resulterror() -> i32 {
 ^bb42:
-  return    // expected-error {{'std.return' op has 0 operands, but enclosing function returns 1}}
+  return    // expected-error {{'std.return' op has 0 operands, but enclosing function (@resulterror) returns 1}}
 }
 
 // -----
 
 func @func_resulterror() -> i32 {
-  return // expected-error {{'std.return' op has 0 operands, but enclosing function returns 1}}
+  return // expected-error {{'std.return' op has 0 operands, but enclosing function (@func_resulterror) returns 1}}
 }
 
 // -----
@@ -467,7 +467,7 @@ func @dominance_failure() {
 
 func @return_type_mismatch() -> i32 {
   %0 = "foo"() : ()->f32
-  return %0 : f32  // expected-error {{type of return operand 0 ('f32') doesn't match function result type ('i32')}}
+  return %0 : f32  // expected-error {{type of return operand 0 ('f32') doesn't match function result type ('i32') in function @return_type_mismatch}}
 }
 
 // -----