PR middle-end/85602 - -Warray-bounds fails to detect the out of bound array access
authorMartin Sebor <msebor@redhat.com>
Tue, 19 Jun 2018 22:35:45 +0000 (22:35 +0000)
committerMartin Sebor <msebor@gcc.gnu.org>
Tue, 19 Jun 2018 22:35:45 +0000 (16:35 -0600)
gcc/testsuite/ChangeLog:
  * c-c++-common/attr-nonstring-8.c: Adjust text of expected warning
  to also match C++.

From-SVN: r261774

gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/Warray-bounds-28.c [new file with mode: 0644]

index 04da05d23e12a2509b24b0b30bfaec39e156a987..5ce5b61c927b21617ceb44b0a3929c052aa4da31 100644 (file)
@@ -1,3 +1,8 @@
+2018-06-19  Martin Sebor  <msebor@redhat.com>
+
+       PR tree-optimization/48560
+       * gcc.dg/Warray-bounds-28.c: New test.
+
 2018-06-19  Martin Sebor  <msebor@redhat.com>
 
        PR middle-end/85602
diff --git a/gcc/testsuite/gcc.dg/Warray-bounds-28.c b/gcc/testsuite/gcc.dg/Warray-bounds-28.c
new file mode 100644 (file)
index 0000000..c63c70a
--- /dev/null
@@ -0,0 +1,15 @@
+/* PR tree-optimization/48560 - -Warray-bounds fails to detect the out of
+   bound array access
+   { dg-do compile }
+   { dg-options "-O2 -Warray-bounds" } */
+
+char foo1 (int i)
+{
+  static char s[] = "foo";
+  switch (i)
+    {
+    case 30:
+      return s[30];   /* { dg-warning "array subscript 30 is above array bounds" } */
+    }
+  return s[i];
+}