basic VRP min/max range overflow question
Joseph S. Myers
joseph@codesourcery.com
Sat Jun 18 16:19:00 GMT 2005
On Sat, 18 Jun 2005, Paul Schlie wrote:
> Maybe I didn't phrase my statement well; I fully agree with the cited
> paragraph above which specifically says a program containing unspecified
> behavior "shall be a correct program and act in accordance with
> 5.1.2.3". Which specifies program execution, in terms of an abstract machine
> model, which correspondingly requires:
You appear to have confused unspecified behavior (where the possibilities
are bounded) and undefined behavior (where the possibilities are
unbounded). On *undefined* behavior (such as signed integer overflow),
*this International Standard imposes no requirements*. If a program
execution involved undefined behavior, *there are no requirements on its
execution, even before the undefined behavior occurs in the abstract
machine*. Therefore the compiler assumes that you only ever pass it
programs which do not execute undefined behavior. If a possible execution
might involve undefined behavior, the compiler presumes that the
programmer knows more than it can prove and knows that the relevant
circumstances cannot arise at execution. For example, a correct program
never involves overflow of a signed loop variable, so the compiler
presumes that the programmer proved that the loop variable can never
overflow at execution and uses this information to optimize the loop: it
cannot prove it by itself but using the presumption that the program is
correct it can optimize the program better.
The traditional form of undefined behavior is for demons to fly out of
your nose. We just haven't yet got -fnasal-demons working reliably but it
would be conforming for it to be on by default. If you are lucky, it will
happen anyway without that option.
http://groups.google.com/groups?hl=en&selm=10195%40ksr.com
--
Joseph S. Myers http://www.srcf.ucam.org/~jsm28/gcc/
jsm@polyomino.org.uk (personal mail)
joseph@codesourcery.com (CodeSourcery mail)
jsm28@gcc.gnu.org (Bugzilla assignments and CCs)
More information about the Gcc
mailing list