[llvm] [llubi] Always print out error message (PR #205573)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 24 08:04:18 PDT 2026
https://github.com/dtcxzyw created https://github.com/llvm/llvm-project/pull/205573
When `--verbose` is not specified, the error message and UB reason are omitted. However, this information is still useful for test oracles. For example, the fuzzer may skip the seed when it runs out of time.
BTW, the stack trace is always dumped. Not sure if it is intended or not.
>From e965681d83149e45f1dc084f7cdd068363c8b9f4 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng <dtcxzyw2333 at gmail.com>
Date: Wed, 24 Jun 2026 22:51:39 +0800
Subject: [PATCH 1/2] [llubi] Add pre-commit tests. NFC.
---
llvm/test/tools/llubi/infinite_loop_error_only.ll | 13 +++++++++++++
1 file changed, 13 insertions(+)
create mode 100644 llvm/test/tools/llubi/infinite_loop_error_only.ll
diff --git a/llvm/test/tools/llubi/infinite_loop_error_only.ll b/llvm/test/tools/llubi/infinite_loop_error_only.ll
new file mode 100644
index 0000000000000..9c0fbe3e813f9
--- /dev/null
+++ b/llvm/test/tools/llubi/infinite_loop_error_only.ll
@@ -0,0 +1,13 @@
+; NOTE: Assertions have been autogenerated by utils/update_llubi_test_checks.py UTC_ARGS: --version 6
+; RUN: not llubi --max-steps 10 < %s 2>&1 | FileCheck %s
+
+define void @main() {
+entry:
+ br label %loop
+
+loop:
+ br label %loop
+}
+; CHECK: Stacktrace:
+; CHECK-NEXT: #0 br label %loop at @main <stdin>:9
+; CHECK-NEXT: error: Execution of function 'main' failed.
>From 1397dac0b1a82d0492821025f867a7d9eb117564 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng <dtcxzyw2333 at gmail.com>
Date: Wed, 24 Jun 2026 22:53:49 +0800
Subject: [PATCH 2/2] [llubi] Always print out error message
---
.../tools/llubi/infinite_loop_error_only.ll | 1 +
llvm/tools/llubi/llubi.cpp | 26 ++++++++++---------
2 files changed, 15 insertions(+), 12 deletions(-)
diff --git a/llvm/test/tools/llubi/infinite_loop_error_only.ll b/llvm/test/tools/llubi/infinite_loop_error_only.ll
index 9c0fbe3e813f9..01680e5783665 100644
--- a/llvm/test/tools/llubi/infinite_loop_error_only.ll
+++ b/llvm/test/tools/llubi/infinite_loop_error_only.ll
@@ -10,4 +10,5 @@ loop:
}
; CHECK: Stacktrace:
; CHECK-NEXT: #0 br label %loop at @main <stdin>:9
+; CHECK-NEXT: Error: Exceeded maximum number of execution steps.
; CHECK-NEXT: error: Execution of function 'main' failed.
diff --git a/llvm/tools/llubi/llubi.cpp b/llvm/tools/llubi/llubi.cpp
index 56bd7f49eabd9..fd6d0fa807761 100644
--- a/llvm/tools/llubi/llubi.cpp
+++ b/llvm/tools/llubi/llubi.cpp
@@ -123,7 +123,19 @@ cl::opt<ubi::NaNPropagationBehavior> NaNPropagationBehavior(
"payloads.")),
cl::init(ubi::NaNPropagationBehavior::NonDeterministic));
-class VerboseEventHandler : public ubi::EventHandler {
+class NoopEventHandler : public ubi::EventHandler {
+ void onImmediateUB(StringRef Msg) override {
+ errs() << "Immediate UB detected: " << Msg << '\n';
+ }
+
+ void onError(StringRef Msg) override { errs() << "Error: " << Msg << '\n'; }
+
+ void onUnrecognizedInstruction(Instruction &I) override {
+ errs() << "Unrecognized instruction: " << I << '\n';
+ }
+};
+
+class VerboseEventHandler : public NoopEventHandler {
public:
bool onInstructionExecuted(Instruction &I,
const ubi::AnyValue &Result) override {
@@ -136,12 +148,6 @@ class VerboseEventHandler : public ubi::EventHandler {
return true;
}
- void onImmediateUB(StringRef Msg) override {
- errs() << "Immediate UB detected: " << Msg << '\n';
- }
-
- void onError(StringRef Msg) override { errs() << "Error: " << Msg << '\n'; }
-
bool onBBJump(Instruction &I, BasicBlock &To) override {
errs() << I << " jump to ";
To.printAsOperand(errs(), /*PrintType=*/false);
@@ -186,10 +192,6 @@ class VerboseEventHandler : public ubi::EventHandler {
llvm_unreachable("Unknown ProgramExitKind");
}
-
- void onUnrecognizedInstruction(Instruction &I) override {
- errs() << "Unrecognized instruction: " << I << '\n';
- }
};
int main(int argc, char **argv) {
@@ -317,7 +319,7 @@ int main(int argc, char **argv) {
Args.push_back(ubi::AnyValue::getNullValue(Ctx, Arg.getType()));
}
- ubi::EventHandler NoopHandler;
+ NoopEventHandler NoopHandler;
VerboseEventHandler VerboseHandler;
ubi::AnyValue RetVal;
ubi::ProgramExitInfo ExitInfo = Ctx.runFunction(
More information about the llvm-commits
mailing list