[llvm] x86: fix musttail sibcall miscompilation (PR #168956)

Eli Friedman via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 24 15:46:35 PST 2025


================
@@ -2146,6 +2205,74 @@ X86TargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
   unsigned NumBytesToPush = NumBytes;
   unsigned NumBytesToPop = NumBytes;
 
+  SDValue StackPtr;
+  const X86RegisterInfo *RegInfo = Subtarget.getRegisterInfo();
+  int RetAddrSize = 8;
+
+  // If we are doing a tail-call, any byval arguments will be written to stack
+  // space which was used for incoming arguments. If any the values being used
+  // are incoming byval arguments to this function, then they might be
+  // overwritten by the stores of the outgoing arguments. To avoid this, we
+  // need to make a temporary copy of them in local stack space, then copy back
+  // to the argument area.
----------------
efriedma-quic wrote:

There's been continual effort to refactor call lowering to share various bits of code... but it's hard because every calling convention has its own weird quirks.  Not sure how you'd extract out byval lowering, specifically.

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


More information about the llvm-commits mailing list