[PATCH] D10938: [Sema] Warn when shifting a negative value
Richard Smith
richard at metafoo.co.uk
Sun Jul 5 21:47:40 PDT 2015
rsmith accepted this revision.
This revision is now accepted and ready to land.
LGTM
================
Comment at: lib/Sema/SemaExpr.cpp:7940-7941
@@ -7939,4 +7939,4 @@
if (LHS.get()->isValueDependent() ||
- !LHS.get()->isIntegerConstantExpr(Left, S.Context) ||
+ !LHS.get()->EvaluateAsInt(Left, S.Context) ||
LHSType->hasUnsignedIntegerRepresentation())
return;
----------------
While you're here, please reverse the order of these two lines. It's much cheaper to check for an unsigned type than to evaluate the expression.
================
Comment at: test/Sema/shift.c:42
@@ -41,3 +41,3 @@
i = 1 << (WORD_BIT - 1); // expected-warning {{sets the sign bit of the shift expression}}
- i = -1 << (WORD_BIT - 1);
+ i = -1 << (WORD_BIT - 1); // expected-warning {{shifting a negative signed value is undefined}}
i = 0 << (WORD_BIT - 1);
----------------
Please also add a test that we even warn for shifting a negative value by zero.
Repository:
rL LLVM
http://reviews.llvm.org/D10938
More information about the cfe-commits
mailing list