https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102690
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Last reconfirmed| |2021-10-12 Status|UNCONFIRMED |NEW Ever confirmed|0 |1 --- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> --- Oh, I can probably fix the FAIL: g++.dg/warn/Warray-bounds-16.C -std=gnu++17 scan-tree-dump-not optimized "goto" since the expected optimization is not valid. But the IMHO bogus excess error remains, see PR101480 for an analysis. Quote: -- What we see is the global variable construction function which accesses just 'a', and yes, the call to 'new' is considered clobbering global variables (including 'a'): <bb 2> [local count: 1073741824]: MEM[(struct __as_base &)&a] ={v} {CLOBBER}; a.m = 0; _5 = operator new [] (0); a.p = _5; goto <bb 4>; [100.00%] <bb 3> [local count: 8687547547]: _7 = (long unsigned int) i_6; _8 = _7 * 4; _9 = _5 + _8; MEM[(int *)_9] = 0; i_10 = i_6 + 1; <bb 4> [local count: 9761289362]: # i_6 = PHI <0(2), i_10(3)> _11 = a.m; if (i_6 < _11) goto <bb 3>; [89.00%] else goto <bb 5>; [11.00%] <bb 5> [local count: 1073741824]: return; I suppose implementing the global operator new as accessing a.m would be valid as IIRC lifetime of a starts when the CTOR is invoked, not when it finished (otherwise the CTOR could not access the variable itself). We somehow conclude that _9: void * [1B, +INF] EQUIVALENCES: { } (0 elements) possibly because it cannot be NULL (?): extract_range_from_stmt visiting: _5 = operator new [] (0); Found new range for _5: void * [1B, +INF] marking stmt to be not simulated again (huh?) and then the -Warray-bounds warning concludes the access is always outside of the allocated area. I suspect when we'd arrive at VARYING we'd not issue the warning even when the access would always extend beyond a zero-sized allocation. --