Description
Bugzilla Link | 9010 |
Resolution | FIXED |
Resolved on | Mar 09, 2011 05:16 |
Version | trunk |
OS | Windows XP |
Blocks | llvm/llvm-bugzilla-archive#9100 |
Attachments | .ll and generated .s file |
Reporter | LLVM Bugzilla Contributor |
Extended Description
Tail call optimization is erroneously applied in Windows 64.
As result stack area which contains function parameters is released (RSP is updated) before the call (replaced by jump in tail call optimization). It may cause to wrong function behavior. See attached .s example. Specifically these 3 lines may explain the problem:
lea R8, QWORD PTR [RSP + 32] ; using stack to for parameter storage
...
add RSP, 232 ;; Stack is freed and allocated parameter with it
jmp testcall # TAILCALL
Attached are .ll and .s file generated with latest llc.
The simple inlined fix is solves the problem.
Index: lib/Target/X86/X86ISelLowering.cpp
--- lib/Target/X86/X86ISelLowering.cpp (revision 2609)
+++ lib/Target/X86/X86ISelLowering.cpp (working copy)
@@ -2501,6 +2501,9 @@
SmallVector<CCValAssign, 16> ArgLocs;
CCState CCInfo(CalleeCC, isVarArg, getTargetMachine(),
ArgLocs, *DAG.getContext());
- if (Subtarget->isTargetWin64()) {
-
CCInfo.AllocateStack(32, 8);
- }
CCInfo.AnalyzeCallOperands(Outs, CCAssignFnForNode(CalleeCC));
if (CCInfo.getNextStackOffset()) {
MachineFunction &MF = DAG.getMachineFunction();