OSDN Git Service

PR c++/43076
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / pr40946.c
1 /* PR middle-end/40946 */
2 /* { dg-do compile } */
3 /* { dg-options "-O2 -Wall" } */
4
5 struct A
6 {
7   unsigned char a1[8];
8   unsigned short a2, a3, a4, a5, a6, a7;
9 };
10
11 int bar (void *, const char *, int);
12 char *foo (void *, int);
13
14 char *
15 baz (const char *x, const char *y)
16 {
17   int a = sizeof (struct A) + 2 * (__builtin_strlen (y)
18                                    + __builtin_strlen (x) + 24) + 16;
19   struct A *b = __builtin_malloc (a);
20   char *c;
21   int d;
22
23   b->a4 = sizeof (struct A);
24   c = ((char *) b) + b->a4;
25   d = ((char *) b) + a - c;
26   b->a2 = b->a3 = (unsigned short) bar (c, y, d); /* { dg-bogus "array subscript is above array bounds" } */
27   c += b->a2;
28   d = ((char *) b) + a - c;
29   b->a7 = b->a4 + b->a2;
30   b->a5 = b->a6 = (unsigned short) bar (c, x, d);
31   c = foo (b, a);
32   return c;
33 }