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: Denis Vlasenko
Subject: Re: GCC optimizes integer overflow: bug or feature?
Date: Tue, 19 Dec 2006 22:25:41 +0100
User-agent: KMail/1.8.2

On Tuesday 19 December 2006 20:05, Andrew Haley wrote:
> Denis Vlasenko writes:
>  > 
>  > I wrote this just a few days ago:
>  > 
>  >         do {
>  >                 int32_t v1 = v << 1;
>  >                 if (v < 0) v1 ^= mask;
>  >                 v = v1;
>  >                 printf("%10u: %08x\n", c++, v);
>  >         } while (v != 1);
>  > 
>  > I would become rather sad if this will stop compiling correctly.
> 
> I can understand the objections to do with "dusty deck" code that
> hasn't been looked at for aeons, but in the case of code that you
> wrote so recently, given that you understand the issue, why not simply
> use the standard idiom?

I want sane compiler. One in which N-bit integer variables stay exactly N-bit.
Without "magic" N+1 bit which is there "somethimes". a*2/2:
If I say "multiply by 2 and _after that_ divide by 2,
I meant that. Compiler can optimize it any way it wants,
as long as result is the same as unoptimized one.

Above: v is a signed entity. I expect (v < 0) to be equal to
"most significant bit is set". It's not about standards.
It's about sanity.
--
vda




reply via email to

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