[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 07:15:00 GMT 2016
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71224
--- Comment #5 from Iain Buclaw <ibuclaw at gdcproject dot org> ---
And thinking more about it, I don't think it even explains why this triggers
the warning:
---
if (nlength < pthis->length)
{
Array aggr = {pthis->length - nlength, pthis->ptr + nlength};
for (size_t key = 0; key < aggr.length; key++)
aggr.ptr[key] = 0;
}
---
But this works just fine.
---
if (nlength < pthis->length)
{
if (pthis->length >= nlength)
__builtin_unreachable();
Array aggr = {pthis->length - nlength, pthis->ptr + nlength};
for (size_t key = 0; key < aggr.length; key++)
aggr.ptr[key] = 0;
}
---
Surely the optimizer must be able to deduce that if the first condition is
true, then the second condition must always be a given?
More information about the Gcc-bugs
mailing list