diff options
author | Jakub Jelinek <jakub@redhat.com> | 2008-12-03 17:57:44 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2008-12-03 17:57:44 +0100 |
commit | f6ab27bb6d2a196cc8fdf13efbd137c520bae4ad (patch) | |
tree | 179bc0c86fb188da7b2fb52ee88940be78660607 | |
parent | 050bbfebe25a20cc711fc35d49be6bae5ff7a047 (diff) | |
download | gcc-f6ab27bb6d2a196cc8fdf13efbd137c520bae4ad.zip gcc-f6ab27bb6d2a196cc8fdf13efbd137c520bae4ad.tar.gz gcc-f6ab27bb6d2a196cc8fdf13efbd137c520bae4ad.tar.bz2 |
re PR middle-end/38360 (ICE in gimple_op, at gimple.h:1636)
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
-rw-r--r-- | gcc/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.c-torture/compile/pr38360.c | 9 | ||||
-rw-r--r-- | gcc/tree-ssa-ccp.c | 25 |
4 files changed, 35 insertions, 10 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 1f1c031..29104d8 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c9364f8..e62b980 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -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 index 0000000..463218d --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr38360.c @@ -0,0 +1,9 @@ +/* PR middle-end/38360 */ + +int +main () +{ + fputs (""); + fputs_unlocked (""); + return 0; +} diff --git a/gcc/tree-ssa-ccp.c b/gcc/tree-ssa-ccp.c index a7d5be3..82933f8 100644 --- a/gcc/tree-ssa-ccp.c +++ b/gcc/tree-ssa-ccp.c @@ -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), |