[PATCH] tile: Fix up corner cases with signed relocations
Rich Felker
dalias@libc.org
Mon Sep 8 15:27:00 GMT 2014
On Mon, Sep 08, 2014 at 03:20:59PM +0000, Joseph S. Myers wrote:
> On Sat, 6 Sep 2014, Chris Metcalf wrote:
>
> > Right, sorry. On tile, the compiler will always generate a "shli" for
> > shifting an unknown value by a known constant, and shli is defined with
> > unsigned semantics on tile, so in practice this code generates the correct
> > value.
>
> In any case, the GNU C language defines signed shifts (as long as the
> shift amount is >= 0 and < width of type), although it may still be useful
> to avoid the cases that are outside what ISO C defines.
I don't think this is true. For example, in many versions of GCC, this
is (rightfully!) an infinite loop:
int i;
for (i=1; i>0; i<<=1);
On the other hand, defining a<<b when a is negative but a*(2**b) does
not overflow makes sense, and it's frustrating that the C standard
doesn't already define this (but see my workaround, i.e. just using
*(1<<b) or similar). But defining a<<b when it would overflow is
inconsistent and unreasonable.
Rich
More information about the Libc-alpha
mailing list