This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug middle-end/71224] Looping over local copy of aggregate invokes undefined behavior -Waggressive-loop-optimizations


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?

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]