Blame SOURCES/gcc44-ppc32-retaddr.patch

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