aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc
diff options
context:
space:
mode:
authorAlexander Ivchenko <alexander.ivchenko@intel.com>2015-01-28 14:16:01 +0300
committerAlexander Ivchenko <alexander.ivchenko@intel.com>2015-01-28 15:41:39 +0300
commit63fd708bd182b50b37b9f64fa330458c9109380a (patch)
tree2799a45bf3f48cd9f4039d79aa82b5c0b2189f6a /gcc-4.9/gcc
parent866bd0b46cd84957df84e7a3e674d9777807b7f7 (diff)
downloadtoolchain_gcc-63fd708bd182b50b37b9f64fa330458c9109380a.tar.gz
toolchain_gcc-63fd708bd182b50b37b9f64fa330458c9109380a.tar.bz2
toolchain_gcc-63fd708bd182b50b37b9f64fa330458c9109380a.zip
[4.9] Fix bogus warnings about array-bounds.
2015-01-28 Ilya Enkovich <ilya.enkovich@intel.com> 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 <rguenther@suse.de> 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 <alexander.ivchenko@intel.com>
Diffstat (limited to 'gcc-4.9/gcc')
-rw-r--r--gcc-4.9/gcc/testsuite/g++.dg/warn/Warray-bounds-6.C26
-rw-r--r--gcc-4.9/gcc/testsuite/gcc.dg/Warray-bounds-12.c26
-rw-r--r--gcc-4.9/gcc/testsuite/gcc.dg/Warray-bounds-13.c18
-rw-r--r--gcc-4.9/gcc/testsuite/gcc.dg/pr64277.c23
-rw-r--r--gcc-4.9/gcc/tree-ssa-loop-niter.c17
-rw-r--r--gcc-4.9/gcc/tree-vrp.c2
6 files changed, 110 insertions, 2 deletions
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 000000000..f2e5f2f59
--- /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 000000000..ef26c6596
--- /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 000000000..7b40a8388
--- /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 000000000..c6ef33119
--- /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]++;
+}
diff --git a/gcc-4.9/gcc/tree-ssa-loop-niter.c b/gcc-4.9/gcc/tree-ssa-loop-niter.c
index 7628363cc..62175f344 100644
--- a/gcc-4.9/gcc/tree-ssa-loop-niter.c
+++ b/gcc-4.9/gcc/tree-ssa-loop-niter.c
@@ -2724,6 +2724,7 @@ record_nonwrapping_iv (struct loop *loop, tree base, tree step, gimple stmt,
tree niter_bound, extreme, delta;
tree type = TREE_TYPE (base), unsigned_type;
double_int max;
+ tree orig_base = base;
if (TREE_CODE (step) != INTEGER_CST || integer_zerop (step))
return;
@@ -2747,7 +2748,14 @@ record_nonwrapping_iv (struct loop *loop, tree base, tree step, gimple stmt,
if (tree_int_cst_sign_bit (step))
{
+ double_int min, max;
extreme = fold_convert (unsigned_type, low);
+ if (TREE_CODE (orig_base) == SSA_NAME
+ && TREE_CODE (high) == INTEGER_CST
+ && INTEGRAL_TYPE_P (TREE_TYPE (orig_base))
+ && get_range_info (orig_base, &min, &max) == VR_RANGE
+ && max.slt (TREE_INT_CST (high)))
+ base = double_int_to_tree (unsigned_type, max);
if (TREE_CODE (base) != INTEGER_CST)
base = fold_convert (unsigned_type, high);
delta = fold_build2 (MINUS_EXPR, unsigned_type, base, extreme);
@@ -2755,8 +2763,15 @@ record_nonwrapping_iv (struct loop *loop, tree base, tree step, gimple stmt,
}
else
{
+ double_int min, max;
extreme = fold_convert (unsigned_type, high);
- if (TREE_CODE (base) != INTEGER_CST)
+ if (TREE_CODE (orig_base) == SSA_NAME
+ && TREE_CODE (low) == INTEGER_CST
+ && INTEGRAL_TYPE_P (TREE_TYPE (orig_base))
+ && get_range_info (orig_base, &min, &max) == VR_RANGE
+ && min.sgt (TREE_INT_CST (low)))
+ base = double_int_to_tree (unsigned_type, min);
+ else if (TREE_CODE (base) != INTEGER_CST)
base = fold_convert (unsigned_type, low);
delta = fold_build2 (MINUS_EXPR, unsigned_type, extreme, base);
}
diff --git a/gcc-4.9/gcc/tree-vrp.c b/gcc-4.9/gcc/tree-vrp.c
index 2c80135f9..b31194410 100644
--- a/gcc-4.9/gcc/tree-vrp.c
+++ b/gcc-4.9/gcc/tree-vrp.c
@@ -9728,7 +9728,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