bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GCC optimizes integer overflow: bug or feature?


From: Paul Eggert
Subject: Re: GCC optimizes integer overflow: bug or feature?
Date: Tue, 19 Dec 2006 01:36:30 -0800
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.4 (gnu/linux)

Ralf Wildenhues <address@hidden> writes:

> Maybe it's also just an unintended bug I happened to observe
> (and take for given behavior)?

I read up a bit more and it looks like it is intended behavior.
However, this disruptive change isn't documented in
<http://gcc.gnu.org/gcc-4.2/changes.html>, which is where I assume
stuff like this should be mentioned.  (In Capital Letters.  :-)

The irony of this is that I ran into this problem in 1992 or so, and
had the problem fixed in GCC back then.  The problem was that the DEC
SRC Modula-3 runtime had code that looked something like this:

  int i, n; ...
  if (0 < i && n + i < n)
    report_integer_overflow ();

GCC 2.2.2 came out with a new optimization (on the SPARC, with -O)
that decided to optimize away the entire `if' statement, on the
grounds that the only way that the 'if' could succeed was for integer
overflow to occur, and the resulting behavior was undefined.

Obviously C89 allows this optimization, as does C99 without LIA-1.
But a reasonable amount of C code will break if you do it, and some of
this code is in glibc and has been in glibc for quite some time.  As
well as in other programs like the Modula-3 implementation.

This is why the optimization was removed from GCC soon after GCC 2.2.2
came out.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]