diff --git a/mlir/lib/Dialect/StandardOps/IR/Ops.cpp b/mlir/lib/Dialect/StandardOps/IR/Ops.cpp --- a/mlir/lib/Dialect/StandardOps/IR/Ops.cpp +++ b/mlir/lib/Dialect/StandardOps/IR/Ops.cpp @@ -2023,15 +2023,16 @@ 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(); } diff --git a/mlir/test/IR/invalid.mlir b/mlir/test/IR/invalid.mlir --- a/mlir/test/IR/invalid.mlir +++ b/mlir/test/IR/invalid.mlir @@ -335,13 +335,13 @@ 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 @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}} } // -----