This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Document arithmetic overflow semantics
On Thu, Feb 13, 2003 at 07:22:42AM -0700, Roger Sayle wrote:
>
> Hi Richard,
> > I think that's backwards. If program in C, C++, or Ada generates an
> > overflow, that program is undefined. That means the optimizer can do
> > anything it wants to the program, which, in turn, means that the optimizer
> > can assume that overflow *does not* occur, and that allows a lot more
> > optimizations.
>
> I completely disagree, and so do GCC's patch reviewers. The behaviour
> of a program with optimization should always be the same as its behaviour
> without optimization.
Since the behaviour of a program includes things like the time it takes
to execute a program as well as the exact sequence of memory locations
that are read from/written to, and many other similar things this would
imply that optimization is essentially not allowed to do anything.
Optimization is certainly allowed to change the behaviour of a program,
anything else would be just plain silly since the very purpose of
optimization is to change the behaviour of a program (in particular the
execution time of the program.)
What optimization is not allowed to do is change the semantics of a
program, but in the case of undefined behaviour there is no semantics
to preserve and therefore the optimizer can do whatever it damn well
pleases in that case.
--
<Insert your favourite quote here.>
Erik Trulsson
ertr1013@student.uu.se