http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50865

--- Comment #8 from joseph at codesourcery dot com <joseph at codesourcery dot 
com> 2011-10-25 16:18:12 UTC ---
On Tue, 25 Oct 2011, jaak at ristioja dot ee wrote:

> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50865
> 
> --- Comment #7 from Jaak Ristioja <jaak at ristioja dot ee> 2011-10-25 
> 16:08:19 UTC ---
> (In reply to comment #6)
> >       /* X % -Y is the same as X % Y.  */
> > (fold-const.c:fold_binary_loc) would probably be what's wrong here.
> 
> On the other hand
> https://www.securecoding.cert.org/confluence/display/seccode/INT32-C.+Ensure+that+operations+on+signed+integers+do+not+result+in+overflow#INT32-C.Ensurethatoperationsonsignedintegersdonotresultinoverflow-Modulo
> also refers to C99, saying that X % Y and X % -Y are equivalent.

Well, they are equivalent where they are both defined, or if you apply C99 
rules to infinite-precision integers.  The problem here is that INT_MIN % 
-1 is undefined (explicitly in C1X) and so a transformation of INT_MIN % 1 
into INT_MIN % -1 is unsafe (the other way round, transforming undefined 
behavior to defined, is fine at least in the absence of -ftrapv).

Reply via email to