[cfe-commits] [PATCH RFC] Emit nsw/nuw flags for shl
Richard Smith
richard at metafoo.co.uk
Wed Jan 2 04:10:56 PST 2013
On Sun, Dec 30, 2012 at 4:30 PM, Xi Wang <xi.wang at gmail.com> wrote:
> The attached patch adds nsw/nuw flags to signed left shift. This is
> useful for LLVM-based tools to distinguish between signed and unsigned
> left shift operations.
>
> The patch is also available at:
>
> https://github.com/xiw/clang/compare/shl
>
> BTW, I am confused by some comments in ScalarExprEmitter::EmitShl().
>
> 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.
More information about the cfe-commits
mailing list