On Sat, Dec 24, 2022 at 3:27 PM Camm Maguire <[email protected]> wrote: > Greetings, and thank you so much for pinning down the offending > optimization flag, reducing the bug report, and forwarding the response! > > I'm not convinced (yet at least) that this code being classified as > 'undefined' means gcc is not in error. Signed and unsigned integer > arithmetic of any precision is defined in C to loop around extremal > values, i.e. to act as modular operations. This code acknowledges this > and relies upon it -- runtime 'overflows' are not a mistake. Perhaps > there is some better syntax to make this clear?
My understanding is that *unsigned* integer overflow is well-defined, and simply wraps around as you describe. *Signed* integer overflow, on the other hand, is undefined behavior. This article supports that view: https://en.wikipedia.org/wiki/Integer_overflow (see the section on "Inconsistent behavior"). This also means that, while -fno-tree-vrp may cause the symptoms to disappear, the correct flag to use is -fwrapv. Better would be to make sure that overflow only happens for unsigned integer operations. Regards, -- Jerry James http://www.jamezone.org/
