This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix PR middle-end/37669 (take 2)


This fixes the bug by completely removing the loop where the undefined shift
was occuring.  It also adds the testcase by Jakub.

Previous discussion was at
http://gcc.gnu.org/ml/gcc-patches/2008-10/msg00821.html.

Bootstrapped and tested on {mips64octeon,x86_64}-linux-gnu.

OK to install?

Adam

2008-10-21  Adam Nemet  <anemet@caviumnetworks.com>

	PR middle-end/37669
	* tree-ssa-ccp.c (ccp_fold_builtin): Only allow one argument to be
	processed by get_maxval_strlen.

testsuite/
2008-10-21  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/37669
	* gcc.c-torture/compile/pr37669-2.c: New test.

Index: tree-ssa-ccp.c
===================================================================
--- tree-ssa-ccp.c	(revision 141180)
+++ tree-ssa-ccp.c	(working copy)
@@ -2430,7 +2430,7 @@ ccp_fold_builtin (gimple stmt)
 {
   tree result, val[3];
   tree callee, a;
-  int arg_mask, i, type;
+  int arg_idx, type;
   bitmap visited;
   bool ignore;
   int nargs;
@@ -2466,12 +2466,12 @@ ccp_fold_builtin (gimple stmt)
     case BUILT_IN_STRLEN:
     case BUILT_IN_FPUTS:
     case BUILT_IN_FPUTS_UNLOCKED:
-      arg_mask = 1;
+      arg_idx = 0;
       type = 0;
       break;
     case BUILT_IN_STRCPY:
     case BUILT_IN_STRNCPY:
-      arg_mask = 2;
+      arg_idx = 1;
       type = 0;
       break;
     case BUILT_IN_MEMCPY_CHK:
@@ -2479,17 +2479,17 @@ ccp_fold_builtin (gimple stmt)
     case BUILT_IN_MEMMOVE_CHK:
     case BUILT_IN_MEMSET_CHK:
     case BUILT_IN_STRNCPY_CHK:
-      arg_mask = 4;
+      arg_idx = 2;
       type = 2;
       break;
     case BUILT_IN_STRCPY_CHK:
     case BUILT_IN_STPCPY_CHK:
-      arg_mask = 2;
+      arg_idx = 1;
       type = 1;
       break;
     case BUILT_IN_SNPRINTF_CHK:
     case BUILT_IN_VSNPRINTF_CHK:
-      arg_mask = 2;
+      arg_idx = 1;
       type = 2;
       break;
     default:
@@ -2498,18 +2498,12 @@ ccp_fold_builtin (gimple stmt)
 
   /* Try to use the dataflow information gathered by the CCP process.  */
   visited = BITMAP_ALLOC (NULL);
+  bitmap_clear (visited);
 
   memset (val, 0, sizeof (val));
-  for (i = 0; i < nargs; i++)
-    {
-      if ((arg_mask >> i) & 1)
-        {
-          a = gimple_call_arg (stmt, i);
-          bitmap_clear (visited);
-          if (!get_maxval_strlen (a, &val[i], visited, type))
-            val[i] = NULL_TREE;
-        }
-    }
+  a = gimple_call_arg (stmt, arg_idx);
+  if (!get_maxval_strlen (a, &val[arg_idx], visited, type))
+    val[arg_idx] = NULL_TREE;
 
   BITMAP_FREE (visited);
 
Index: testsuite/gcc.c-torture/compile/pr37669-2.c
===================================================================
--- testsuite/gcc.c-torture/compile/pr37669-2.c	(revision 0)
+++ testsuite/gcc.c-torture/compile/pr37669-2.c	(revision 0)
@@ -0,0 +1,14 @@
+/* PR middle-end/37669 */
+
+#define FMT10 "%d%d%d%d%d%d%d%d%d%d"
+#define FMT100 FMT10 FMT10 FMT10 FMT10 FMT10 FMT10 FMT10 FMT10 FMT10 FMT10
+#define FMT1000 FMT100 FMT100 FMT100 FMT100 FMT100 \
+		FMT100 FMT100 FMT100 FMT100 FMT100
+#define ARG10 , i, i, i, i, i, i, i, i, i, i
+#define ARG100 ARG10 ARG10 ARG10 ARG10 ARG10 ARG10 ARG10 ARG10 ARG10 ARG10
+#define ARG1000 ARG100 ARG100 ARG100 ARG100 ARG100 \
+		ARG100 ARG100 ARG100 ARG100 ARG100
+void foo (char *s, int i, int j)
+{
+  __builtin___snprintf_chk (s, i, 1, j, FMT1000 ARG1000);
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]