ubsan: csky: left shift cannot be represented in type 'int'

Alan Modra amodra@gmail.com
Wed Dec 11 14:34:00 GMT 2019


On Wed, Dec 11, 2019 at 02:12:17PM +0000, Michael Matz wrote:
> Hi,
> 
> On Wed, 11 Dec 2019, Alan Modra wrote:
> 
> >    if (dis_info.info->endian == BFD_ENDIAN_BIG)
> > -    while (n--)
> > -      val |= buf[n] << (n*8);
> > -  else
> >      for (i = 0; i < n; i++)
> > -      val |= buf[i] << (i*8);
> > +      val = val << 8 | (buf[i] & 0xff);
> > +  else
> > +    for (i = n - 1; i >= 0; i--)
> > +      val = val << 8 | (buf[i] & 0xff);
> 
> But the '& 0xff' is really a no-op here, as you said: buf[i] is unsigned 
> char.

Thanks for reviewing!  There is quite some risk that fixing these
ubsan warnings will introduce bugs, so I do appreciate people
critically looking at my bit twiddling patches.

Yes, we can presume char is eight bits.

-- 
Alan Modra
Australia Development Lab, IBM



More information about the Binutils mailing list