D51108
authorLLVM Packaging Team <pkg-llvm-team@lists.alioth.debian.org>
Sun, 26 Aug 2018 12:00:14 +0000 (13:00 +0100)
committerSylvestre Ledru <sylvestre@debian.org>
Sun, 26 Aug 2018 12:00:14 +0000 (13:00 +0100)
===================================================================

Gbp-Pq: Name D51108.diff

lib/Target/PowerPC/PPCISelLowering.cpp
test/CodeGen/PowerPC/ppc32-i1-stack-arguments-abi-bug.ll [new file with mode: 0644]

index 26e9f13f9ff418c295df29c25212e3613bd98ca5..ac1062dfa91545ddc5fb9ff8a009ea7c8b11de02 100644 (file)
@@ -3351,9 +3351,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);
@@ -5303,10 +5308,11 @@ SDValue PPCTargetLowering::LowerCall_32SVR4(
       Arg = PtrOff;
     }
 
-    if (VA.isRegLoc()) {
-      if (Arg.getValueType() == MVT::i1)
-        Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::i32, Arg);
+    // Ensure callee will get either 0x00000001 or 0x00000000.
+    if (Arg.getValueType() == MVT::i1)
+      Arg = DAG.getNode(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));
diff --git a/test/CodeGen/PowerPC/ppc32-i1-stack-arguments-abi-bug.ll b/test/CodeGen/PowerPC/ppc32-i1-stack-arguments-abi-bug.ll
new file mode 100644 (file)
index 0000000..ccdde45
--- /dev/null
@@ -0,0 +1,24 @@
+; RUN: llc -verify-machineinstrs < %s -mcpu=ppc32 -mattr=+crbits | FileCheck %s
+target triple = "powerpc-unknown-linux-gnu"
+
+define zeroext i1 @check_callee(
+  i1 zeroext, i1 zeroext, i1 zeroext, i1 zeroext,
+  i1 zeroext, i1 zeroext, i1 zeroext, i1 zeroext,
+  i1 zeroext %s1
+) {
+  call void @check_caller(
+    i1 zeroext true, i1 zeroext true, i1 zeroext true, i1 zeroext true,
+    i1 zeroext true, i1 zeroext true, i1 zeroext true, i1 zeroext true,
+    i1 zeroext %s1)
+  ret i1 true
+}
+
+; CHECK-LABEL: @check_callee
+; CHECK: lbz {{[0-9]+}}, 27(1)
+; CHECK: stw {{[0-9]+}}, 8(1)
+
+declare void @check_caller(
+  i1 zeroext, i1 zeroext, i1 zeroext, i1 zeroext,
+  i1 zeroext, i1 zeroext, i1 zeroext, i1 zeroext,
+  i1 zeroext
+)