Blame SOURCES/gcc44-ppc32-retaddr.patch

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