This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: GCC optimizes integer overflow: bug or feature?
- From: Denis Vlasenko <vda dot linux at googlemail dot com>
- To: Andrew Haley <aph at redhat dot com>
- Cc: gcc at gcc dot gnu dot org, Paolo Bonzini <bonzini at gnu dot org>, bug-gnulib at gnu dot org
- Date: Tue, 19 Dec 2006 22:25:41 +0100
- Subject: Re: GCC optimizes integer overflow: bug or feature?
- References: <20061218230847.GD3824@iam.uni-bonn.de> <200612191948.36039.vda.linux@googlemail.com> <17800.14335.643248.648942@zebedee.pink>
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