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