https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101480
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |amacleod at redhat dot com --- Comment #18 from Richard Biener <rguenth at gcc dot gnu.org> --- (In reply to Martin Sebor from comment #16) > (In reply to Richard Biener from comment #14) > ... > > the testcase does > > > > m = i; > > p = (int*) new unsigned char [sizeof (int) * m]; > > > > for (int i = 0; i < m; i++) > > new (p + i) int (); > > > > and we likely have to assume that 'new' changes 'm'. > > Why? Because of the flow-insensitivity of the alias analysis? > > m is a member of the class whose ctor has the loop above. Neither the > enclosing object nor the member actually escapes (the operator new to which > p is passed in the loop is the nonreplaceable placement new), so there is no > way it can be changed. 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. I'm going to ignore this diagnostic issue, it concerns the 'offrange' code I'm not familiar with at all (and maybe the value-range code for which I now have to say sth similar).