diff --git a/mlir/lib/IR/Operation.cpp b/mlir/lib/IR/Operation.cpp --- a/mlir/lib/IR/Operation.cpp +++ b/mlir/lib/IR/Operation.cpp @@ -231,8 +231,10 @@ InFlightDiagnostic Operation::emitError(const Twine &message) { InFlightDiagnostic diag = mlir::emitError(getLoc(), message); if (getContext()->shouldPrintOpOnDiagnostic()) { + // Emit the op on a new line if the op has one or more regions. diag.attachNote(getLoc()) - .append("see current operation: ") + .append("see current operation:") + .append(getNumRegions() > 0 ? '\n' : ' ') .appendOp(*this, OpPrintingFlags().printGenericOpForm()); } return diag; @@ -243,7 +245,11 @@ InFlightDiagnostic Operation::emitWarning(const Twine &message) { InFlightDiagnostic diag = mlir::emitWarning(getLoc(), message); if (getContext()->shouldPrintOpOnDiagnostic()) - diag.attachNote(getLoc()) << "see current operation: " << *this; + // Emit the op on a new line if the op has one or more regions. + diag.attachNote(getLoc()) + .append("see current operation:") + .append(getNumRegions() > 0 ? '\n' : ' ') + << *this; return diag; } @@ -252,7 +258,11 @@ InFlightDiagnostic Operation::emitRemark(const Twine &message) { InFlightDiagnostic diag = mlir::emitRemark(getLoc(), message); if (getContext()->shouldPrintOpOnDiagnostic()) - diag.attachNote(getLoc()) << "see current operation: " << *this; + // Emit the op on a new line if the op has one or more regions. + diag.attachNote(getLoc()) + .append("see current operation:") + .append(getNumRegions() > 0 ? '\n' : ' ') + << *this; return diag; } diff --git a/mlir/test/IR/print-op-on-diagnostic.mlir b/mlir/test/IR/print-op-on-diagnostic.mlir --- a/mlir/test/IR/print-op-on-diagnostic.mlir +++ b/mlir/test/IR/print-op-on-diagnostic.mlir @@ -3,5 +3,6 @@ // This file tests the functionality of 'mlir-print-op-on-diagnostic'. // CHECK: {{invalid to use 'test.invalid_attr'}} -// CHECK: {{see current operation: "builtin.module"()}} +// CHECK: see current operation: +// CHECK-NEXT: "builtin.module"() module attributes {test.invalid_attr} {}