[Bug middle-end/71224] Looping over local copy of aggregate invokes undefined behavior -Waggressive-loop-optimizations
ibuclaw at gdcproject dot org
gcc-bugzilla@gcc.gnu.org
Mon May 23 06:52:00 GMT 2016
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71224
--- Comment #4 from Iain Buclaw <ibuclaw at gdcproject dot org> ---
(In reply to Andrew Pinski from comment #3)
> I think the warning is correct and here is why:
> If we look at the final code which is produced on the tree level:
>
> _3 = pthis_2(D)->length;
> _4 = _3 + 1;
> if (_3 > _4)
> goto <bb 4>;
> else
> goto <bb 3>;
>
> If pthis_2(D)->length was UINT_MAX, then that UINT_MAX > UINT_MAX + 1 would
> be true while for all other cases, it is false.
Yeah, I can see overflow as a possibility, but it should never happen. I'd be
surprised if there is a system out there can return success from a
malloc((size_t) -1). :-)
If it is correctly detecting overflow, should it warn that instead?
Also, if the behaviour is correct, I'd expect this to trigger it also.
---
if (nlength < pthis->length)
{
for (size_t key = 0; key < pthis->length - nlength; key++)
pthis->ptr[key + nlength] = 0;
}
---
More information about the Gcc-bugs
mailing list