using namespace mlir;
//===----------------------------------------------------------------------===//
-// Translation Parser
+// Diagnostic Filter
+//===----------------------------------------------------------------------===//
+
+namespace {
+/// A scoped diagnostic handler that marks non-error diagnostics as handled. As
+/// a result, the main diagnostic handler does not print non-error diagnostics.
+class ErrorDiagnosticFilter : public ScopedDiagnosticHandler {
+public:
+ ErrorDiagnosticFilter(MLIRContext *ctx) : ScopedDiagnosticHandler(ctx) {
+ setHandler([](Diagnostic &diag) {
+ if (diag.getSeverity() != DiagnosticSeverity::Error)
+ return success();
+ return failure();
+ });
+ }
+};
+} // namespace
+
+//===----------------------------------------------------------------------===//
+// Translate Entry Point
//===----------------------------------------------------------------------===//
LogicalResult mlir::mlirTranslateMain(int argc, char **argv,
"expected-* lines on the corresponding line"),
llvm::cl::init(false));
+ static llvm::cl::opt<bool> errorDiagnosticsOnly(
+ "error-diagnostics-only",
+ llvm::cl::desc("Filter all non-error diagnostics "
+ "(discouraged: testing only!)"),
+ llvm::cl::init(false));
+
llvm::InitLLVM y(argc, argv);
// Add flags for all the registered translations.
if (verifyDiagnostics) {
// In the diagnostic verification flow, we ignore whether the
- // translation failed (in most cases, it is expected to fail).
- // Instead, we check if the diagnostics were produced as expected.
+ // translation failed (in most cases, it is expected to fail) and we do
+ // not filter non-error diagnostics even if `errorDiagnosticsOnly` is
+ // set. Instead, we check if the diagnostics were produced as expected.
SourceMgrDiagnosticVerifierHandler sourceMgrHandler(*sourceMgr,
&context);
(void)(*translationRequested)(sourceMgr, os, &context);
result = sourceMgrHandler.verify();
+ } else if (errorDiagnosticsOnly) {
+ SourceMgrDiagnosticHandler sourceMgrHandler(*sourceMgr, &context);
+ ErrorDiagnosticFilter diagnosticFilter(&context);
+ result = (*translationRequested)(sourceMgr, *stream, &context);
} else {
SourceMgrDiagnosticHandler sourceMgrHandler(*sourceMgr, &context);
result = (*translationRequested)(sourceMgr, *stream, &context);
--- /dev/null
+; RUN: not mlir-translate %s -import-llvm -split-input-file -error-diagnostics-only 2>&1 | FileCheck %s --check-prefix=ERROR
+; RUN: not mlir-translate %s -import-llvm -split-input-file 2>&1 | FileCheck %s --check-prefix=ALL
+
+; ERROR-NOT: warning:
+; ALL: warning:
+define void @warning(i64 %n, ptr %A) {
+entry:
+ br label %end, !llvm.loop !0
+end:
+ ret void
+}
+
+!0 = distinct !{!0, !1, !2}
+!1 = !{!"llvm.loop.disable_nonforced"}
+!2 = !{!"llvm.loop.typo"}
+
+; // -----
+
+; ERROR: error:
+; ALL: error:
+define i32 @error(ptr %dst) {
+ indirectbr ptr %dst, [label %bb1, label %bb2]
+bb1:
+ ret i32 0
+bb2:
+ ret i32 1
+}