[llvm] [llubi] Reset retval when return type is void (PR #205107)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 22 06:42:00 PDT 2026
https://github.com/dtcxzyw created https://github.com/llvm/llvm-project/pull/205107
In `returnFromCallee`, the return value is moved out from `CurrentFrame->RetVal`. So `visitReturnInst` is always responsible for setting a valid value.
Closes https://github.com/llvm/llvm-project/issues/204992
>From 9bfaacf77399b11a690baa59e0a92ecedf9123e2 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng <dtcxzyw2333 at gmail.com>
Date: Mon, 22 Jun 2026 21:38:57 +0800
Subject: [PATCH] [llubi] Reset retval when return type is void
---
.../tools/llubi/reset_return_value_slot.ll | 30 +++++++++++++++++++
llvm/tools/llubi/lib/Interpreter.cpp | 2 ++
2 files changed, 32 insertions(+)
create mode 100644 llvm/test/tools/llubi/reset_return_value_slot.ll
diff --git a/llvm/test/tools/llubi/reset_return_value_slot.ll b/llvm/test/tools/llubi/reset_return_value_slot.ll
new file mode 100644
index 0000000000000..72cab180e4556
--- /dev/null
+++ b/llvm/test/tools/llubi/reset_return_value_slot.ll
@@ -0,0 +1,30 @@
+; NOTE: Assertions have been autogenerated by utils/update_llubi_test_checks.py UTC_ARGS: --version 6
+; RUN: llubi --verbose < %s 2>&1 | FileCheck %s
+
+define void @main() {
+entry:
+ %res = call i16 @func1()
+ call void @func2()
+ ret void
+}
+
+define i16 @func1() {
+entry:
+ ret i16 0
+}
+
+define void @func2() {
+entry:
+ ret void
+}
+; CHECK: Entering function: main
+; CHECK-NEXT: Entering function: func1
+; CHECK-NEXT: ret i16 0
+; CHECK-NEXT: Exiting function: func1
+; CHECK-NEXT: %res = call i16 @func1() => i16 0
+; CHECK-NEXT: Entering function: func2
+; CHECK-NEXT: ret void
+; CHECK-NEXT: Exiting function: func2
+; CHECK-NEXT: call void @func2()
+; CHECK-NEXT: ret void
+; CHECK-NEXT: Exiting function: main
diff --git a/llvm/tools/llubi/lib/Interpreter.cpp b/llvm/tools/llubi/lib/Interpreter.cpp
index 588f1069c2a80..f833b660f4e3a 100644
--- a/llvm/tools/llubi/lib/Interpreter.cpp
+++ b/llvm/tools/llubi/lib/Interpreter.cpp
@@ -710,6 +710,8 @@ class InstExecutor : public InstVisitor<InstExecutor, void>,
void visitReturnInst(ReturnInst &RI) {
if (auto *RV = RI.getReturnValue())
CurrentFrame->RetVal = getValue(RV);
+ else
+ CurrentFrame->RetVal = AnyValue();
CurrentFrame->State = FrameState::Exit;
if (!Handler.onInstructionExecuted(RI, None))
setFailed();
More information about the llvm-commits
mailing list