The recent improvement to -Warray-bounds to detect past-the-end accesses by string functions to member subobjects had a bug that triggered a false positive in a Binutils build. In r276022 I've committed the attached trivial fix to correct the bug.
Martin
Index: gcc/ChangeLog =================================================================== Index: gcc/testsuite/gcc.dg/Warray-bounds-47.c =================================================================== --- gcc/testsuite/gcc.dg/Warray-bounds-47.c (nonexistent) +++ gcc/testsuite/gcc.dg/Warray-bounds-47.c (revision 276022) @@ -0,0 +1,429 @@ +/* PR middle-end/91830 - Bogus -Warray-bounds on strcpy into a member + of a subobject compiling binutils + { dg-do compile } + { dg-options "-O2 -Wall -ftrack-macro-expansion=0" } */ + +extern char* strcpy (char*, const char*); +extern void sink (void*); + +#define S36 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" + +#define S(N) (S36 + sizeof (S36) - N - 1) + +/* In the test macro, prevent the strcpy to memcpy transformation + by using a local array initialized with the string literal. Without + it, GCC transforms the strcpy call with memcpy which (unfortunately) + permits accesses that cross subobject boundaries. */ +#define T(obj, mem, n) \ + do { \ + struct A *pa = &obj; \ + const char a[] = S36; \ + strcpy (pa->mem, a + sizeof a - n - 1); \ + sink (&obj); \ + } while (0) + + +struct A { char a[3]; char b[5]; }; +struct B { char c[7]; struct A a; struct A a2[2]; }; + +extern struct B b[]; + +void array_nowarn (int i) +{ + struct B *pb = b; + + T (pb[0].a, a, 0); // { dg-bogus "\\\[-W" } + T (pb[0].a, a, 1); // { dg-bogus "\\\[-W" } + T (pb[0].a, a, 2); // { dg-bogus "\\\[-W" } + + T (pb[1].a, a, 0); // { dg-bogus "\\\[-W" } + T (pb[1].a, a, 1); // { dg-bogus "\\\[-W" } + T (pb[1].a, a, 2); // { dg-bogus "\\\[-W" } + + T (pb[123].a, a, 0); // { dg-bogus "\\\[-W" } + T (pb[123].a, a, 1); // { dg-bogus "\\\[-W" } + T (pb[123].a, a, 2); // { dg-bogus "\\\[-W" } + + T (pb[i].a, a, 0); + T (pb[i].a, a, 1); + T (pb[i].a, a, 2); + + + T (pb[0].a, b, 0); // { dg-bogus "\\\[-W" } + T (pb[0].a, b, 1); // { dg-bogus "\\\[-W" } + T (pb[0].a, b, 2); // { dg-bogus "\\\[-W" } + T (pb[0].a, b, 3); // { dg-bogus "\\\[-W" } + T (pb[0].a, b, 4); // { dg-bogus "\\\[-W" } + + T (pb[1].a, b, 0); // { dg-bogus "\\\[-W" } + T (pb[1].a, b, 1); // { dg-bogus "\\\[-W" } + T (pb[1].a, b, 2); // { dg-bogus "\\\[-W" } + T (pb[1].a, b, 3); // { dg-bogus "\\\[-W" } + T (pb[1].a, b, 4); // { dg-bogus "\\\[-W" } + + T (pb[123].a, b, 0); // { dg-bogus "\\\[-W" } + T (pb[123].a, b, 1); // { dg-bogus "\\\[-W" } + T (pb[123].a, b, 2); // { dg-bogus "\\\[-W" } + T (pb[123].a, b, 3); // { dg-bogus "\\\[-W" } + T (pb[123].a, b, 4); // { dg-bogus "\\\[-W" } + + T (pb[i].a, b, 0); + T (pb[i].a, b, 1); + T (pb[i].a, b, 2); + T (pb[i].a, b, 3); + T (pb[i].a, b, 4); + + + T (pb[0].a2[0], b, 0); // { dg-bogus "\\\[-W" } + T (pb[0].a2[0], b, 1); // { dg-bogus "\\\[-W" } + T (pb[0].a2[0], b, 2); // { dg-bogus "\\\[-W" } + T (pb[0].a2[0], b, 3); // { dg-bogus "\\\[-W" } + T (pb[0].a2[0], b, 4); // { dg-bogus "\\\[-W" } + + T (pb[1].a2[0], b, 0); // { dg-bogus "\\\[-W" } + T (pb[1].a2[0], b, 1); // { dg-bogus "\\\[-W" } + T (pb[1].a2[0], b, 2); // { dg-bogus "\\\[-W" } + T (pb[1].a2[0], b, 3); // { dg-bogus "\\\[-W" } + T (pb[1].a2[0], b, 4); // { dg-bogus "\\\[-W" } + + T (pb[123].a2[0], b, 0); // { dg-bogus "\\\[-W" } + T (pb[123].a2[0], b, 1); // { dg-bogus "\\\[-W" } + T (pb[123].a2[0], b, 2); // { dg-bogus "\\\[-W" } + T (pb[123].a2[0], b, 3); // { dg-bogus "\\\[-W" } + T (pb[123].a2[0], b, 4); // { dg-bogus "\\\[-W" } + + T (pb[123].a2[1], b, 0); // { dg-bogus "\\\[-W" } + T (pb[123].a2[1], b, 1); // { dg-bogus "\\\[-W" } + T (pb[123].a2[1], b, 2); // { dg-bogus "\\\[-W" } + T (pb[123].a2[1], b, 3); // { dg-bogus "\\\[-W" } + T (pb[123].a2[1], b, 4); // { dg-bogus "\\\[-W" } + + T (pb[i].a2[0], b, 0); + T (pb[i].a2[0], b, 1); + T (pb[i].a2[0], b, 2); + T (pb[i].a2[0], b, 3); + T (pb[i].a2[0], b, 4); + + T (pb[i].a2[1], b, 0); + T (pb[i].a2[1], b, 1); + T (pb[i].a2[1], b, 2); + T (pb[i].a2[1], b, 3); + T (pb[i].a2[1], b, 4); +} + +void array_warn (int i) +{ + struct B *pb = b; + + T (pb[0].a, a, 3); // { dg-warning "\\\[-Warray-bounds" } + T (pb[0].a, a, 4); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[1].a, a, 5); // { dg-warning "\\\[-Warray-bounds" } + T (pb[1].a, a, 6); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[789].a, a, 5); // { dg-warning "\\\[-Warray-bounds" } + T (pb[789].a, a, 6); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[i].a, a, 7); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } + T (pb[i].a, a, 8); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } + + + T (pb[0].a, b, 5); // { dg-warning "\\\[-Warray-bounds" } + T (pb[0].a, b, 6); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[1].a, b, 5); // { dg-warning "\\\[-Warray-bounds" } + T (pb[1].a, b, 6); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[789].a, b, 5); // { dg-warning "\\\[-Warray-bounds" } + T (pb[789].a, b, 6); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[i].a, b, 5); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } + T (pb[i].a, b, 6); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } + + + T (pb[0].a2[0], b, 5); // { dg-warning "\\\[-Warray-bounds" } + T (pb[0].a2[0], b, 6); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[1].a2[0], b, 5); // { dg-warning "\\\[-Warray-bounds" } + T (pb[1].a2[0], b, 6); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[789].a2[0], b, 5); // { dg-warning "\\\[-Warray-bounds" } + T (pb[789].a2[0], b, 6); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[i].a2[0], b, 5); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } + T (pb[i].a2[0], b, 6); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } + + T (pb[0].a2[1], b, 5); // { dg-warning "\\\[-Warray-bounds" } + T (pb[0].a2[1], b, 6); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[1].a2[1], b, 5); // { dg-warning "\\\[-Warray-bounds" } + T (pb[1].a2[1], b, 6); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[789].a2[1], b, 5); // { dg-warning "\\\[-Warray-bounds" } + T (pb[789].a2[1], b, 6); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[i].a2[1], b, 5); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } + T (pb[i].a2[1], b, 6); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } +} + +void ptr_nowarn (struct B *pb, int i) +{ + T (pb[-123].a, a, 0); // { dg-bogus "\\\[-W" } + T (pb[-123].a, a, 1); // { dg-bogus "\\\[-W" } + T (pb[-123].a, a, 2); // { dg-bogus "\\\[-W" } + + T (pb[-2].a, a, 0); // { dg-bogus "\\\[-W" } + T (pb[-2].a, a, 1); // { dg-bogus "\\\[-W" } + T (pb[-2].a, a, 2); // { dg-bogus "\\\[-W" } + + T (pb[-1].a, a, 0); // { dg-bogus "\\\[-W" } + T (pb[-1].a, a, 1); // { dg-bogus "\\\[-W" } + T (pb[-1].a, a, 2); // { dg-bogus "\\\[-W" } + + T (pb[0].a, a, 0); // { dg-bogus "\\\[-W" } + T (pb[0].a, a, 1); // { dg-bogus "\\\[-W" } + T (pb[0].a, a, 2); // { dg-bogus "\\\[-W" } + + T (pb[1].a, a, 0); // { dg-bogus "\\\[-W" } + T (pb[1].a, a, 1); // { dg-bogus "\\\[-W" } + T (pb[1].a, a, 2); // { dg-bogus "\\\[-W" } + + T (pb[123].a, a, 0); // { dg-bogus "\\\[-W" } + T (pb[123].a, a, 1); // { dg-bogus "\\\[-W" } + T (pb[123].a, a, 2); // { dg-bogus "\\\[-W" } + + T (pb[i].a, a, 0); // { dg-bogus "\\\[-W" } + T (pb[i].a, a, 1); // { dg-bogus "\\\[-W" } + T (pb[i].a, a, 2); // { dg-bogus "\\\[-W" } + + + T (pb[-123].a, b, 0); // { dg-bogus "\\\[-W" } + T (pb[-123].a, b, 1); // { dg-bogus "\\\[-W" } + T (pb[-123].a, b, 2); // { dg-bogus "\\\[-W" } + T (pb[-123].a, b, 3); // { dg-bogus "\\\[-W" } + T (pb[-123].a, b, 4); // { dg-bogus "\\\[-W" } + + T (pb[-2].a, b, 0); // { dg-bogus "\\\[-W" } + T (pb[-2].a, b, 1); // { dg-bogus "\\\[-W" } + T (pb[-2].a, b, 2); // { dg-bogus "\\\[-W" } + T (pb[-2].a, b, 3); // { dg-bogus "\\\[-W" } + T (pb[-2].a, b, 4); // { dg-bogus "\\\[-W" } + + T (pb[-1].a, b, 0); // { dg-bogus "\\\[-W" } + T (pb[-1].a, b, 1); // { dg-bogus "\\\[-W" } + T (pb[-1].a, b, 2); // { dg-bogus "\\\[-W" } + T (pb[-1].a, b, 3); // { dg-bogus "\\\[-W" } + T (pb[-1].a, b, 4); // { dg-bogus "\\\[-W" } + + T (pb[0].a, b, 0); // { dg-bogus "\\\[-W" } + T (pb[0].a, b, 1); // { dg-bogus "\\\[-W" } + T (pb[0].a, b, 2); // { dg-bogus "\\\[-W" } + T (pb[0].a, b, 3); // { dg-bogus "\\\[-W" } + T (pb[0].a, b, 4); // { dg-bogus "\\\[-W" } + + T (pb[1].a, b, 0); // { dg-bogus "\\\[-W" } + T (pb[1].a, b, 1); // { dg-bogus "\\\[-W" } + T (pb[1].a, b, 2); // { dg-bogus "\\\[-W" } + T (pb[1].a, b, 3); // { dg-bogus "\\\[-W" } + T (pb[1].a, b, 4); // { dg-bogus "\\\[-W" } + + T (pb[123].a, b, 0); // { dg-bogus "\\\[-W" } + T (pb[123].a, b, 1); // { dg-bogus "\\\[-W" } + T (pb[123].a, b, 2); // { dg-bogus "\\\[-W" } + T (pb[123].a, b, 3); // { dg-bogus "\\\[-W" } + T (pb[123].a, b, 4); // { dg-bogus "\\\[-W" } + + T (pb[i].a, b, 0); + T (pb[i].a, b, 1); + T (pb[i].a, b, 2); + T (pb[i].a, b, 3); + T (pb[i].a, b, 4); + + + T (pb[-123].a2[0], b, 0); // { dg-bogus "\\\[-W" } + T (pb[-123].a2[0], b, 1); // { dg-bogus "\\\[-W" } + T (pb[-123].a2[0], b, 2); // { dg-bogus "\\\[-W" } + T (pb[-123].a2[0], b, 3); // { dg-bogus "\\\[-W" } + T (pb[-123].a2[0], b, 4); // { dg-bogus "\\\[-W" } + + T (pb[-2].a2[0], b, 0); // { dg-bogus "\\\[-W" } + T (pb[-2].a2[0], b, 1); // { dg-bogus "\\\[-W" } + T (pb[-2].a2[0], b, 2); // { dg-bogus "\\\[-W" } + T (pb[-2].a2[0], b, 3); // { dg-bogus "\\\[-W" } + T (pb[-2].a2[0], b, 4); // { dg-bogus "\\\[-W" } + + T (pb[-1].a2[0], b, 0); // { dg-bogus "\\\[-W" } + T (pb[-1].a2[0], b, 1); // { dg-bogus "\\\[-W" } + T (pb[-1].a2[0], b, 2); // { dg-bogus "\\\[-W" } + T (pb[-1].a2[0], b, 3); // { dg-bogus "\\\[-W" } + T (pb[-1].a2[0], b, 4); // { dg-bogus "\\\[-W" } + + T (pb[0].a2[0], b, 0); // { dg-bogus "\\\[-W" } + T (pb[0].a2[0], b, 1); // { dg-bogus "\\\[-W" } + T (pb[0].a2[0], b, 2); // { dg-bogus "\\\[-W" } + T (pb[0].a2[0], b, 3); // { dg-bogus "\\\[-W" } + T (pb[0].a2[0], b, 4); // { dg-bogus "\\\[-W" } + + T (pb[1].a2[0], b, 0); // { dg-bogus "\\\[-W" } + T (pb[1].a2[0], b, 1); // { dg-bogus "\\\[-W" } + T (pb[1].a2[0], b, 2); // { dg-bogus "\\\[-W" } + T (pb[1].a2[0], b, 3); // { dg-bogus "\\\[-W" } + T (pb[1].a2[0], b, 4); // { dg-bogus "\\\[-W" } + + T (pb[123].a2[0], b, 0); // { dg-bogus "\\\[-W" } + T (pb[123].a2[0], b, 1); // { dg-bogus "\\\[-W" } + T (pb[123].a2[0], b, 2); // { dg-bogus "\\\[-W" } + T (pb[123].a2[0], b, 3); // { dg-bogus "\\\[-W" } + T (pb[123].a2[0], b, 4); // { dg-bogus "\\\[-W" } + + T (pb[i].a2[0], b, 0); + T (pb[i].a2[0], b, 1); + T (pb[i].a2[0], b, 2); + T (pb[i].a2[0], b, 3); + T (pb[i].a2[0], b, 4); + + T (pb[-123].a2[1], b, 0); // { dg-bogus "\\\[-W" } + T (pb[-123].a2[1], b, 1); // { dg-bogus "\\\[-W" } + T (pb[-123].a2[1], b, 2); // { dg-bogus "\\\[-W" } + T (pb[-123].a2[1], b, 3); // { dg-bogus "\\\[-W" } + T (pb[-123].a2[1], b, 4); // { dg-bogus "\\\[-W" } + + T (pb[-2].a2[1], b, 0); // { dg-bogus "\\\[-W" } + T (pb[-2].a2[1], b, 1); // { dg-bogus "\\\[-W" } + T (pb[-2].a2[1], b, 2); // { dg-bogus "\\\[-W" } + T (pb[-2].a2[1], b, 3); // { dg-bogus "\\\[-W" } + T (pb[-2].a2[1], b, 4); // { dg-bogus "\\\[-W" } + + T (pb[-1].a2[1], b, 0); // { dg-bogus "\\\[-W" } + T (pb[-1].a2[1], b, 1); // { dg-bogus "\\\[-W" } + T (pb[-1].a2[1], b, 2); // { dg-bogus "\\\[-W" } + T (pb[-1].a2[1], b, 3); // { dg-bogus "\\\[-W" } + T (pb[-1].a2[1], b, 4); // { dg-bogus "\\\[-W" } + + T (pb[0].a2[1], b, 0); // { dg-bogus "\\\[-W" } + T (pb[0].a2[1], b, 1); // { dg-bogus "\\\[-W" } + T (pb[0].a2[1], b, 2); // { dg-bogus "\\\[-W" } + T (pb[0].a2[1], b, 3); // { dg-bogus "\\\[-W" } + T (pb[0].a2[1], b, 4); // { dg-bogus "\\\[-W" } + + T (pb[1].a2[1], b, 0); // { dg-bogus "\\\[-W" } + T (pb[1].a2[1], b, 1); // { dg-bogus "\\\[-W" } + T (pb[1].a2[1], b, 2); // { dg-bogus "\\\[-W" } + T (pb[1].a2[1], b, 3); // { dg-bogus "\\\[-W" } + T (pb[1].a2[1], b, 4); // { dg-bogus "\\\[-W" } + + T (pb[123].a2[1], b, 0); // { dg-bogus "\\\[-W" } + T (pb[123].a2[1], b, 1); // { dg-bogus "\\\[-W" } + T (pb[123].a2[1], b, 2); // { dg-bogus "\\\[-W" } + T (pb[123].a2[1], b, 3); // { dg-bogus "\\\[-W" } + T (pb[123].a2[1], b, 4); // { dg-bogus "\\\[-W" } + + T (pb[i].a2[1], b, 0); + T (pb[i].a2[1], b, 1); + T (pb[i].a2[1], b, 2); + T (pb[i].a2[1], b, 3); + T (pb[i].a2[1], b, 4); + + T (pb[i].a2[i], b, 0); + T (pb[i].a2[i], b, 1); + T (pb[i].a2[i], b, 2); + T (pb[i].a2[i], b, 3); + T (pb[i].a2[i], b, 4); +} + +void ptr_warn (struct B *pb, int i) +{ + T (pb[-987].a, a, 8); // { dg-warning "\\\[-Warray-bounds" } + T (pb[-654].a, a, 7); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[-2].a, a, 6); // { dg-warning "\\\[-Warray-bounds" } + T (pb[-2].a, a, 5); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[-1].a, a, 3); // { dg-warning "\\\[-Warray-bounds" } + T (pb[-1].a, a, 4); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[0].a, a, 3); // { dg-warning "\\\[-Warray-bounds" } + T (pb[0].a, a, 4); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[1].a, a, 5); // { dg-warning "\\\[-Warray-bounds" } + T (pb[1].a, a, 6); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[789].a, a, 7); // { dg-warning "\\\[-Warray-bounds" } + T (pb[789].a, a, 8); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[i].a, a, 3); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } + T (pb[i].a, a, 4); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } + T (pb[i].a, a, 5); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } + + + T (pb[-987].a, b, 10); // { dg-warning "\\\[-Warray-bounds" } + T (pb[-654].a, b, 9); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[-2].a, b, 8); // { dg-warning "\\\[-Warray-bounds" } + T (pb[-2].a, b, 7); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[-1].a, b, 6); // { dg-warning "\\\[-Warray-bounds" } + T (pb[-1].a, b, 5); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[0].a, b, 5); // { dg-warning "\\\[-Warray-bounds" } + T (pb[0].a, b, 6); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[1].a, b, 7); // { dg-warning "\\\[-Warray-bounds" } + T (pb[1].a, b, 8); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[789].a, b, 9); // { dg-warning "\\\[-Warray-bounds" } + T (pb[789].a, b, 10); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[i].a, b, 5); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } + T (pb[i].a, b, 6); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } + T (pb[i].a, b, 7); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } + + + T (pb[-987].a2[0], b, 10); // { dg-warning "\\\[-Warray-bounds" } + T (pb[-654].a2[0], b, 9); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[-2].a2[0], b, 8); // { dg-warning "\\\[-Warray-bounds" } + T (pb[-2].a2[0], b, 7); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[-1].a2[0], b, 6); // { dg-warning "\\\[-Warray-bounds" } + T (pb[-1].a2[0], b, 5); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[0].a2[0], b, 5); // { dg-warning "\\\[-Warray-bounds" } + T (pb[0].a2[0], b, 6); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[1].a2[0], b, 7); // { dg-warning "\\\[-Warray-bounds" } + T (pb[1].a2[0], b, 8); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[789].a2[0], b, 9); // { dg-warning "\\\[-Warray-bounds" } + T (pb[789].a2[0], b, 10); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[i].a2[0], b, 5); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } + T (pb[i].a2[0], b, 6); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } + T (pb[i].a2[0], b, 7); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } + + T (pb[-987].a2[1], b, 10); // { dg-warning "\\\[-Warray-bounds" } + T (pb[-654].a2[1], b, 9); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[-2].a2[1], b, 8); // { dg-warning "\\\[-Warray-bounds" } + T (pb[-2].a2[1], b, 7); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[-1].a2[1], b, 6); // { dg-warning "\\\[-Warray-bounds" } + T (pb[-1].a2[1], b, 5); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[0].a2[1], b, 5); // { dg-warning "\\\[-Warray-bounds" } + T (pb[0].a2[1], b, 6); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[1].a2[1], b, 7); // { dg-warning "\\\[-Warray-bounds" } + T (pb[1].a2[1], b, 8); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[789].a2[1], b, 9); // { dg-warning "\\\[-Warray-bounds" } + T (pb[789].a2[1], b, 10); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[i].a2[1], b, 5); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } + T (pb[i].a2[1], b, 6); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } + T (pb[i].a2[1], b, 7); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } + + T (pb[i].a2[i], b, 5); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } + T (pb[i].a2[i], b, 6); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } + T (pb[i].a2[i], b, 7); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } +} Index: gcc/testsuite/ChangeLog =================================================================== Index: gcc/gimple-ssa-warn-restrict.c =================================================================== --- gcc/gimple-ssa-warn-restrict.c (revision 276021) +++ gcc/gimple-ssa-warn-restrict.c (revision 276022) @@ -517,14 +517,8 @@ builtin_memref::set_base_and_offset (tree expr) struct S { char a, b[3]; } s[2]; strcpy (s[1].b, "1234"); REFOFF is set to s[1].b - (char*)s. */ - tree basetype = TREE_TYPE (TREE_TYPE (base)); - if (tree basesize = TYPE_SIZE_UNIT (basetype)) - if (TREE_CODE (basesize) == INTEGER_CST) - { - offset_int size = wi::to_offset (basesize); - offset_int off = tree_to_shwi (memrefoff); - refoff += size * (off / size); - } + offset_int off = tree_to_shwi (memrefoff); + refoff += off; } if (!integer_zerop (memrefoff))