From: Richard Guenther Date: Tue, 20 Apr 2010 14:24:39 +0000 (+0000) Subject: backport: [multiple changes] X-Git-Tag: releases/gcc-4.3.5~84 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3742b7f365fa21e3aee620251da039820ab5fe79;p=thirdparty%2Fgcc.git backport: [multiple changes] 2010-04-20 Richard Guenther Backport from mainline: 2010-03-01 Richard Guenther 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 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 177aba29feae..84cd0c48519d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,18 @@ +2010-04-20 Richard Guenther + + Backport from mainline: + 2010-03-01 Richard Guenther + + 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 + + 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 Backport from mainline diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8002421e21e8..6098a3134682 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,16 @@ +2010-04-20 Richard Guenther + + Backport from mainline: + 2010-03-01 Richard Guenther + + PR tree-optimization/43220 + * gcc.c-torture/execute/pr43220.c: New testcase. + + 2008-12-03 Jakub Jelinek + + PR middle-end/38360 + * gcc.c-torture/compile/pr38360.c: New test. + 2010-04-20 Richard Guenther 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 index 000000000000..463218d1156e --- /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/testsuite/gcc.c-torture/execute/pr43220.c b/gcc/testsuite/gcc.c-torture/execute/pr43220.c new file mode 100644 index 000000000000..4709f17b5a0c --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr43220.c @@ -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; +} diff --git a/gcc/tree-ssa-ccp.c b/gcc/tree-ssa-ccp.c index 41eed535d50e..bd29c40e9e7d 100644 --- a/gcc/tree-ssa-ccp.c +++ b/gcc/tree-ssa-ccp.c @@ -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)