Blame SOURCES/gcc6-ppc32-retaddr.patch

7d9f3d
2005-11-28  Jakub Jelinek  <jakub@redhat.com>
7d9f3d
7d9f3d
	* config/rs6000/rs6000.c (rs6000_return_addr): If COUNT == 0,
7d9f3d
	read word RETURN_ADDRESS_OFFSET bytes above arg_pointer_rtx
7d9f3d
	instead of doing an extran indirection from frame_pointer_rtx.
7d9f3d
7d9f3d
	* gcc.dg/20051128-1.c: New test.
7d9f3d
7d9f3d
--- gcc/config/rs6000/rs6000.c.jj	2005-11-26 14:38:01.000000000 +0100
7d9f3d
+++ gcc/config/rs6000/rs6000.c	2005-11-28 20:32:18.000000000 +0100
7d9f3d
@@ -20970,18 +20970,22 @@ rs6000_return_addr (int count, rtx frame
7d9f3d
   if (count != 0
7d9f3d
       || ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_DARWIN) && flag_pic))
7d9f3d
     {
7d9f3d
+      rtx x;
7d9f3d
       cfun->machine->ra_needs_full_frame = 1;
7d9f3d
 
7d9f3d
-      return
7d9f3d
-	gen_rtx_MEM
7d9f3d
-	  (Pmode,
7d9f3d
-	   memory_address
7d9f3d
-	   (Pmode,
7d9f3d
-	    plus_constant (Pmode,
7d9f3d
-			   copy_to_reg
7d9f3d
-			   (gen_rtx_MEM (Pmode,
7d9f3d
-					 memory_address (Pmode, frame))),
7d9f3d
-			   RETURN_ADDRESS_OFFSET)));
7d9f3d
+      if (count == 0)
7d9f3d
+	{
7d9f3d
+	  gcc_assert (frame == frame_pointer_rtx);
7d9f3d
+	  x = arg_pointer_rtx;
7d9f3d
+	}
7d9f3d
+      else
7d9f3d
+	{
7d9f3d
+	  x = memory_address (Pmode, frame);
7d9f3d
+	  x = copy_to_reg (gen_rtx_MEM (Pmode, x));
7d9f3d
+	}
7d9f3d
+
7d9f3d
+      x = plus_constant (Pmode, x, RETURN_ADDRESS_OFFSET);
7d9f3d
+      return gen_rtx_MEM (Pmode, memory_address (Pmode, x));
7d9f3d
     }
7d9f3d
 
7d9f3d
   cfun->machine->ra_need_lr = 1;
7d9f3d
--- gcc/testsuite/gcc.dg/20051128-1.c.jj	2005-10-10 11:21:41.096999000 +0200
7d9f3d
+++ gcc/testsuite/gcc.dg/20051128-1.c	2005-11-28 12:30:57.000000000 +0100
7d9f3d
@@ -0,0 +1,41 @@
7d9f3d
+/* { dg-do run } */
7d9f3d
+/* { dg-options "-O2 -fpic" } */
7d9f3d
+
7d9f3d
+extern void exit (int);
7d9f3d
+extern void abort (void);
7d9f3d
+
7d9f3d
+int b;
7d9f3d
+
7d9f3d
+struct A
7d9f3d
+{
7d9f3d
+  void *pad[147];
7d9f3d
+  void *ra, *h;
7d9f3d
+  long o;
7d9f3d
+};
7d9f3d
+
7d9f3d
+void
7d9f3d
+__attribute__((noinline))
7d9f3d
+foo (struct A *a, void *x)
7d9f3d
+{
7d9f3d
+  __builtin_memset (a, 0, sizeof (a));
7d9f3d
+  if (!b)
7d9f3d
+    exit (0);
7d9f3d
+}
7d9f3d
+
7d9f3d
+void
7d9f3d
+__attribute__((noinline))
7d9f3d
+bar (void)
7d9f3d
+{
7d9f3d
+  struct A a;
7d9f3d
+
7d9f3d
+  __builtin_unwind_init ();
7d9f3d
+  foo (&a, __builtin_return_address (0));
7d9f3d
+}
7d9f3d
+
7d9f3d
+int
7d9f3d
+main (void)
7d9f3d
+{
7d9f3d
+  bar ();
7d9f3d
+  abort ();
7d9f3d
+  return 0;
7d9f3d
+}