libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / Wzero-length-array-bounds-2-novec.c
blob8e023b7cfa7fbef11acb306d6e0962ea4c43a9aa
1 /* Test to verify that -Wzero-length-bounds and not -Warray-bounds is
2 issued for accesses to interior zero-length array members that are
3 within the bounds of the enclosing struct.
4 { dg-do compile }
5 { dg-options "-O2 -Wall -fno-tree-vectorize" } */
7 void sink (void*);
9 struct A { int i; };
10 struct B { int j; struct A a[0]; };
12 struct C
14 struct B b1;
15 struct B b2;
18 char cbuf1[1 * sizeof (struct C)];
19 char cbuf2[2 * sizeof (struct C)] = { };
21 void test_C_global_buf (void)
23 struct C *p = (struct C*)&cbuf1;
25 p->b1.a[-1].i = 0; // { dg-warning "\\\[-Warray-bounds" }
26 p->b1.a[ 0].i = 0; // { dg-warning "\\\[-Wzero-length-bounds" }
27 p->b1.a[ 1].i = 0; // { dg-warning "\\\[-Warray-bounds" }
28 sink (p);
30 p->b2.a[ 0].i = 0; // { dg-warning "\\\[-Warray-bounds" }
31 p->b2.a[ 1].i = 0; // { dg-warning "\\\[-Warray-bounds" }
32 sink (p);
34 p = (struct C*)&cbuf2;
35 p->b1.a[-1].i = 0; // { dg-warning "\\\[-Warray-bounds" }
36 p->b1.a[ 0].i = 0; // { dg-warning "\\\[-Wzero-length-bounds" }
37 p->b1.a[ 1].i = 0; // { dg-warning "\\\[-Wzero-length-bounds" }
38 sink (p);
40 p->b2.a[ 0].i = 0;
41 p->b2.a[ 1].i = 0;
42 p->b2.a[ 2].i = 0; // { dg-warning "\\\[-Warray-bounds" }
43 p->b2.a[ 3].i = 0; // { dg-warning "\\\[-Warray-bounds" }
44 sink (p);