[Mlir-commits] [mlir] [MLIR] Do not abort on invalid --mlir-debug-counter values (PR #181751)
Shashi Shankar
llvmlistbot at llvm.org
Tue Feb 17 09:47:20 PST 2026
https://github.com/shashforge updated https://github.com/llvm/llvm-project/pull/181751
>From a7c04838b8808428190cf0fe82ff7eb72ff27094 Mon Sep 17 00:00:00 2001
From: Shashi Shankar <shashishankar1687 at gmail.com>
Date: Mon, 16 Feb 2026 22:52:23 +0100
Subject: [PATCH] =?UTF-8?q?\[MLIR]=20Don=E2=80=99t=20abort=20on=20invalid?=
=?UTF-8?q?=20--mlir-debug-counter=20values?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Treat malformed --mlir-debug-counter arguments as normal CLI errors instead of calling report_fatal_error.
Use cl::Option::error() and exit(1) to avoid stack dumps for user input errors.
Add mlir-opt tests for invalid numeric values (-1n), missing '=', missing suffix, and a valid configuration.
Tested: ninja check-mlir
---
mlir/lib/Debug/DebugCounter.cpp | 33 ++++++++++---------
.../debugcounter-invalid-cl-options.mlir | 27 +++++++++++++++
2 files changed, 44 insertions(+), 16 deletions(-)
create mode 100644 mlir/test/mlir-opt/debugcounter-invalid-cl-options.mlir
diff --git a/mlir/lib/Debug/DebugCounter.cpp b/mlir/lib/Debug/DebugCounter.cpp
index e026a982859a9..879f6c9365cf6 100644
--- a/mlir/lib/Debug/DebugCounter.cpp
+++ b/mlir/lib/Debug/DebugCounter.cpp
@@ -132,22 +132,23 @@ void DebugCounter::applyCLOptions() {
// Debug counter arguments are expected to be in the form: `counter=value`.
auto [counterName, counterValueStr] = arg.split('=');
if (counterValueStr.empty()) {
- llvm::errs() << "error: expected DebugCounter argument to have an `=` "
- "separating the counter name and value, but the provided "
- "argument was: `"
- << arg << "`\n";
- llvm::report_fatal_error(
- "Invalid DebugCounter command-line configuration");
+ clOptions->counters.error(
+ llvm::Twine(
+ "expected DebugCounter argument to have an `=` separating "
+ "the counter name and value, but the provided argument "
+ "was: `") +
+ arg + "`");
+ exit(1);
}
// Extract the counter value.
int64_t counterValue;
if (counterValueStr.getAsInteger(0, counterValue)) {
- llvm::errs() << "error: expected DebugCounter counter value to be "
- "numeric, but got `"
- << counterValueStr << "`\n";
- llvm::report_fatal_error(
- "Invalid DebugCounter command-line configuration");
+ clOptions->counters.error(
+ llvm::Twine("expected DebugCounter counter value to be numeric, but "
+ "got `") +
+ counterValueStr + "`");
+ exit(1);
}
// Now we need to see if this is the skip or the count, remove the suffix,
@@ -159,11 +160,11 @@ void DebugCounter::applyCLOptions() {
counters[counterName].countToStopAfter = counterValue;
} else {
- llvm::errs() << "error: expected DebugCounter counter name to end with "
- "either `-skip` or `-count`, but got`"
- << counterName << "`\n";
- llvm::report_fatal_error(
- "Invalid DebugCounter command-line configuration");
+ clOptions->counters.error(
+ llvm::Twine("expected DebugCounter counter name to end with either "
+ "`-skip` or `-count`, but got `") +
+ counterName + "`");
+ exit(1);
}
}
}
diff --git a/mlir/test/mlir-opt/debugcounter-invalid-cl-options.mlir b/mlir/test/mlir-opt/debugcounter-invalid-cl-options.mlir
new file mode 100644
index 0000000000000..ab66fedede6e8
--- /dev/null
+++ b/mlir/test/mlir-opt/debugcounter-invalid-cl-options.mlir
@@ -0,0 +1,27 @@
+// RUN: not mlir-opt %s --mlir-disable-threading \
+// RUN: --mlir-debug-counter=unique-tag-for-my-action-skip=-1n 2>&1 \
+// RUN: | FileCheck %s --check-prefix=BADNUM
+//
+// RUN: not mlir-opt %s --mlir-disable-threading \
+// RUN: --mlir-debug-counter=unique-tag-for-my-action-skip 2>&1 \
+// RUN: | FileCheck %s --check-prefix=NOEQ
+//
+// RUN: not mlir-opt %s --mlir-disable-threading \
+// RUN: --mlir-debug-counter=unique-tag-for-my-action=-1 2>&1 \
+// RUN: | FileCheck %s --check-prefix=BADSFX
+
+func.func @foo() {
+ return
+}
+
+// BADNUM-NOT: LLVM ERROR
+// BADNUM-NOT: Stack dump:
+// BADNUM: {{.*}}: for the {{-+}}mlir-debug-counter option: expected DebugCounter counter value to be numeric, but got `-1n`
+
+// NOEQ-NOT: LLVM ERROR
+// NOEQ-NOT: Stack dump:
+// NOEQ: {{.*}}: for the {{-+}}mlir-debug-counter option: expected DebugCounter argument to have an `=` separating the counter name and value, but the provided argument was: `unique-tag-for-my-action-skip`
+
+// BADSFX-NOT: LLVM ERROR
+// BADSFX-NOT: Stack dump:
+// BADSFX: {{.*}}: for the {{-+}}mlir-debug-counter option: expected DebugCounter counter name to end with either `-skip` or `-count`, but got `unique-tag-for-my-action`
More information about the Mlir-commits
mailing list