diff options
author | Richard Guenther <rguenther@suse.de> | 2013-01-11 10:20:02 +0000 |
---|---|---|
committer | Richard Biener <rguenth@gcc.gnu.org> | 2013-01-11 10:20:02 +0000 |
commit | c7ab25306dd8672e44b23414ebd2cf590c9fa63e (patch) | |
tree | cf7a483327f831613f65e779338a6b9783f8fd9e /gcc | |
parent | 8549adbd32fa9fdcb30e70cc3ff9cd9875e22d34 (diff) | |
download | gcc-c7ab25306dd8672e44b23414ebd2cf590c9fa63e.zip gcc-c7ab25306dd8672e44b23414ebd2cf590c9fa63e.tar.gz gcc-c7ab25306dd8672e44b23414ebd2cf590c9fa63e.tar.bz2 |
re PR tree-optimization/44061 (Warns about out-of-bounds array access inside __builtin_constant_p guarded section)
2012-01-11 Richard Guenther <rguenther@suse.de>
PR tree-optimization/44061
* tree-vrp.c (extract_range_basic): Compute zero as
value-range for __builtin_constant_p of function parameters.
* gcc.dg/pr44061.c: New testcase.
From-SVN: r195103
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr44061.c | 16 | ||||
-rw-r--r-- | gcc/tree-vrp.c | 16 |
4 files changed, 41 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index be407d4..9cbce45 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2012-01-11 Richard Guenther <rguenther@suse.de> + + PR tree-optimization/44061 + * tree-vrp.c (extract_range_basic): Compute zero as + value-range for __builtin_constant_p of function parameters. + 2013-01-10 Richard Sandiford <rdsandiford@googlemail.com> Update copyright years diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 25a44f0..df0378f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2012-01-11 Richard Guenther <rguenther@suse.de> + + PR tree-optimization/44061 + * gcc.dg/pr44061.c: New testcase. + 2013-01-10 Richard Sandiford <rdsandiford@googlemail.com> Update copyright years diff --git a/gcc/testsuite/gcc.dg/pr44061.c b/gcc/testsuite/gcc.dg/pr44061.c new file mode 100644 index 0000000..60a4260 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr44061.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wall" } */ + +int a[2]; +int foo (int q) +{ + if (__builtin_constant_p (q)) + { + if (q == 4) + return a[4]; /* { dg-bogus "array subscript is above array bounds" } */ + else + return a[0]; + } + else + return a[q]; +} diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index 38cf7dd..e902f6e 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -3565,8 +3565,20 @@ extract_range_basic (value_range_t *vr, gimple stmt) bool sop = false; tree type = gimple_expr_type (stmt); - if (INTEGRAL_TYPE_P (type) - && gimple_stmt_nonnegative_warnv_p (stmt, &sop)) + /* If the call is __builtin_constant_p and the argument is a + function parameter resolve it to false. This avoids bogus + array bound warnings. + ??? We could do this as early as inlining is finished. */ + if (gimple_call_builtin_p (stmt, BUILT_IN_CONSTANT_P)) + { + tree arg = gimple_call_arg (stmt, 0); + if (TREE_CODE (arg) == SSA_NAME + && SSA_NAME_IS_DEFAULT_DEF (arg) + && TREE_CODE (SSA_NAME_VAR (arg)) == PARM_DECL) + set_value_range_to_null (vr, type); + } + else if (INTEGRAL_TYPE_P (type) + && gimple_stmt_nonnegative_warnv_p (stmt, &sop)) set_value_range_to_nonnegative (vr, type, sop || stmt_overflow_infinity (stmt)); else if (vrp_stmt_computes_nonzero (stmt, &sop) |