[llvm] [X86] Fix missing ByValTemporaries update in CopyViaTemp path for musttail calls (PR #190540)

via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 5 10:19:32 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-x86

Author: Zile Xiong (xiongzile)

<details>
<summary>Changes</summary>

This fixes a miscompilation in musttail calls with byval arguments on X86.

In the CopyViaTemp path, a temporary stack object is created and the argument is copied into it. 
However, the temporary is not recorded in ByValTemporaries, 
so the final lowering phase does not emit the copy to the real outgoing argument slot.

As a result, the callee may read incorrect values from the stack.

Fix this by recording the temporary in ByValTemporaries so that the final lowering step correctly copies the argument to the expected stack location.

Reproducer: https://github.com/llvm/llvm-project/issues/190429

---
Full diff: https://github.com/llvm/llvm-project/pull/190540.diff


1 Files Affected:

- (modified) llvm/lib/Target/X86/X86ISelLoweringCall.cpp (+1) 


``````````diff
diff --git a/llvm/lib/Target/X86/X86ISelLoweringCall.cpp b/llvm/lib/Target/X86/X86ISelLoweringCall.cpp
index 37c80e27f4bd2..65d77769b3c45 100644
--- a/llvm/lib/Target/X86/X86ISelLoweringCall.cpp
+++ b/llvm/lib/Target/X86/X86ISelLoweringCall.cpp
@@ -2237,6 +2237,7 @@ X86TargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
         SDValue CopyChain =
             CreateCopyOfByValArgument(Src, Temp, Chain, Flags, DAG, dl);
         ByValCopyChains.push_back(CopyChain);
+        ByValTemporaries[ArgIdx] = Temp;
       }
     }
     if (!ByValCopyChains.empty())

``````````

</details>


https://github.com/llvm/llvm-project/pull/190540


More information about the llvm-commits mailing list