diff --git a/mlir/include/mlir/IR/Diagnostics.h b/mlir/include/mlir/IR/Diagnostics.h --- a/mlir/include/mlir/IR/Diagnostics.h +++ b/mlir/include/mlir/IR/Diagnostics.h @@ -197,10 +197,10 @@ Diagnostic &operator<<(OperationName val); /// Stream in an Operation. - Diagnostic &operator<<(Operation &val); - Diagnostic &operator<<(Operation *val) { return *this << *val; } + Diagnostic &operator<<(Operation &op); + Diagnostic &operator<<(Operation *op) { return *this << *op; } /// Append an operation with the given printing flags. - Diagnostic &appendOp(Operation &val, const OpPrintingFlags &flags); + Diagnostic &appendOp(Operation &op, const OpPrintingFlags &flags); /// Stream in a Value. Diagnostic &operator<<(Value val); diff --git a/mlir/lib/IR/Diagnostics.cpp b/mlir/lib/IR/Diagnostics.cpp --- a/mlir/lib/IR/Diagnostics.cpp +++ b/mlir/lib/IR/Diagnostics.cpp @@ -133,13 +133,18 @@ } /// Stream in an Operation. -Diagnostic &Diagnostic::operator<<(Operation &val) { - return appendOp(val, OpPrintingFlags()); +Diagnostic &Diagnostic::operator<<(Operation &op) { + return appendOp(op, OpPrintingFlags()); } -Diagnostic &Diagnostic::appendOp(Operation &val, const OpPrintingFlags &flags) { + +Diagnostic &Diagnostic::appendOp(Operation &op, const OpPrintingFlags &flags) { std::string str; llvm::raw_string_ostream os(str); - val.print(os, adjustPrintingFlags(flags, severity)); + op.print(os, adjustPrintingFlags(flags, severity)); + // Print on a new line for better readability if the op will be printed on + // multiple lines. + if (str.find('\n') != std::string::npos) + *this << '\n'; return *this << os.str(); } 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 @@ -1,7 +1,18 @@ -// RUN: not mlir-opt %s -mlir-print-op-on-diagnostic 2>&1 | FileCheck %s +// RUN: not mlir-opt -split-input-file %s -mlir-print-op-on-diagnostic 2>&1 | FileCheck %s // 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} {} + +// ----- + +func.func @foo() { + "test.foo"(%cst) : (index) -> () + // CHECK: {{operand #0 does not dominate this use}} + // CHECK: {{see current operation: "test.foo"(.*)}} + %cst = arith.constant 0 : index + return +}