Blame SOURCES/gcc6-ppc32-retaddr.patch

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