> You could emit a warning if the entire range overflows (i.e. both lower
> and upper bound calculations overflow), since that means that the calculation
> of a+b necessarily overflows.

True, but the interesting question is not whether a computation NECESSARILY
overflows, but whether it MIGHT overflow in some case that's actually
executed by the program.

The case of a computation necessarily overflowing is quite rare (and is
almost always a bug in the code anyway since that would be a bizarre way to
code something).  The problem is that most computations that look like the
MIGHT overflow don't.  After all, if I just write:

        int sum (int a, int b) { return a + b;}

There's absolutely no way a compiler could EVER tell if that's relying on
wrapping semantics and issuing a warning that a+b might overflow would be
completely useless.  Luckily, that's not a question we need to answer.  The
question we care about is if we're making some TRANSFORMATION to the
program that would change the behavior of the program if it required
wrapping semantics. That can't be determined when we GENERATE a range, only
when we USE that range for something.

Reply via email to