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

Folkert de Vries via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 5 13:35:14 PST 2025


================

----------------
folkertdev wrote:

Hmm, the cause is that the call is now marked as a sibcall. It properly qualifies to be one I think?

```diff
--- <unnamed>
+++ <unnamed>
@@ -17,8 +17,6 @@
 	callq	_foo
 	movq	%r14, (%rax)
 	movl	40(%rsp), %edx
-	movq	24(%rsp), %rcx
-	movq	%rcx, 40(%rsp)
 	movq	%rax, %r14
 	movq	%r13, %rdi
 	movq	%r15, %rsi
@@ -26,7 +24,6 @@
 	addq	$8, %rsp
 	popq	%rbx
 	popq	%r15
-	addq	$16, %rsp
 	jmp	_tc_fn                          ## TAILCALL
 	.cfi_endproc
                                         ## -- End function
```

so previously this moved the value at `rsp + 24` to `rsp + 40`, but then shifted the stack pointer by 16. Now we leave it at `rsp + 40` but don't move the stack pointer. I think that cancels out?

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


More information about the llvm-commits mailing list