[llvm] [lli] fix lli crash when run variable arguments function as a interpret (PR #173719)

via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 11 23:35:56 PST 2026


https://github.com/Fushj89 updated https://github.com/llvm/llvm-project/pull/173719

>From a652aaa8e8462c031ff86bf944c990632d94db98 Mon Sep 17 00:00:00 2001
From: fushijian <fsjzzu at 126.com>
Date: Sat, 27 Dec 2025 20:07:29 +0800
Subject: [PATCH] [lli] fix lli crash when run variable arguments function as a
 interpret

---
 .../ExecutionEngine/Interpreter/Execution.cpp |  8 ++++---
 .../test-interp-variable-arguments.ll         | 24 +++++++++++++++++++
 2 files changed, 29 insertions(+), 3 deletions(-)
 create mode 100644 llvm/test/ExecutionEngine/test-interp-variable-arguments.ll

diff --git a/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp b/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp
index 2d69edef878e6..02ec403807861 100644
--- a/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp
+++ b/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp
@@ -1084,7 +1084,7 @@ void Interpreter::visitVAStartInst(VAStartInst &I) {
   GenericValue ArgIndex;
   ArgIndex.UIntPairVal.first = ECStack.size() - 1;
   ArgIndex.UIntPairVal.second = 0;
-  SetValue(&I, ArgIndex, SF);
+  SetValue(I.getArgList(), ArgIndex, SF);
 }
 
 void Interpreter::visitVAEndInst(VAEndInst &I) {
@@ -1731,7 +1731,8 @@ void Interpreter::visitVAArgInst(VAArgInst &I) {
 
   // Get the incoming valist parameter.  LLI treats the valist as a
   // (ec-stack-depth var-arg-index) pair.
-  GenericValue VAList = getOperandValue(I.getOperand(0), SF);
+  Value *V = I.getOperand(0);
+  GenericValue VAList = getOperandValue(V, SF);
   GenericValue Dest;
   GenericValue Src = ECStack[VAList.UIntPairVal.first]
                       .VarArgs[VAList.UIntPairVal.second];
@@ -1751,8 +1752,9 @@ void Interpreter::visitVAArgInst(VAArgInst &I) {
   // Set the Value of this Instruction.
   SetValue(&I, Dest, SF);
 
-  // Move the pointer to the next vararg.
+  // Move the pointer to the next vararg and set new value back.
   ++VAList.UIntPairVal.second;
+  SetValue(V, VAList, SF);
 }
 
 void Interpreter::visitExtractElementInst(ExtractElementInst &I) {
diff --git a/llvm/test/ExecutionEngine/test-interp-variable-arguments.ll b/llvm/test/ExecutionEngine/test-interp-variable-arguments.ll
new file mode 100644
index 0000000000000..11a49f5cdbc55
--- /dev/null
+++ b/llvm/test/ExecutionEngine/test-interp-variable-arguments.ll
@@ -0,0 +1,24 @@
+; RUN: %lli -jit-kind=mcjit -force-interpreter=true %s | FileCheck %s
+; CHECK: result is 6
+
+
+ at .str = private constant [14 x i8] c"result is %d\0A\00", align 1
+
+declare i32 @printf(ptr, ...)
+
+define i32 @sum(i32 %0, ...)  {
+  %2 = alloca ptr, align 8
+  call void @llvm.va_start.p0(ptr nonnull %2)
+  %3 = va_arg ptr %2, i32
+  %4 = add nsw i32 %3, %0
+  %5 = va_arg ptr %2, i32
+  %6 = add nsw i32 %4, %5
+  call void @llvm.va_end.p0(ptr nonnull %2)
+  ret i32 %6
+}
+
+define i32 @main() {
+  %1 = tail call i32 (i32, ...) @sum(i32 noundef 1, i32 noundef 2, i32 noundef 3)
+  %2 = tail call i32 (ptr, ...) @printf(ptr @.str, i32 noundef %1)
+  ret i32 0
+}
\ No newline at end of file



More information about the llvm-commits mailing list