[X86] Fix missing ByValTemporaries update in CopyViaTemp path for musttail calls#190540
Conversation
|
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
|
@llvm/pr-subscribers-backend-x86 Author: Zile Xiong (xiongzile) ChangesThis fixes a miscompilation in musttail calls with byval arguments on X86. In the CopyViaTemp path, a temporary stack object is created and the argument is copied into it. As a result, the callee may read incorrect values from the stack. Fix this by recording the temporary in ByValTemporaries so that the final lowering step correctly copies the argument to the expected stack location. Reproducer: #190429 Full diff: https://github.com/llvm/llvm-project/pull/190540.diff 1 Files Affected:
diff --git a/llvm/lib/Target/X86/X86ISelLoweringCall.cpp b/llvm/lib/Target/X86/X86ISelLoweringCall.cpp
index 37c80e27f4bd2..65d77769b3c45 100644
--- a/llvm/lib/Target/X86/X86ISelLoweringCall.cpp
+++ b/llvm/lib/Target/X86/X86ISelLoweringCall.cpp
@@ -2237,6 +2237,7 @@ X86TargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
SDValue CopyChain =
CreateCopyOfByValArgument(Src, Temp, Chain, Flags, DAG, dl);
ByValCopyChains.push_back(CopyChain);
+ ByValTemporaries[ArgIdx] = Temp;
}
}
if (!ByValCopyChains.empty())
|
b0f1215 to
03109e8
Compare
|
Hi @RKSimon , could you please take a look at this PR when you have a moment? This fixes a miscompilation in musttail calls with byval arguments on X86. All checks are passing. Thanks! |
efriedma-quic
left a comment
There was a problem hiding this comment.
CC @folkertdev @rnk
| @@ -0,0 +1,90 @@ | |||
| ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6 | |||
There was a problem hiding this comment.
Does this new test cover any constructs that are significantly different from the existing test coverage in musttail-struct.ll?
There was a problem hiding this comment.
You're right — the existing test already covers this case after the update.
I've removed the additional test in the latest commit. Thanks!
…ttail calls The CopyViaTemp path creates a temporary for byval arguments but does not record it in ByValTemporaries. As a result, the final lowering phase does not emit the copy to the outgoing argument slot, leading to incorrect values being observed by the callee. Record the temporary in ByValTemporaries to ensure correct lowering. Fixes: llvm#190429
| SDValue CopyChain = | ||
| CreateCopyOfByValArgument(Src, Temp, Chain, Flags, DAG, dl); | ||
| ByValCopyChains.push_back(CopyChain); | ||
| ByValTemporaries[ArgIdx] = Temp; |
There was a problem hiding this comment.
The fix here is consistent with the arm implementation that the x86 implementation is based on
llvm-project/llvm/lib/Target/ARM/ARMISelLowering.cpp
Lines 2193 to 2201 in e7ac60c
That line must have gotten lost at some point...
efriedma-quic
left a comment
There was a problem hiding this comment.
LGTM
Let's cherry-pick this to 22.
It would also be nice if anyone has suggestions for better testing, to make sure there aren't any further issues...
I'll let this stew in trunk for a few days and then get it cherry picked (probably next week during EuroLLVM) |
|
@xiongzile Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
|
/cherry-pick abd502a |
|
/pull-request #192507 |
…ttail calls (llvm#190540) This fixes a miscompilation in musttail calls with byval arguments on X86. In the CopyViaTemp path, a temporary stack object is created and the argument is copied into it. However, the temporary is not recorded in ByValTemporaries, so the final lowering phase does not emit the copy to the real outgoing argument slot. As a result, the callee may read incorrect values from the stack. Fix this by recording the temporary in ByValTemporaries so that the final lowering step correctly copies the argument to the expected stack location. Reproducer: llvm#190429 (cherry picked from commit abd502a)
…ttail calls (llvm#190540) This fixes a miscompilation in musttail calls with byval arguments on X86. In the CopyViaTemp path, a temporary stack object is created and the argument is copied into it. However, the temporary is not recorded in ByValTemporaries, so the final lowering phase does not emit the copy to the real outgoing argument slot. As a result, the callee may read incorrect values from the stack. Fix this by recording the temporary in ByValTemporaries so that the final lowering step correctly copies the argument to the expected stack location. Reproducer: llvm#190429
…ttail calls (llvm#190540) This fixes a miscompilation in musttail calls with byval arguments on X86. In the CopyViaTemp path, a temporary stack object is created and the argument is copied into it. However, the temporary is not recorded in ByValTemporaries, so the final lowering phase does not emit the copy to the real outgoing argument slot. As a result, the callee may read incorrect values from the stack. Fix this by recording the temporary in ByValTemporaries so that the final lowering step correctly copies the argument to the expected stack location. Reproducer: llvm#190429
…ttail calls (llvm#190540) This fixes a miscompilation in musttail calls with byval arguments on X86. In the CopyViaTemp path, a temporary stack object is created and the argument is copied into it. However, the temporary is not recorded in ByValTemporaries, so the final lowering phase does not emit the copy to the real outgoing argument slot. As a result, the callee may read incorrect values from the stack. Fix this by recording the temporary in ByValTemporaries so that the final lowering step correctly copies the argument to the expected stack location. Reproducer: llvm#190429
This fixes a miscompilation in musttail calls with byval arguments on X86.
In the CopyViaTemp path, a temporary stack object is created and the argument is copied into it.
However, the temporary is not recorded in ByValTemporaries,
so the final lowering phase does not emit the copy to the real outgoing argument slot.
As a result, the callee may read incorrect values from the stack.
Fix this by recording the temporary in ByValTemporaries so that the final lowering step correctly copies the argument to the expected stack location.
Reproducer: #190429