Blame SOURCES/gcc7-ppc32-retaddr.patch

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