From 8045c7393bc83060f812d0f7b1221edbc767407c Mon Sep 17 00:00:00 2001 From: Ryan Flynn Date: Sat, 8 Aug 2009 19:18:23 +0000 Subject: [PATCH] PR4700 - remove shift by 0 warning git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@78488 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticSemaKinds.td | 3 --- lib/Sema/SemaExpr.cpp | 11 +---------- test/Sema/shift.c | 11 ++++++++--- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 591cf0a28a..fb36a717f4 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -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>, DefaultIgnore; def err_sizeof_nonfragile_interface : Error< "invalid application of '%select{alignof|sizeof}1' to interface %0 in " diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index cec1aeafac..f00ab5412d 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -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(), diff --git a/test/Sema/shift.c b/test/Sema/shift.c index 4c2b88a7f0..2516d1b861 100644 --- a/test/Sema/shift.c +++ b/test/Sema/shift.c @@ -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) }; + -- 2.40.0