https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104165
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW CC| |msebor at gcc dot gnu.org Last reconfirmed| |2022-01-21 Blocks| |56456 Summary|[12 Regression] Incorrectly |[12 Regression] |identifying array bounds |-Warray-bounds for |with -O2 |unreachable code inlined |-Werror=array-bounds |from std::sort() Ever confirmed|0 |1 --- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> --- The warning triggers for the out of bounds pointer addition in &f.148 + 64 for an array of 16 chars: int foo (int n) { unsigned char f.148[16]; ... <bb 8> [local count: 116203857]: _25 = ASSERT_EXPR <_15, _15 != &f.148>; _6 = (signed long) _14; _19 = _6 /[ex] 4; __n.3_20 = (long unsigned int) _19; _21 = __builtin_clzl (__n.3_20); _22 = 63 - _21; _23 = (long int) _22; _24 = _23 * 2; std::__introsort_loop<int*, long int, __gnu_cxx::__ops::_Iter_comp_iter<bar(int, int)::<lambda(int, int)> > > (&f.148, _25, _24, __comp); if (_14 > 64) goto <bb 9>; [50.00%] else goto <bb 15>; [50.00%] <bb 9> [local count: 58101929]: std::__insertion_sort.constprop (&f.148, &MEM <int[0:D.48109]> [(void *)&f.148 + 64B]); <<< -Warray-bounds goto <bb 14>; [100.00%] The basic block is removed later, in CCP3, as unreachable: Removing basic block 8 ;; basic block 8, loop depth 0 ;; pred: std::__insertion_sort.constprop (&f.148, &MEM <int[0:D.48109]> [(void *)&f.148 + 64B]); if (&MEM <int[0:D.48109]> [(void *)&f.148 + 64B] != _15) goto <bb 9>; [89.00%] else goto <bb 13>; [11.00%] ;; succ: 9 ;; 13 The warning runs too early to benefit from the subsequent simplification. This is one instance of a false positive that something like __builtin_warning() would cure. GCC 11 emits (and eliminates) the same invalid expression but the warning is suppressed because in GCC 11 -Warray-bounds wasn't issued code inlined from system headers. That's a GCC 12 change. Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56456 [Bug 56456] [meta-bug] bogus/missing -Warray-bounds