[cfe-commits] r96326 - /cfe/trunk/lib/AST/Expr.cpp

John McCall rjmccall at apple.com
Mon Feb 15 20:10:54 PST 2010


Author: rjmccall
Date: Mon Feb 15 22:10:53 2010
New Revision: 96326

URL: http://llvm.org/viewvc/llvm-project?rev=96326&view=rev
Log:
White-list comma expressions with the literal 0 as their RHS against
unused-value warnings.  This is a common macro idiom.


Modified:
    cfe/trunk/lib/AST/Expr.cpp

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=96326&r1=96325&r2=96326&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Mon Feb 15 22:10:53 2010
@@ -827,9 +827,17 @@
   case BinaryOperatorClass: {
     const BinaryOperator *BO = cast<BinaryOperator>(this);
     // Consider comma to have side effects if the LHS or RHS does.
-    if (BO->getOpcode() == BinaryOperator::Comma)
+    if (BO->getOpcode() == BinaryOperator::Comma) {
+      // ((foo = <blah>), 0) is an idiom for hiding the result (and
+      // lvalue-ness) of an assignment written in a macro.
+      if (IntegerLiteral *IE =
+            dyn_cast<IntegerLiteral>(BO->getRHS()->IgnoreParens()))
+        if (IE->getValue() == 0)
+          return false;
+
       return (BO->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx) ||
               BO->getLHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx));
+    }
 
     if (BO->isAssignmentOp())
       return false;





More information about the cfe-commits mailing list