[Libreoffice-commits] core.git: compilerplugins/clang

Stephan Bergmann sbergman at redhat.com
Mon Mar 2 08:17:01 PST 2015


 compilerplugins/clang/literaltoboolconversion.cxx |   21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

New commits:
commit 9e6c2369a177f2df16b046d7342fae8b26511bbb
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Mon Mar 2 17:14:33 2015 +0100

    plugin:literaltoboolconversion: Recurse into comma operator's rhs
    
    ...inspired by <http://www.viva64.com/en/b/0308/#ID0EE4BI>'s V639 finding.
    
    Change-Id: I3b49f00dd4a593ed0b94d81398fa89ff64f6c79b

diff --git a/compilerplugins/clang/literaltoboolconversion.cxx b/compilerplugins/clang/literaltoboolconversion.cxx
index 07a7e50..caae89b 100644
--- a/compilerplugins/clang/literaltoboolconversion.cxx
+++ b/compilerplugins/clang/literaltoboolconversion.cxx
@@ -43,6 +43,15 @@ bool LiteralToBoolConversion::VisitImplicitCastExpr(
         return true;
     }
     Expr const * sub = expr->getSubExpr()->IgnoreParenCasts();
+    Expr const * expr2;
+    for (;;) {
+        BinaryOperator const * op = dyn_cast<BinaryOperator>(sub);
+        if (op == nullptr || op->getOpcode() != BO_Comma) {
+            break;
+        }
+        expr2 = op->getRHS()->IgnoreParenCasts();
+        sub = expr2;
+    }
     if (sub->getType()->isBooleanType()) {
         return true;
     }
@@ -113,9 +122,9 @@ bool LiteralToBoolConversion::VisitImplicitCastExpr(
             report(
                 DiagnosticsEngine::Warning,
                 "implicit conversion (%0) of literal of type %1 to %2",
-                expr->getLocStart())
+                expr2->getLocStart())
                 << expr->getCastKindName() << expr->getSubExpr()->getType()
-                << expr->getType() << expr->getSourceRange();
+                << expr->getType() << expr2->getSourceRange();
         }
     } else if (sub->isNullPointerConstant(
                    compiler.getASTContext(), Expr::NPC_ValueDependentIsNull)
@@ -130,9 +139,9 @@ bool LiteralToBoolConversion::VisitImplicitCastExpr(
             DiagnosticsEngine::Warning,
             ("implicit conversion (%0) of null pointer constant of type %1 to"
              " %2"),
-            expr->getLocStart())
+            expr2->getLocStart())
             << expr->getCastKindName() << expr->getSubExpr()->getType()
-            << expr->getType() << expr->getSourceRange();
+            << expr->getType() << expr2->getSourceRange();
     } else if (!sub->isValueDependent()
                && sub->isIntegerConstantExpr(res, compiler.getASTContext()))
     {
@@ -140,9 +149,9 @@ bool LiteralToBoolConversion::VisitImplicitCastExpr(
             DiagnosticsEngine::Warning,
             ("implicit conversion (%0) of integer constant expression of type"
              " %1 with value %2 to %3"),
-            expr->getLocStart())
+            expr2->getLocStart())
             << expr->getCastKindName() << expr->getSubExpr()->getType()
-            << res.toString(10) << expr->getType() << expr->getSourceRange();
+            << res.toString(10) << expr->getType() << expr2->getSourceRange();
     }
     return true;
 }


More information about the Libreoffice-commits mailing list