[cfe-commits] r108388 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/Sema/exprs.c

Chris Lattner sabre at nondot.org
Wed Jul 14 17:26:43 PDT 2010


Author: lattner
Date: Wed Jul 14 19:26:43 2010
New Revision: 108388

URL: http://llvm.org/viewvc/llvm-project?rev=108388&view=rev
Log:
restrict the && -> & warning to cover a case daniel noted.
Don't warn about "logically bool" expressions on the RHS,
even if they fold to a constant.

Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/Sema/exprs.c

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=108388&r1=108387&r2=108388&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Jul 14 19:26:43 2010
@@ -5742,6 +5742,10 @@
   // is a constant.
   if (lex->getType()->isIntegerType() && !lex->getType()->isBooleanType() &&
       rex->getType()->isIntegerType() && rex->isEvaluatable(Context) &&
+      // Don't warn if the RHS is a (constant folded) boolean expression like
+      // "sizeof(int) == 4".
+      !rex->isKnownToHaveBooleanValue() &&
+      // Don't warn in macros.
       !Loc.isMacroID())
     Diag(Loc, diag::warn_logical_instead_of_bitwise)
      << rex->getSourceRange()

Modified: cfe/trunk/test/Sema/exprs.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/exprs.c?rev=108388&r1=108387&r2=108388&view=diff
==============================================================================
--- cfe/trunk/test/Sema/exprs.c (original)
+++ cfe/trunk/test/Sema/exprs.c Wed Jul 14 19:26:43 2010
@@ -144,4 +144,6 @@
 
 int test20(int x) {
   return x && 4; // expected-warning {{use of logical && with constant operand; switch to bitwise & or remove constant}}
+
+  return x && sizeof(int) == 4;  // no warning.
 }





More information about the cfe-commits mailing list