[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: changing "configure" to default to "gcc -g -O2 -fwrapv ..."
From: |
Vincent Lefevre |
Subject: |
Re: changing "configure" to default to "gcc -g -O2 -fwrapv ..." |
Date: |
Sun, 31 Dec 2006 15:16:21 +0100 |
User-agent: |
Mutt/1.5.13-vl-r14963 (2006-12-20) |
On 2006-12-31 08:25:23 -0500, Richard Kenner wrote:
> > > > I suppose there is
> > > >
> > > > *hv = (HOST_WIDE_INT) -(unsigned HOST_WIDE_INT) h1;
> > > >
> > > > to make it safe.
> > >
> > > Can't that conversion overflow?
> >
> > Not on a two's complement machine,
>
> Then I'm confused about C's arithmetic rules. Suppose h1 is 1. It's
> cast to unsigned, so stays as 1. Now we do unary minus in unsigned.
> That's ~0 because it's done mod 2**32, but interpreted as a POSITIVE
> number. Now, that positive number overflows when converted to signed
> (the intent is for that overflow make it negative). Am I missing
> something (quite likely!)?
No, this is not portable. On the same kind of code, even the wrap
may hide a bug, e.g. when one has:
*hv = -(unsigned HOST_WIDE_INT) h1;
where *hv is signed, but not the same type as the original one.
For instance, such a code will work on a 32-bit machine, but not
necessarily on a 64-bit machine. Now, will GCC do anything to
make such code work on such machines? I doubt that.
--
Vincent Lefèvre <address@hidden> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon)
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", (continued)
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Bernd Schmidt, 2006/12/31
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Gabriel Dos Reis, 2006/12/31
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Joe Buck, 2006/12/30
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Richard Kenner, 2006/12/30
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Joe Buck, 2006/12/31
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Paul Eggert, 2006/12/31
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Richard Kenner, 2006/12/31
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...",
Vincent Lefevre <=
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Eric Blake, 2006/12/30
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Richard Kenner, 2006/12/30
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Gabriel Dos Reis, 2006/12/30
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Richard Guenther, 2006/12/30
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Gabriel Dos Reis, 2006/12/30
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Richard Guenther, 2006/12/30
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Gabriel Dos Reis, 2006/12/30
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Robert Dewar, 2006/12/30
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Gabriel Dos Reis, 2006/12/30
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Andrew Pinski, 2006/12/30