Blame SOURCES/gcc7-ppc32-retaddr.patch

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