https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104165
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- URL| |https://bugzilla.redhat.com | |/show_bug.cgi?id=2051783 Keywords| |missed-optimization --- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> --- See also another similar test case reduced in https://bugzilla.redhat.com/show_bug.cgi?id=2051783: #include <algorithm> bool cond; int foo; int func (void) { int a[3], qa = 0; for(int i = 0; i < 3; i++) if (cond) a[qa++] = foo; std::sort (a, a + qa); return 0; } The warning is issued for the synthesized call to std::__insertion_sort.isra() in basic block 9 (vrp1 output): <bb 9> [local count: 71766220]: std::__insertion_sort.isra (&a, &MEM <int[3]> [(void *)&a + 64B]); <<< -Warray-bounds goto <bb 14>; [100.00%] The block is unreachable but GCC is unable to determine that from the loop. Adding an annotation just after the loop asserting that avoids the warning and also improves the emitted object code. The same warning triggers in GCC 11 with -Wsystem-headers. The difference in GCC 12 is that -Wsystem-headers no longer disables warnings for code defined in system headers that's inlined into user code.