| 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" } */ |
| 6 |
|
| 7 |
void sink (void*); |
| 8 |
|
| 9 |
struct A { int i; }; |
| 10 |
struct B { int j; struct A a[0]; }; |
| 11 |
|
| 12 |
struct C |
| 13 |
{ |
| 14 |
struct B b1; |
| 15 |
struct B b2; |
| 16 |
}; |
| 17 |
|
| 18 |
char cbuf1[1 * sizeof (struct C)]; |
| 19 |
char cbuf2[2 * sizeof (struct C)] = { }; |
| 20 |
|
| 21 |
void test_C_global_buf (void) |
| 22 |
{ |
| 23 |
struct C *p = (struct C*)&cbuf1; |
| 24 |
|
| 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); |
| 29 |
|
| 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); |
| 33 |
|
| 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); |
| 39 |
|
| 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); |
| 45 |
} |