OSDN Git Service

Backported from mainline
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 7 May 2014 16:00:33 +0000 (16:00 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 7 May 2014 16:00:33 +0000 (16:00 +0000)
2013-08-23  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/58209
* tree-tailcall.c (find_tail_calls): Give up for pointer result types
if m or a is non-NULL.

* gcc.c-torture/execute/pr58209.c: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_7-branch@210170 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/pr58209.c [new file with mode: 0644]
gcc/tree-tailcall.c

index f2b7b9e..8838f62 100644 (file)
@@ -1,6 +1,12 @@
 2014-05-07  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
 2014-05-07  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2013-08-23  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/58209
+       * tree-tailcall.c (find_tail_calls): Give up for pointer result types
+       if m or a is non-NULL.
+
        2013-07-03  Jakub Jelinek  <jakub@redhat.com>
 
        PR target/57777
        2013-07-03  Jakub Jelinek  <jakub@redhat.com>
 
        PR target/57777
index 385241c..e5bd7ce 100644 (file)
@@ -1,6 +1,11 @@
 2014-05-07  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
 2014-05-07  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2013-08-23  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/58209
+       * gcc.c-torture/execute/pr58209.c: New test.
+
        2013-07-03  Jakub Jelinek  <jakub@redhat.com>
 
        PR target/57777
        2013-07-03  Jakub Jelinek  <jakub@redhat.com>
 
        PR target/57777
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr58209.c b/gcc/testsuite/gcc.c-torture/execute/pr58209.c
new file mode 100644 (file)
index 0000000..78743bf
--- /dev/null
@@ -0,0 +1,32 @@
+/* PR tree-optimization/58209 */
+
+extern void abort (void);
+typedef __INTPTR_TYPE__ T;
+T buf[1024];
+
+T *
+foo (T n)
+{
+  if (n == 0)
+    return (T *) buf;
+  T s = (T) foo (n - 1);
+  return (T *) (s + sizeof (T));
+}
+
+T *
+bar (T n)
+{
+  if (n == 0)
+    return buf;
+  return foo (n - 1) + 1;
+}
+
+int
+main ()
+{
+  int i;
+  for (i = 0; i < 27; i++)
+    if (foo (i) != buf + i || bar (i) != buf + i)
+      abort ();
+  return 0;
+}
index f07297e..e538700 100644 (file)
@@ -576,6 +576,11 @@ find_tail_calls (basic_block bb, struct tailcall **ret)
   if (!tail_recursion && (m || a))
     return;
 
   if (!tail_recursion && (m || a))
     return;
 
+  /* For pointers don't allow additions or multiplications.  */
+  if ((m || a)
+      && POINTER_TYPE_P (TREE_TYPE (DECL_RESULT (current_function_decl))))
+    return;
+
   nw = XNEW (struct tailcall);
 
   nw->call_gsi = gsi;
   nw = XNEW (struct tailcall);
 
   nw->call_gsi = gsi;