diff options
author | Lion Yang <lion@aosc.io> | 2018-09-14 21:26:05 +0000 |
---|---|---|
committer | Lion Yang <lion@aosc.io> | 2018-09-14 21:26:05 +0000 |
commit | c68f78d5d86e4d3a2e69c5f1ed8d6a17f3e16233 (patch) | |
tree | 51ef277c69b7f86c63dcd8e684f8a64fd4eba78e /llvm/lib/Target/PowerPC/PPCISelLowering.cpp | |
parent | a3937b231db67c33b4f06e1a5a90a1168487bf21 (diff) | |
download | bcm5719-llvm-c68f78d5d86e4d3a2e69c5f1ed8d6a17f3e16233.tar.gz bcm5719-llvm-c68f78d5d86e4d3a2e69c5f1ed8d6a17f3e16233.zip |
[PowerPC] Fix the calling convention for i1 arguments on PPC32
Summary:
Integer types smaller than i32 must be extended to i32 by default.
The feature "crbits" introduced at r202451 handles i1 as a special case,
but it did not extend properly.
The caller was, therefore, passing i1 stack arguments by writing 0/1 to
the first byte of the 4-byte stack object and callee was
reading the first byte for the value.
"crbits" is enabled if the optimization level is greater than 1,
which is very common in "release builds".
Such discrepancies with ABI specification also introduces
potential incompatibility with programs or libraries
built with other compilers e.g. GCC.
Fixes PR38661
Reviewers: hfinkel, cuviper
Subscribers: sylvestre.ledru, glaubitz, nagisa, nemanjai, kbarton, llvm-commits
Differential Revision: https://reviews.llvm.org/D51108
llvm-svn: 342288
Diffstat (limited to 'llvm/lib/Target/PowerPC/PPCISelLowering.cpp')
-rw-r--r-- | llvm/lib/Target/PowerPC/PPCISelLowering.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp index 48f093cc5ee..5dee7b12a21 100644 --- a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp +++ b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp @@ -3511,9 +3511,14 @@ SDValue PPCTargetLowering::LowerFormalArguments_32SVR4( // Argument stored in memory. assert(VA.isMemLoc()); + // Get the extended size of the argument type in stack unsigned ArgSize = VA.getLocVT().getStoreSize(); - int FI = MFI.CreateFixedObject(ArgSize, VA.getLocMemOffset(), - isImmutable); + // Get the actual size of the argument type + unsigned ObjSize = VA.getValVT().getStoreSize(); + unsigned ArgOffset = VA.getLocMemOffset(); + // Stack objects in PPC32 are right justified. + ArgOffset += ArgSize - ObjSize; + int FI = MFI.CreateFixedObject(ArgSize, ArgOffset, isImmutable); // Create load nodes to retrieve arguments from the stack. SDValue FIN = DAG.getFrameIndex(FI, PtrVT); @@ -5468,10 +5473,15 @@ SDValue PPCTargetLowering::LowerCall_32SVR4( Arg = PtrOff; } - if (VA.isRegLoc()) { - if (Arg.getValueType() == MVT::i1) - Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::i32, Arg); + // When useCRBits() is true, there can be i1 arguments. + // It is because getRegisterType(MVT::i1) => MVT::i1, + // and for other integer types getRegisterType() => MVT::i32. + // Extend i1 and ensure callee will get i32. + if (Arg.getValueType() == MVT::i1) + Arg = DAG.getNode(Flags.isSExt() ? ISD::SIGN_EXTEND : ISD::ZERO_EXTEND, + dl, MVT::i32, Arg); + if (VA.isRegLoc()) { seenFloatArg |= VA.getLocVT().isFloatingPoint(); // Put argument in a physical register. RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg)); |