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

Folkert de Vries via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 25 04:20:49 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.
----------------
folkertdev wrote:

>From `rustc`'s perspective it is unfortunate that tail call support is so inconsistent between backends, so I'm trying to see if there is some more structural way to fix that.

But yeah I can totally see how it would get messy. I guess we'll see how this PR works out and if there is anything that seems shareable.

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


More information about the llvm-commits mailing list