https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90607
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |msebor at gcc dot gnu.org --- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> --- There's not really anything wrong here - we just diagnose things twice for void fn3 (void) { unsigned char a[16], b[16], c[16]; int i; bar (b); for (i = 0; i < (int) (sizeof (a) / sizeof (a[0])); i++) /* { dg-message "note: within this loop" } */ { c[i + 8] = b[i]; /* { dg-warning "8 invokes undefined behavior" } */ a[i + 8] = b[i + 8]; } bar (a); bar (c); } first we see /space/rguenther/src/svn/trunk2/gcc/testsuite/gcc.dg/pr53265.c: In function ‘fn3’: /space/rguenther/src/svn/trunk2/gcc/testsuite/gcc.dg/pr53265.c:40:16: warning: iteration 8 invokes undefined behavior [-Waggressive-loop-optimizations] /space/rguenther/src/svn/trunk2/gcc/testsuite/gcc.dg/pr53265.c:38:3: note: within this loop and then later, after loop-distribution makes undefined memcpy calls out of this loop invoking undefined behavior we warn about that again: /space/rguenther/src/svn/trunk2/gcc/testsuite/gcc.dg/pr53265.c: In function ‘fn3’: cc1: warning: ‘__builtin_memcpy’ forming offset [17, 24] is out of the bounds [0, 16] of object ‘c’ with type ‘unsigned char[16]’ [-Warray-bounds] /space/rguenther/src/svn/trunk2/gcc/testsuite/gcc.dg/pr53265.c:34:31: note: ‘c’ declared here cc1: warning: ‘__builtin_memcpy’ forming offset [17, 24] is out of the bounds [0, 16] of object ‘a’ with type ‘unsigned char[16]’ [-Warray-bounds] /space/rguenther/src/svn/trunk2/gcc/testsuite/gcc.dg/pr53265.c:34:17: note: ‘a’ declared here generally warning about stmts with UNKNOWN_LOCATION isn't very helpful (the generated memcpy calls fall under this category). We might want to improve the location here (use the location of the stmt doing the store?). With adjusting the location we see /space/rguenther/src/svn/trunk2/gcc/testsuite/gcc.dg/pr53265.c:40:16: warning: ‘__builtin_memcpy’ forming offset [17, 24] is out of the bounds [0, 16] of object ‘c’ with type ‘unsigned char[16]’ [-Warray-bounds] /space/rguenther/src/svn/trunk2/gcc/testsuite/gcc.dg/pr53265.c:34:31: note: ‘c’ declared here /space/rguenther/src/svn/trunk2/gcc/testsuite/gcc.dg/pr53265.c:41:16: warning: ‘__builtin_memcpy’ forming offset [17, 24] is out of the bounds [0, 16] of object ‘a’ with type ‘unsigned char[16]’ [-Warray-bounds] /space/rguenther/src/svn/trunk2/gcc/testsuite/gcc.dg/pr53265.c:34:17: note: ‘a’ declared here which is of course nicer and can be tested for. I'll simply amend the testcase.