qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] undefined behavior of signed left shifts (was Re: [PULL


From: Joseph Myers
Subject: Re: [Qemu-devel] undefined behavior of signed left shifts (was Re: [PULL 00/40] ppc patch queue 2015-06-03)
Date: Fri, 5 Jun 2015 17:21:16 +0000
User-agent: Alpine 2.10 (DEB 1266 2009-07-14)

On Fri, 5 Jun 2015, Paolo Bonzini wrote:

> The GCC manual says "GCC does not use the latitude given in C99 and C11
> only to treat certain aspects of signed '<<' as undefined, but this is
> subject to change".  It would certainly be nice if they removed the
> "this is subject to change" part.

The correct statement would be more complicated.  That is: the value 
returned is as documented, without that latitude being used for 
*optimization*, but (a) -fsanitize=undefined (and its subcase 
-fsanitize=shift) intends to follow exactly what the different standards 
specify when giving runtime errors and (b) the cases that are undefined 
are thereby not considered integer constant expressions (with consequent 
pedwarns-if-pedantic in various cases, and corner case effects on what's a 
null pointer constant).  (The only "subject to change" would be that if 
there are still missing cases from the runtime detection or the not 
treating as integer constant expressions, then those missing cases may be 
fixed.  I don't think it would be a good idea to add optimizations on this 
basis - for example, optimizations of x * 2 based on undefined overflow 
should not be applied to x << 1.)

-- 
Joseph S. Myers
address@hidden



reply via email to

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