From d9cc481a359c713f473a136730e4019124368d6b Mon Sep 17 00:00:00 2001 From: Adam Nemet Date: Tue, 21 Oct 2008 17:46:53 +0000 Subject: [PATCH] re PR middle-end/37669 (ice for legal code with -O2) PR middle-end/37669 * tree-ssa-ccp.c (ccp_fold_builtin): Only allow one argument to be processed by get_maxval_strlen. testsuite/ PR middle-end/37669 * gcc.c-torture/compile/pr37669-2.c: New test. From-SVN: r141270 --- gcc/ChangeLog | 6 +++++ gcc/testsuite/ChangeLog | 5 ++++ .../gcc.c-torture/compile/pr37669-2.c | 14 ++++++++++ gcc/tree-ssa-ccp.c | 26 +++++++------------ 4 files changed, 35 insertions(+), 16 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr37669-2.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 455fcd94743..2400d9966b9 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2008-10-21 Adam Nemet + + PR middle-end/37669 + * tree-ssa-ccp.c (ccp_fold_builtin): Only allow one argument to be + processed by get_maxval_strlen. + 2008-10-21 David Edelsohn PR target/35485 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e65e7253fac..ddabb984223 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2008-10-21 Jakub Jelinek + + PR middle-end/37669 + * gcc.c-torture/compile/pr37669-2.c: New test. + 2008-10-21 Richard Guenther * gcc.dg/tree-ssa/alias-19.c: New testcase. diff --git a/gcc/testsuite/gcc.c-torture/compile/pr37669-2.c b/gcc/testsuite/gcc.c-torture/compile/pr37669-2.c new file mode 100644 index 00000000000..abeae7a2f32 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr37669-2.c @@ -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); +} diff --git a/gcc/tree-ssa-ccp.c b/gcc/tree-ssa-ccp.c index 383367e9fb1..0365697fc85 100644 --- a/gcc/tree-ssa-ccp.c +++ b/gcc/tree-ssa-ccp.c @@ -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);