Blame SOURCES/gcc5-ppc32-retaddr.patch

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