https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102706
--- Comment #3 from Hongtao.liu <crazylht at gmail dot com> --- >From gcc.dg/Warray-bounds-51.c void test_struct_char_vla_location (void) { unsigned nelts = 7; struct { char cvla[nelts]; // { dg-message "declared here|while referencing" } } s; s.cvla[0] = __LINE__; s.cvla[nelts - 1] = 0; // { dg-warning "\\\[-Wstringop-overflow" "" { target { i?86-*-* x86_64-*-* } } } s.cvla[nelts] = 0; // { dg-warning "\\\[-Warray-bounds" } sink (&s); } >From gcc.dg/Warray-parameter-3.c __attribute__ ((noipa)) void gcas3 (char a[static 3]) { a[0] = 0; a[1] = 1; a[2] = 2; // { dg-warning "\\\[-Wstringop-overflow" "" { target { i?86-*-* x86_64-*-* } } } a[3] = 3; // { dg-warning "\\\[-Warray-bounds" } } >From gcc.dg/Wstringop-overflow-14.c void test_int16 (void) { char *p = a4 + 1; *(int16_t*)p = 0; // { dg-warning "writing 4 bytes into a region of size 3" "" { target { i?86-*-* x86_64-*-* } } } *(int16_t*)(p + 2) = 0; // { dg-warning "writing 2 bytes into a region of size 1" "" { xfail { i?86-*-* x86_64-*-* } } } } >From gcc.dg/Wstringop-overflow-21.c void test_store_zero_length (int i) { char a[3]; struct S0 *p = (struct S0*)a; p->a = 0; // { dg-warning "\\\[-Wstringop-overflow" "" { target { i?86-*-* x86_64-*-* } } } p->b[0] = 0; p->b[1] = 1; // { dg-bogus "\\\[-Wstringop-overflow" } p->b[2] = 2; // { dg-warning "\\\[-Wstringop-overflow" "" { xfail { i?86-*-* x86_64-*-* } } } p->b[i] = 2; sink (p); } void test_store_flexarray (int i) { char a[3]; struct Sx *p = (struct Sx*)a; p->a = 0; // { dg-warning "\\\[-Wstringop-overflow" "" { target { i?86-*-* x86_64-*-* } } } p->b[0] = 0; p->b[1] = 1; // { dg-bogus "\\\[-Wstringop-overflow" } p->b[2] = 1; // { dg-warning "\\\[-Wstringop-overflow" "" { xfail { i?86-*-* x86_64-*-* } } } p->b[i] = 2; sink (p); } >From gcc.dg/Wstringop-overflow-76.c: extern char a3[3]; extern char a5[5]; // { dg-message "at offset \[^a-zA-Z\n\r\]*5\[^a-zA-Z0-9\]* into destination object 'a5' of size 5" "note" } void max_a3_a5 (int i) { char *p = a3 + i; char *q = a5 + i; /* The relational expression below is invalid and should be diagnosed by its own warning independently of -Wstringop-overflow. */ char *d = MAX (p, q); d[2] = 0; // { dg-warning "writing 4 bytes into a region of size 3" "" { target { i?86-*-* x86_64-*-* } } } d[3] = 0; d[4] = 0; d[5] = 0; // { dg-warning "writing 1 byte into a region of size 0" "" { xfail { i?86-*-* x86_64-*-* } } } } // Same as above but with the larger array as the first MAX_EXPR operand. extern char b4[4]; extern char b6[6]; // { dg-message "at offset \[^a-zA-Z\n\r\]*6\[^a-zA-Z0-9\]* into destination object 'b6' of size 6" "note" } void max_b6_b4 (int i) { char *p = b6 + i; char *q = b4 + i; char *d = MAX (p, q); d[3] = 0; // { dg-warning "writing 4 bytes into a region of size 3" "" { target { i?86-*-* x86_64-*-* } } } d[4] = 0; d[5] = 0; d[6] = 0; // { dg-warning "writing 1 byte into a region of size 0" "" { xfail { i?86-*-* x86_64-*-* } } } }