[cfe-commits] [PATCH RFC] Emit nsw/nuw flags for shl

Chris Lattner clattner at apple.com
Wed Jan 2 06:40:41 PST 2013


On Jan 2, 2013, at 4:10 AM, Richard Smith <richard at metafoo.co.uk> wrote:
>> In C99, we are not permitted to shift a 1 bit into the sign bit.
>> Under C++11's rules, shifting a 1 bit into the sign bit is
>> OK, but shifting a 1 bit out of it is not. (C89 and C++03 don't
>> define signed left shifts, so we use the C99 and C++11 rules there).
>> 
>> It looks to me that both C99 (6.5.7p4) and C++11 (5.8p2) have the same
>> rules for signed left shift.
> 
> See http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1457
> 
> In C++11, a signed left shift is nuw but not nsw.

Also, clang intentionally follow's GCC's lead and makes some shift behavior implementation-defined to be ok:
http://gcc.gnu.org/onlinedocs/gcc/Integers-implementation.html#Integers-implementation 

-Chris



More information about the cfe-commits mailing list