Skip to content

Commit

Permalink
[TargetLowering] Correctly track NumFixedArgs field of CallLoweringInfo
Browse files Browse the repository at this point in the history
The NumFixedArgs field of CallLoweringInfo is used by
TargetLowering::LowerCallTo to determine whether a given argument is passed
using the vararg calling convention or not (specifically, to set IsFixed for
each ISD::OutputArg).

Firstly, CallLoweringInfo::setLibCallee and CallLoweringInfo::setCallee both
incorrectly set NumFixedArgs based on the _previous_ args list. Secondly,
TargetLowering::LowerCallTo failed to increment NumFixedArgs when modifying
the argument list so a pointer is passed for the return value.

If your backend uses the IsFixed property or directly accesses NumFixedArgs, 
it is _possible_ this change could result in codegen changes (although the 
previous behaviour would have been incorrect). No such cases have been
identified during code review for any in-tree architecture.

Differential Revision: https://reviews.llvm.org/D37898

llvm-svn: 315457
asb committed Oct 11, 2017
1 parent 8acb2e3 commit 4d275f0
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions llvm/include/llvm/Target/TargetLowering.h
Original file line number Diff line number Diff line change
@@ -2907,7 +2907,7 @@ class TargetLowering : public TargetLoweringBase {
RetTy = ResultType;
Callee = Target;
CallConv = CC;
NumFixedArgs = Args.size();
NumFixedArgs = ArgsList.size();
Args = std::move(ArgsList);

DAG.getTargetLoweringInfo().markLibCallAttributes(
@@ -2920,7 +2920,7 @@ class TargetLowering : public TargetLoweringBase {
RetTy = ResultType;
Callee = Target;
CallConv = CC;
NumFixedArgs = Args.size();
NumFixedArgs = ArgsList.size();
Args = std::move(ArgsList);
return *this;
}
1 change: 1 addition & 0 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Original file line number Diff line number Diff line change
@@ -8077,6 +8077,7 @@ TargetLowering::LowerCallTo(TargetLowering::CallLoweringInfo &CLI) const {
Entry.IsSwiftError = false;
Entry.Alignment = Align;
CLI.getArgs().insert(CLI.getArgs().begin(), Entry);
CLI.NumFixedArgs += 1;
CLI.RetTy = Type::getVoidTy(CLI.RetTy->getContext());

// sret demotion isn't compatible with tail-calls, since the sret argument

0 comments on commit 4d275f0

Please sign in to comment.