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 Brook
Subject: Re: GCC optimizes integer overflow: bug or feature?
Date: Tue, 19 Dec 2006 22:58:23 +0000
User-agent: KMail/1.9.5

On Tuesday 19 December 2006 22:39, Denis Vlasenko wrote:
> On Tuesday 19 December 2006 22:46, Paul Brook wrote:
> > > Compiler can optimize it any way it wants,
> > > as long as result is the same as unoptimized one.
> >
> > We have an option for that. It's called -O0.
> >
> > Pretty much all optimization will change the behavior of your program.
>
> Even x*2 -> x+x? Or unsigned x/8 -> x>>3 ?
>
> I am perfectly happy with registers too. Not nesessarily with same size,
> even. (Just proprerly autoextend signed values a-la AMD64).
>
> Do not put words in my mouth. I said nothing about volatility
> and multithreading.

My point exactly. You said you wanted results "the same as unoptimized".
That was an unqualified statement, so the only reasonably assumption is that 
you meant the results should be the same in all cases, for all code.

And yes, in extreme circumstances these transformations could be considered 
unsafe. Particularly if one form requires a libcall.

As an even more extreme case it's theoretically possible to break some 
cryptographic algorithms by observing the power consumption variations as the 
CPU miltiplier unit is powered up to do the multiply.

If what you really meant was "don't break my code", you're going to have to be 
a lot more specific about exactly what additional guarantees you require.

Paul




reply via email to

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