From f101c4b47a98c98238bbf31a7ee79b1b2e4cce7b Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Tue, 27 Jan 2015 09:49:29 +0000 Subject: [PATCH] re PR tree-optimization/56273 (Bogus -Warray-bounds warning) 2015-01-27 Richard Biener PR tree-optimization/56273 PR tree-optimization/59124 PR tree-optimization/64277 * tree-vrp.c (vrp_finalize): Emit array-bound warnings only from the first VRP pass. * g++.dg/warn/Warray-bounds-6.C: New testcase. * gcc.dg/Warray-bounds-12.c: Likewise. * gcc.dg/Warray-bounds-13.c: Likewise. From-SVN: r220157 --- gcc/ChangeLog | 8 +++++++ gcc/testsuite/ChangeLog | 9 +++++++ gcc/testsuite/g++.dg/warn/Warray-bounds-6.C | 26 +++++++++++++++++++++ gcc/testsuite/gcc.dg/Warray-bounds-12.c | 26 +++++++++++++++++++++ gcc/testsuite/gcc.dg/Warray-bounds-13.c | 18 ++++++++++++++ gcc/tree-vrp.c | 2 +- 6 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/warn/Warray-bounds-6.C create mode 100644 gcc/testsuite/gcc.dg/Warray-bounds-12.c create mode 100644 gcc/testsuite/gcc.dg/Warray-bounds-13.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 2f4e5255e23..7972a4dc29d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2015-01-27 Richard Biener + + PR tree-optimization/56273 + PR tree-optimization/59124 + PR tree-optimization/64277 + * tree-vrp.c (vrp_finalize): Emit array-bound warnings only + from the first VRP pass. + 2015-01-27 Jakub Jelinek PR ipa/64776 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8bcb32a0e39..a27bf71ffc2 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2015-01-27 Richard Biener + + PR tree-optimization/56273 + PR tree-optimization/59124 + PR tree-optimization/64277 + * g++.dg/warn/Warray-bounds-6.C: New testcase. + * gcc.dg/Warray-bounds-12.c: Likewise. + * gcc.dg/Warray-bounds-13.c: Likewise. + 2015-01-27 Jakub Jelinek PR rtl-optimization/61058 diff --git a/gcc/testsuite/g++.dg/warn/Warray-bounds-6.C b/gcc/testsuite/g++.dg/warn/Warray-bounds-6.C new file mode 100644 index 00000000000..f2e5f2f597a --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Warray-bounds-6.C @@ -0,0 +1,26 @@ +// { dg-do compile } +// { dg-options "-O3 -Warray-bounds" } + +struct type { + bool a, b; + bool get_b() { return b; } +}; + +type stuff[9u]; + +void bar(); + +void foo() +{ + for(unsigned i = 0u; i < 9u; i++) + { + if(!stuff[i].a) + continue; + + bar(); + + for(unsigned j = i + 1u; j < 9u; j++) + if(stuff[j].a && stuff[j].get_b()) // { dg-bogus "above array bounds" } + return; + } +} diff --git a/gcc/testsuite/gcc.dg/Warray-bounds-12.c b/gcc/testsuite/gcc.dg/Warray-bounds-12.c new file mode 100644 index 00000000000..ef26c6596bf --- /dev/null +++ b/gcc/testsuite/gcc.dg/Warray-bounds-12.c @@ -0,0 +1,26 @@ +/* { dg-do compile } */ +/* { dg-options "-O3 -Warray-bounds" } */ +/* { dg-additional-options "-mssse3" { target x86_64-*-* i?86-*-* } } */ + +void foo(short a[], short m) +{ + int i, j; + int f1[10]; + short nc; + + nc = m + 1; + if (nc > 3) + { + for (i = 0; i <= nc; i++) + { + f1[i] = f1[i] + 1; + } + } + + for (i = 0, j = m; i < nc; i++, j--) + { + a[i] = f1[i]; /* { dg-bogus "above array bounds" } */ + a[j] = i; + } + return; +} diff --git a/gcc/testsuite/gcc.dg/Warray-bounds-13.c b/gcc/testsuite/gcc.dg/Warray-bounds-13.c new file mode 100644 index 00000000000..7b40a83887d --- /dev/null +++ b/gcc/testsuite/gcc.dg/Warray-bounds-13.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-O3 -Warray-bounds" } */ + +extern char *bar[17]; + +int foo(int argc, char **argv) +{ + int i; + int n = 0; + + for (i = 0; i < argc; i++) + n++; + + for (i = 0; i < argc; i++) + argv[i] = bar[i + n]; /* { dg-bogus "above array bounds" } */ + + return 0; +} diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index acf6b20fd4f..c5ca2876b57 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -10229,7 +10229,7 @@ vrp_finalize (void) substitute_and_fold (op_with_constant_singleton_value_range, vrp_fold_stmt, false); - if (warn_array_bounds) + if (warn_array_bounds && first_pass_instance) check_all_array_refs (); /* We must identify jump threading opportunities before we release -- 2.30.2