re PR middle-end/38360 (ICE in gimple_op, at gimple.h:1636)
authorJakub Jelinek <jakub@redhat.com>
Wed, 3 Dec 2008 16:57:44 +0000 (17:57 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 3 Dec 2008 16:57:44 +0000 (17:57 +0100)
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: r142399

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

index 1f1c031..29104d8 100644 (file)
@@ -1,3 +1,9 @@
+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.
+
 2008-12-03  Richard Guenther  <rguenther@suse.de>
 
        PR middle-end/36326
index c9364f8..e62b980 100644 (file)
@@ -1,3 +1,8 @@
+2008-12-03  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/38360
+       * gcc.c-torture/compile/pr38360.c: New test.
+
 2008-12-03  Richard Guenther  <rguenther@suse.de>
 
        PR middle-end/36326
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;
+}
index a7d5be3..82933f8 100644 (file)
@@ -2517,6 +2517,9 @@ ccp_fold_builtin (gimple stmt)
       return NULL_TREE;
     }
 
+  if (arg_idx >= nargs)
+    return NULL_TREE;
+
   /* Try to use the dataflow information gathered by the CCP process.  */
   visited = BITMAP_ALLOC (NULL);
   bitmap_clear (visited);
@@ -2532,7 +2535,7 @@ ccp_fold_builtin (gimple stmt)
   switch (DECL_FUNCTION_CODE (callee))
     {
     case BUILT_IN_STRLEN:
-      if (val[0])
+      if (val[0] && nargs == 1)
        {
          tree new_val =
               fold_convert (TREE_TYPE (gimple_call_lhs (stmt)), val[0]);
@@ -2564,22 +2567,24 @@ ccp_fold_builtin (gimple stmt)
       break;
 
     case BUILT_IN_FPUTS:
-      result = fold_builtin_fputs (gimple_call_arg (stmt, 0),
-                                   gimple_call_arg (stmt, 1),
-                                  ignore, false, val[0]);
+      if (nargs == 2)
+       result = fold_builtin_fputs (gimple_call_arg (stmt, 0),
+                                    gimple_call_arg (stmt, 1),
+                                    ignore, false, val[0]);
       break;
 
     case BUILT_IN_FPUTS_UNLOCKED:
-      result = fold_builtin_fputs (gimple_call_arg (stmt, 0),
-                                  gimple_call_arg (stmt, 1),
-                                   ignore, true, val[0]);
+      if (nargs == 2)
+       result = fold_builtin_fputs (gimple_call_arg (stmt, 0),
+                                    gimple_call_arg (stmt, 1),
+                                    ignore, true, 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,
                                           gimple_call_arg (stmt, 0),
                                           gimple_call_arg (stmt, 1),
@@ -2591,7 +2596,7 @@ ccp_fold_builtin (gimple stmt)
 
     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,
                                           gimple_call_arg (stmt, 0),
                                           gimple_call_arg (stmt, 1),
@@ -2601,7 +2606,7 @@ ccp_fold_builtin (gimple stmt)
       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 (gimple_call_arg (stmt, 0),
                                            gimple_call_arg (stmt, 1),
                                            gimple_call_arg (stmt, 2),