]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR tree-optimization/56273 (Bogus -Warray-bounds warning)
authorRichard Biener <rguenther@suse.de>
Tue, 24 Feb 2015 12:49:11 +0000 (12:49 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 24 Feb 2015 12:49:11 +0000 (12:49 +0000)
2015-02-24  Richard Biener  <rguenther@suse.de>

        Backport from mainline
        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.

From-SVN: r220939

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Warray-bounds-6.C [new file with mode: 0644]
gcc/testsuite/gcc.dg/Warray-bounds-12.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/Warray-bounds-13.c [new file with mode: 0644]
gcc/tree-vrp.c

index fcca28be6c6f70d5a019ae0c9c929124345aa7d3..a3ebfc56fdfe0dccd6f1504f1e8ed7b0f8da3854 100644 (file)
@@ -1,3 +1,14 @@
+2015-02-24  Richard Biener  <rguenther@suse.de>
+
+       Backport from mainline
+       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.
+
 2015-02-24  Richard Biener  <rguenther@suse.de>
 
        Backport from mainline
index dd7d67386358d9552d0e11e6af37c9c8535ef700..68bc4f604ec659d72110bfb4152dd45d85f5b39f 100644 (file)
@@ -1,3 +1,15 @@
+2015-02-24  Richard Biener  <rguenther@suse.de>
+
+       Backport from mainline
+       2015-01-27  Richard Biener  <rguenther@suse.de>
+
+       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-02-24  Andreas Krebbel  <Andreas.Krebbel@de.ibm.com>
 
        Backport from mainline
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 (file)
index 0000000..f2e5f2f
--- /dev/null
@@ -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 (file)
index 0000000..ef26c65
--- /dev/null
@@ -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 (file)
index 0000000..7b40a83
--- /dev/null
@@ -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;
+}
index 6363e45382229ec758265f3bf6a6b72b9f007a1e..ece180c175e617fb7cd90251d5e4255f711941cb 100644 (file)
@@ -9211,7 +9211,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