PR4700 - remove shift by 0 warning

llvm-svn: 78488
This commit is contained in:
Ryan Flynn
2009-08-08 19:18:23 +00:00
parent 16cf1967f5
commit 2f08571e4d
3 changed files with 9 additions and 16 deletions

View File

@@ -1241,9 +1241,6 @@ def warn_shift_negative : Warning<
"shift count is negative">;
def warn_shift_gt_typewidth : Warning<
"shift count >= width of type">;
def warn_op_no_effect : Warning<
"operation has no effect">,
InGroup<DiagGroup<"all">>, DefaultIgnore;
def err_sizeof_nonfragile_interface : Error<
"invalid application of '%select{alignof|sizeof}1' to interface %0 in "

View File

@@ -4136,16 +4136,7 @@ QualType Sema::CheckShiftOperands(Expr *&lex, Expr *&rex, SourceLocation Loc,
llvm::APSInt Right;
// Check right/shifter operand
if (rex->isIntegerConstantExpr(Right, Context)) {
// Check left/shiftee operand
llvm::APSInt Left;
if (lex->isIntegerConstantExpr(Left, Context)) {
if (Left == 0 && Right != 0)
Diag(Loc, diag::warn_op_no_effect)
<< lex->getSourceRange() << rex->getSourceRange();
}
if (isCompAssign && Right == 0)
Diag(Loc, diag::warn_op_no_effect) << rex->getSourceRange();
else if (Right.isNegative())
if (Right.isNegative())
Diag(Loc, diag::warn_shift_negative) << rex->getSourceRange();
else {
llvm::APInt LeftBits(Right.getBitWidth(),

View File

@@ -12,15 +12,15 @@ void test() {
char c;
c = 0 << 0;
c = 0 << 1; // expected-warning {{no effect}}
c = 0 << 1;
c = 1 << 0;
c = 1 << -0;
c = 1 >> -0;
c = 1 << -1; // expected-warning {{shift count is negative}}
c = 1 >> -1; // expected-warning {{shift count is negative}}
c = 1 << c;
c <<= 0; // expected-warning {{no effect}}
c >>= 0; // expected-warning {{no effect}}
c <<= 0;
c >>= 0;
c <<= 1;
c >>= 1;
c <<= -1; // expected-warning {{shift count is negative}}
@@ -33,3 +33,8 @@ void test() {
c >>= CHAR_BIT+1; // expected-warning {{shift count >= width of type}}
(void)((long)c << CHAR_BIT);
}
#define a 0
#define ashift 8
enum { b = (a << ashift) };