Continue revising diagnostic handling to simplify and generalize it, and improve related infra.
- Add a new -verify mode to the mlir-opt tool that allows writing test cases
for optimization and other passes that produce diagnostics.
- Refactor existing the -check-parser-errors flag to mlir-opt into a new
-split-input-file option which is orthogonal to -verify.
- Eliminate the special error hook the parser maintained and use the standard
MLIRContext's one instead.
- Enhance the default MLIRContext error reporter to print file/line/col of
errors when it is available.
- Add new createChecked() methods to the builder that create ops and invoke
the verify hook on them, use this to detected unhandled code in the
RaiseControlFlow pass.
- Teach mlir-opt about expected-error @+, it previously only worked with @-
PiperOrigin-RevId: 211305770
diff --git a/lib/IR/MLIRContext.cpp b/lib/IR/MLIRContext.cpp
index 46d0103..32e2f52 100644
--- a/lib/IR/MLIRContext.cpp
+++ b/lib/IR/MLIRContext.cpp
@@ -319,11 +319,17 @@
if (kind != DiagnosticKind::Error)
return;
- // TODO(clattner): can improve this now!
+ auto &os = llvm::errs();
+
+ if (auto fileLoc = dyn_cast<FileLineColLoc>(location))
+ os << fileLoc->getFilename() << ':' << fileLoc->getLine() << ':'
+ << fileLoc->getColumn() << ": ";
+
+ os << "error: ";
// The default behavior for errors is to emit them to stderr and exit.
- llvm::errs() << message.str() << "\n";
- llvm::errs().flush();
+ os << message.str() << '\n';
+ os.flush();
exit(1);
}