[Mlir-commits] [mlir] 99c4635 - [MLIR] Do not abort on invalid --mlir-debug-counter values (#181751)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Feb 26 16:50:14 PST 2026
Author: Shashi Shankar
Date: 2026-02-27T09:50:10+09:00
New Revision: 99c463512a0458ff1a1928d670cded3b320eb990
URL: https://github.com/llvm/llvm-project/commit/99c463512a0458ff1a1928d670cded3b320eb990
DIFF: https://github.com/llvm/llvm-project/commit/99c463512a0458ff1a1928d670cded3b320eb990.diff
LOG: [MLIR] Do not abort on invalid --mlir-debug-counter values (#181751)
Use `cl::Option::error()` diagnostics for invalid `--mlir-debug-counter`
arguments and exit with status 1 (no stack dump).
Added `mlir/test/mlir-opt/debugcounter-invalid-cl-options.mlir`
covering:
- non-numeric value (`-1n`)
- missing `=`
- missing `-skip`/`-count` suffix
Fixes #180117
Added:
mlir/test/mlir-opt/debugcounter-invalid-cl-options.mlir
Modified:
mlir/lib/Debug/DebugCounter.cpp
Removed:
################################################################################
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