From 63fd708bd182b50b37b9f64fa330458c9109380a Mon Sep 17 00:00:00 2001 From: Alexander Ivchenko Date: Wed, 28 Jan 2015 14:16:01 +0300 Subject: [4.9] Fix bogus warnings about array-bounds. 2015-01-28 Ilya Enkovich PR tree-optimization/64277 * tree-ssa-loop-niter.c (record_nonwrapping_iv): Use base range info when possible to refine estimation. 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. Change-Id: I175b420a4c8150ecf986d477e4c51cbbff276c82 Signed-off-by: Alexander Ivchenko --- .../gcc/testsuite/g++.dg/warn/Warray-bounds-6.C | 26 ++++++++++++++++++++++ gcc-4.9/gcc/testsuite/gcc.dg/Warray-bounds-12.c | 26 ++++++++++++++++++++++ gcc-4.9/gcc/testsuite/gcc.dg/Warray-bounds-13.c | 18 +++++++++++++++ gcc-4.9/gcc/testsuite/gcc.dg/pr64277.c | 23 +++++++++++++++++++ 4 files changed, 93 insertions(+) create mode 100644 gcc-4.9/gcc/testsuite/g++.dg/warn/Warray-bounds-6.C create mode 100644 gcc-4.9/gcc/testsuite/gcc.dg/Warray-bounds-12.c create mode 100644 gcc-4.9/gcc/testsuite/gcc.dg/Warray-bounds-13.c create mode 100644 gcc-4.9/gcc/testsuite/gcc.dg/pr64277.c (limited to 'gcc-4.9/gcc/testsuite') diff --git a/gcc-4.9/gcc/testsuite/g++.dg/warn/Warray-bounds-6.C b/gcc-4.9/gcc/testsuite/g++.dg/warn/Warray-bounds-6.C new file mode 100644 index 0000000..f2e5f2f --- /dev/null +++ b/gcc-4.9/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-4.9/gcc/testsuite/gcc.dg/Warray-bounds-12.c b/gcc-4.9/gcc/testsuite/gcc.dg/Warray-bounds-12.c new file mode 100644 index 0000000..ef26c65 --- /dev/null +++ b/gcc-4.9/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-4.9/gcc/testsuite/gcc.dg/Warray-bounds-13.c b/gcc-4.9/gcc/testsuite/gcc.dg/Warray-bounds-13.c new file mode 100644 index 0000000..7b40a83 --- /dev/null +++ b/gcc-4.9/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-4.9/gcc/testsuite/gcc.dg/pr64277.c b/gcc-4.9/gcc/testsuite/gcc.dg/pr64277.c new file mode 100644 index 0000000..c6ef331 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/gcc.dg/pr64277.c @@ -0,0 +1,23 @@ +/* PR tree-optimization/64277 */ +/* { dg-do compile } */ +/* { dg-options "-O3 -Wall -Werror -fdump-tree-cunroll-details" } */ +/* { dg-final { scan-tree-dump "loop with 5 iterations completely unrolled" "cunroll" } } */ +/* { dg-final { scan-tree-dump "loop with 6 iterations completely unrolled" "cunroll" } } */ +/* { dg-final { cleanup-tree-dump "cunroll" } } */ + +int f1[10]; +void test1 (short a[], short m, unsigned short l) +{ + int i = l; + for (i = i + 5; i < m; i++) + f1[i] = a[i]++; +} + +void test2 (short a[], short m, short l) +{ + int i; + if (m > 5) + m = 5; + for (i = m; i > l; i--) + f1[i] = a[i]++; +} -- cgit v1.1