Blame SOURCES/gcc6-ppc32-retaddr.patch

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