re PR middle-end/40946 (Spurious array subscript is above bounds warning)
authorJakub Jelinek <jakub@redhat.com>
Mon, 9 Nov 2009 19:40:56 +0000 (20:40 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 9 Nov 2009 19:40:56 +0000 (20:40 +0100)
PR middle-end/40946
* gcc.dg/pr40946.c: New test.

From-SVN: r154047

gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr40946.c [new file with mode: 0644]

index 9192268..a37b0b1 100644 (file)
@@ -1,3 +1,8 @@
+2009-11-09  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/40946
+       * gcc.dg/pr40946.c: New test.
+
 2009-11-09  Jason Merrill  <jason@redhat.com>
 
        PR c++/41972
diff --git a/gcc/testsuite/gcc.dg/pr40946.c b/gcc/testsuite/gcc.dg/pr40946.c
new file mode 100644 (file)
index 0000000..3fd804e
--- /dev/null
@@ -0,0 +1,33 @@
+/* PR middle-end/40946 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wall" } */
+
+struct A
+{
+  unsigned char a1[8];
+  unsigned short a2, a3, a4, a5, a6, a7;
+};
+
+int bar (void *, const char *, int);
+char *foo (void *, int);
+
+char *
+baz (const char *x, const char *y)
+{
+  int a = sizeof (struct A) + 2 * (__builtin_strlen (y)
+                                  + __builtin_strlen (x) + 24) + 16;
+  struct A *b = __builtin_malloc (a);
+  char *c;
+  int d;
+
+  b->a4 = sizeof (struct A);
+  c = ((char *) b) + b->a4;
+  d = ((char *) b) + a - c;
+  b->a2 = b->a3 = (unsigned short) bar (c, y, d); /* { dg-bogus "array subscript is above array bounds" } */
+  c += b->a2;
+  d = ((char *) b) + a - c;
+  b->a7 = b->a4 + b->a2;
+  b->a5 = b->a6 = (unsigned short) bar (c, x, d);
+  c = foo (b, a);
+  return c;
+}