From 00edcfbe01b2bd34ff997984a6e73bcc184c727c Mon Sep 17 00:00:00 2001
From: Yufeng Zhang <yufeng.zhang@arm.com>
Date: Tue, 23 Jul 2013 12:29:51 +0000
Subject: [PATCH] [AArch64, ILP32] 5/6 Pad pointer-typed stack argument
 downward in ILP32.

gcc/

	* config/aarch64/aarch64.c (aarch64_pad_arg_upward): In big-endian,
	pad pointer-typed argument downward.

gcc/testsuite/

	* gcc.target/aarch64/test-ptr-arg-on-stack-1.c: New test.

From-SVN: r201168
---
 gcc/ChangeLog                                 |  5 +++
 gcc/config/aarch64/aarch64.c                  |  5 ++-
 gcc/testsuite/ChangeLog                       |  4 ++
 .../aarch64/test-ptr-arg-on-stack-1.c         | 39 +++++++++++++++++++
 4 files changed, 51 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/aarch64/test-ptr-arg-on-stack-1.c

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index c8d6a1bfe7ac..df9bb9454dd9 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2013-07-23  Yufeng Zhang  <yufeng.zhang@arm.com>
+
+	* config/aarch64/aarch64.c (aarch64_pad_arg_upward): In big-endian,
+	pad pointer-typed argument downward.
+
 2013-07-23  Yufeng Zhang  <yufeng.zhang@arm.com>
 
 	* config/aarch64/aarch64.h (TARGET_CPU_CPP_BUILTINS): Define _ILP32
diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index da041f8e3f89..73e8657b828e 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -1612,11 +1612,12 @@ aarch64_pad_arg_upward (enum machine_mode mode, const_tree type)
   if (!BYTES_BIG_ENDIAN)
     return true;
 
-  /* Otherwise, integral types and floating point types are padded downward:
+  /* Otherwise, integral, floating-point and pointer types are padded downward:
      the least significant byte of a stack argument is passed at the highest
      byte address of the stack slot.  */
   if (type
-      ? (INTEGRAL_TYPE_P (type) || SCALAR_FLOAT_TYPE_P (type))
+      ? (INTEGRAL_TYPE_P (type) || SCALAR_FLOAT_TYPE_P (type)
+	 || POINTER_TYPE_P (type))
       : (SCALAR_INT_MODE_P (mode) || SCALAR_FLOAT_MODE_P (mode)))
     return false;
 
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index e715ca564fdf..7df09a07b4b6 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2013-07-23  Yufeng Zhang  <yufeng.zhang@arm.com>
+
+	* gcc.target/aarch64/test-ptr-arg-on-stack-1.c: New test.
+
 2013-07-23  Yufeng Zhang  <yufeng.zhang@arm.com>
 
 	* gcc.dg/20020219-1.c: Skip the test on aarch64*-*-* in ilp32.
diff --git a/gcc/testsuite/gcc.target/aarch64/test-ptr-arg-on-stack-1.c b/gcc/testsuite/gcc.target/aarch64/test-ptr-arg-on-stack-1.c
new file mode 100644
index 000000000000..bb68e0a568ce
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/test-ptr-arg-on-stack-1.c
@@ -0,0 +1,39 @@
+/* { dg-do run } */
+/* { dg-options "-O2 -fno-inline" } */
+
+/* Test pass-by-reference and pointer-typed argument passing on stack.
+   This test shall pass on any of the following four combinitions:
+    {big-endian, little-endian} {LP64, ILP32}.  */
+
+struct s5
+{
+  double a;
+  double b;
+  double c;
+  double d;
+  double e;
+} gS = {1.0, 2.0, 3.0, 4.0, 5.0};
+
+double  __attribute__ ((noinline))
+foo (struct s5 p1, struct s5 p2, struct s5 p3, struct s5 p4,
+     struct s5 p5, struct s5 p6, struct s5 p7, struct s5 p8,
+     struct s5 p9)
+{
+  asm ("");
+  return p9.c;
+}
+
+void abort (void);
+int printf (const char *, ...);
+
+int main (void)
+{
+  printf ("Here we print out some values and more importantly hope that"
+	  " the stack is getting a bit dirty for the bug to manifest itself"
+	  "\n\t%f, %f, %f, %f, %f\n", gS.a, gS.b, gS.c, gS.d, gS.e);
+
+  if (foo (gS, gS, gS, gS, gS, gS, gS, gS, gS) != 3.0)
+    abort ();
+
+  return 0;
+}
-- 
GitLab