PR tree-optimization/84053 - missing -Warray-bounds accessing a local array across...
authorMartin Sebor <msebor@redhat.com>
Thu, 20 Dec 2018 16:25:13 +0000 (16:25 +0000)
committerMartin Sebor <msebor@gcc.gnu.org>
Thu, 20 Dec 2018 16:25:13 +0000 (09:25 -0700)
gcc/testsuite/ChangeLog:
* gcc.dg/Warray-bounds-36.c: New test.

From-SVN: r267302

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

index 61aa13ba5b62f16a5feaf5d425322513522a00a6..2a78f9722a9e136ddd8d47484b7287f40929f076 100644 (file)
@@ -1,3 +1,8 @@
+2018-12-20  Martin Sebor  <msebor@redhat.com>
+
+       PR tree-optimization/84053
+       * gcc.dg/Warray-bounds-36.c: New test.
+
 2018-12-20  David Malcolm  <dmalcolm@redhat.com>
 
        PR c++/87504
diff --git a/gcc/testsuite/gcc.dg/Warray-bounds-36.c b/gcc/testsuite/gcc.dg/Warray-bounds-36.c
new file mode 100644 (file)
index 0000000..35b3c92
--- /dev/null
@@ -0,0 +1,27 @@
+/* PR tree-optimization/84053] missing -Warray-bounds accessing
+   a local array across inlined function boundaries
+   { dg-do compile }
+   { dg-options "-O2 -Wall" } */
+
+int deref (const int *p, int i)
+{
+  return p[i];                // { dg-warning "array subscript \\\[3, \[0-9\]+] is outside array bounds of .int\\\[2\\\]." "ilp33" { xfail ilp32 } }
+
+  // There should also be an inlining context here.  PR 86650 tracks
+  // its absence.
+}
+
+int deref_3_plus (const int *p, int i)
+{
+  if (i < 3)
+    i = 3;
+
+  return deref (p, i);
+}
+
+int deref_a (int i)
+{
+  int a[] = { 2, 3 };
+
+  return deref_3_plus (a, i);
+}