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

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 14 10:14:00 PST 2026


================
@@ -2098,15 +2142,18 @@ X86TargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
       isTailCall = false;
   }
 
-  if (isTailCall && !IsMustTail) {
+  if (isTailCall) {
     // Check if it's really possible to do a tail call.
-    isTailCall = IsEligibleForTailCallOptimization(CLI, CCInfo, ArgLocs,
-                                                   IsCalleePopSRet);
+    IsSibcall = IsEligibleForTailCallOptimization(CLI, CCInfo, ArgLocs,
+                                                  IsCalleePopSRet);
 
-    // Sibcalls are automatically detected tailcalls which do not require
-    // ABI changes.
-    if (!IsGuaranteeTCO && isTailCall)
-      IsSibcall = true;
+    if (!IsMustTail) {
+      isTailCall = IsSibcall;
+
+      // Sibcalls are automatically detected tailcalls which do not require
+      // ABI changes.
+      IsSibcall = IsSibcall && !ShouldGuaranteeTCO;
+    }
----------------
rnk wrote:

```suggestion
    // Force musttail calls to be tail calls, even it requires passing arguments in memory.
    isTailCall = IsSibcall || IsMustTail;
```

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


More information about the llvm-commits mailing list