]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: [multiple changes]
authorRichard Guenther <rguenther@suse.de>
Tue, 20 Apr 2010 14:24:39 +0000 (14:24 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 20 Apr 2010 14:24:39 +0000 (14:24 +0000)
2010-04-20  Richard Guenther  <rguenther@suse.de>

Backport from mainline:
2010-03-01  Richard Guenther  <rguenther@suse.de>

PR tree-optimization/43220
* tree-ssa-ccp.c (optimize_stack_restore): Do not optimize
BUILT_IN_STACK_{SAVE,RESTORE} around alloca.

* gcc.c-torture/execute/pr43220.c: New testcase.

2008-12-03  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/38360
* tree-ssa-ccp.c (ccp_fold_builtin): Bail out if the builtin doesn't
have the right number of arguments.

* gcc.c-torture/compile/pr38360.c: New test.

From-SVN: r158561

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/compile/pr38360.c [new file with mode: 0644]
gcc/testsuite/gcc.c-torture/execute/pr43220.c [new file with mode: 0644]
gcc/tree-ssa-ccp.c

index 177aba29feaec2510845bd4a1c367fd45cdba820..84cd0c48519d2512a3ce570c4330a98af8122306 100644 (file)
@@ -1,3 +1,18 @@
+2010-04-20  Richard Guenther  <rguenther@suse.de>
+
+       Backport from mainline:
+       2010-03-01  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/43220
+       * tree-ssa-ccp.c (optimize_stack_restore): Do not optimize
+       BUILT_IN_STACK_{SAVE,RESTORE} around alloca.
+
+       2008-12-03  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/38360
+       * tree-ssa-ccp.c (ccp_fold_builtin): Bail out if the builtin doesn't
+       have the right number of arguments.
+
 2010-04-20  Richard Guenther  <rguenther@suse.de>
 
        Backport from mainline
index 8002421e21e8776d19a4cf2436e8d5bc55572283..6098a31346825d313b5a7eae471d024b9f6c3b00 100644 (file)
@@ -1,3 +1,16 @@
+2010-04-20  Richard Guenther  <rguenther@suse.de>
+
+       Backport from mainline:
+       2010-03-01  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/43220
+       * gcc.c-torture/execute/pr43220.c: New testcase.
+
+       2008-12-03  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/38360
+       * gcc.c-torture/compile/pr38360.c: New test.
+
 2010-04-20  Richard Guenther  <rguenther@suse.de>
 
        Backport from mainline
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr38360.c b/gcc/testsuite/gcc.c-torture/compile/pr38360.c
new file mode 100644 (file)
index 0000000..463218d
--- /dev/null
@@ -0,0 +1,9 @@
+/* PR middle-end/38360 */
+
+int
+main ()
+{
+  fputs ("");
+  fputs_unlocked ("");
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr43220.c b/gcc/testsuite/gcc.c-torture/execute/pr43220.c
new file mode 100644 (file)
index 0000000..4709f17
--- /dev/null
@@ -0,0 +1,28 @@
+void *volatile p;
+
+int
+main (void)
+{
+  int n = 0;
+lab:;
+    {
+      int x[n % 1000 + 1];
+      x[0] = 1;
+      x[n % 1000] = 2;
+      p = x;
+      n++;
+    }
+
+    {
+      int x[n % 1000 + 1];
+      x[0] = 1;
+      x[n % 1000] = 2;
+      p = x;
+      n++;
+    }
+
+  if (n < 1000000)
+    goto lab;
+
+  return 0;
+}
index 41eed535d50ef8c06585b2c3af9ab058a2f01257..bd29c40e9e7d258c4258a35cf8b527f403d45ae2 100644 (file)
@@ -588,7 +588,7 @@ likely_value (tree stmt)
     }
   else if (TREE_CODE (stmt) == CALL_EXPR)
     {
-      unsigned i;
+      int i;
       for (i = 0; i < call_expr_nargs (stmt); ++i)
        if (is_gimple_min_invariant (CALL_EXPR_ARG (stmt, i)))
          has_constant_operand = true;
@@ -2478,7 +2478,7 @@ ccp_fold_builtin (tree stmt, tree fn)
   switch (DECL_FUNCTION_CODE (callee))
     {
     case BUILT_IN_STRLEN:
-      if (val[0])
+      if (val[0] && nargs == 1)
        {
          tree new_val = fold_convert (TREE_TYPE (fn), val[0]);
 
@@ -2509,24 +2509,26 @@ ccp_fold_builtin (tree stmt, tree fn)
       break;
 
     case BUILT_IN_FPUTS:
-      result = fold_builtin_fputs (CALL_EXPR_ARG (fn, 0),
-                                  CALL_EXPR_ARG (fn, 1),
-                                  TREE_CODE (stmt) != GIMPLE_MODIFY_STMT, 0,
-                                  val[0]);
+      if (nargs == 2)
+       result = fold_builtin_fputs (CALL_EXPR_ARG (fn, 0),
+                                    CALL_EXPR_ARG (fn, 1),
+                                    TREE_CODE (stmt) != GIMPLE_MODIFY_STMT, 0,
+                                    val[0]);
       break;
 
     case BUILT_IN_FPUTS_UNLOCKED:
-      result = fold_builtin_fputs (CALL_EXPR_ARG (fn, 0),
-                                  CALL_EXPR_ARG (fn, 1),
-                                  TREE_CODE (stmt) != GIMPLE_MODIFY_STMT, 1,
-                                  val[0]);
+      if (nargs == 2)
+       result = fold_builtin_fputs (CALL_EXPR_ARG (fn, 0),
+                                    CALL_EXPR_ARG (fn, 1),
+                                    TREE_CODE (stmt) != GIMPLE_MODIFY_STMT, 1,
+                                    val[0]);
       break;
 
     case BUILT_IN_MEMCPY_CHK:
     case BUILT_IN_MEMPCPY_CHK:
     case BUILT_IN_MEMMOVE_CHK:
     case BUILT_IN_MEMSET_CHK:
-      if (val[2] && is_gimple_val (val[2]))
+      if (val[2] && is_gimple_val (val[2]) && nargs == 4)
        result = fold_builtin_memory_chk (callee,
                                          CALL_EXPR_ARG (fn, 0),
                                          CALL_EXPR_ARG (fn, 1),
@@ -2538,7 +2540,7 @@ ccp_fold_builtin (tree stmt, tree fn)
 
     case BUILT_IN_STRCPY_CHK:
     case BUILT_IN_STPCPY_CHK:
-      if (val[1] && is_gimple_val (val[1]))
+      if (val[1] && is_gimple_val (val[1]) && nargs == 3)
        result = fold_builtin_stxcpy_chk (callee,
                                          CALL_EXPR_ARG (fn, 0),
                                          CALL_EXPR_ARG (fn, 1),
@@ -2548,7 +2550,7 @@ ccp_fold_builtin (tree stmt, tree fn)
       break;
 
     case BUILT_IN_STRNCPY_CHK:
-      if (val[2] && is_gimple_val (val[2]))
+      if (val[2] && is_gimple_val (val[2]) && nargs == 4)
        result = fold_builtin_strncpy_chk (CALL_EXPR_ARG (fn, 0),
                                           CALL_EXPR_ARG (fn, 1),
                                           CALL_EXPR_ARG (fn, 2),
@@ -2734,7 +2736,10 @@ optimize_stack_restore (basic_block bb, tree call, block_stmt_iterator i)
        continue;
 
       callee = get_callee_fndecl (call);
-      if (!callee || DECL_BUILT_IN_CLASS (callee) != BUILT_IN_NORMAL)
+      if (!callee
+         || DECL_BUILT_IN_CLASS (callee) != BUILT_IN_NORMAL
+         /* All regular builtins are ok, just obviously not alloca.  */
+         || DECL_FUNCTION_CODE (callee) == BUILT_IN_ALLOCA)
        return NULL_TREE;
 
       if (DECL_FUNCTION_CODE (callee) == BUILT_IN_STACK_RESTORE)