Blame SOURCES/gcc5-ppc32-retaddr.patch

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