Blame SOURCES/gcc48-ppc32-retaddr.patch

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