This is the mail archive of the gcc@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]

Re: basic VRP min/max range overflow question


> They need not wrap around.  People that are actually on the C standards
> committee have told you this multiple times.

Yes, and may clearly produce erroneous results if the value ranges
are not consistent with the factual behavior of an implementation, i.e.:

 int x;
 volatile int v;

 x = (v ? 0 : INT_MAX) + 1;  // [1, INT_MAX] (without -fwrapv)

 if (x <= 0)                 // Which may be erroneously
  printf("%i is <= 0.", x);  // optimized away, with this.
 else
  printf("%i is > 0.", x);   // Leaving only this in error.

As regardless of the value of x produced by an implementation, it's wrong
to presume a result which is not consistent with the factual behavior of
that implementation.  Therefore -fwrapv must be presumed for all targets
which effectively wrap signed integer overflows, as otherwise non-
conformant behaviors may result. (i.e. effectively all present targets)

As I doubt "-2147483648 > 0" or "0 > 0" (as may otherwise result from
typical 2's or 1's complement implementations which silently wrap
overflows), can be justified as being a valid conforming result in any
circumstance. (and confess that I have nothing more to add if not obvious).



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