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

Stephan Bergmann sbergman at redhat.com
Tue Feb 25 10:05:28 PST 2014


 compilerplugins/clang/literaltoboolconversion.cxx |   29 +++++++++-------------
 1 file changed, 12 insertions(+), 17 deletions(-)

New commits:
commit 907ffec4907eac13bfe51c98d4f27b433b7bb36f
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Tue Feb 25 19:03:12 2014 +0100

    isIntegerConstantExpr is more general than IntegerLiteral
    
    ...and subsumes not only the use of __builtin_expect in assert, but also the use
    of __builtin_constant_p (nested) in htonl on Mac OS X.
    
    Change-Id: I62ab6c71c42948c4ec1e2f1e1d23223cbb13416b

diff --git a/compilerplugins/clang/literaltoboolconversion.cxx b/compilerplugins/clang/literaltoboolconversion.cxx
index bbb0cbf..5c87f47 100644
--- a/compilerplugins/clang/literaltoboolconversion.cxx
+++ b/compilerplugins/clang/literaltoboolconversion.cxx
@@ -1,4 +1,3 @@
-#include<iostream>
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /*
  * This file is part of the LibreOffice project.
@@ -47,8 +46,10 @@ bool LiteralToBoolConversion::VisitImplicitCastExpr(
     if (sub->getType()->isBooleanType()) {
         return true;
     }
-    IntegerLiteral const * lit = dyn_cast<IntegerLiteral>(sub);
-    if (lit != nullptr && lit->getValue().getLimitedValue() <= 1) {
+    APSInt res;
+    if (sub->isIntegerConstantExpr(res, compiler.getASTContext())
+        && res.getLimitedValue() <= 1)
+    {
         SourceLocation loc { sub->getLocStart() };
         while (compiler.getSourceManager().isMacroArgExpansion(loc)) {
             loc = compiler.getSourceManager().getImmediateMacroCallerLoc(loc);
@@ -66,7 +67,6 @@ bool LiteralToBoolConversion::VisitImplicitCastExpr(
                 return true;
             }
         }
-
     }
     if (isa<StringLiteral>(sub)) {
         SourceLocation loc { sub->getLocStart() };
@@ -136,19 +136,14 @@ bool LiteralToBoolConversion::VisitImplicitCastExpr(
             << expr->getCastKindName() << expr->getSubExpr()->getType()
             << expr->getType() << expr->getSourceRange();
 #endif
-    } else if (sub->isIntegerConstantExpr(compiler.getASTContext())) {
-        CallExpr const * ce = dyn_cast<CallExpr>(sub);
-        if (ce == nullptr
-            || compat::getBuiltinCallee(*ce) != Builtin::BI__builtin_expect)
-        {
-            report(
-                DiagnosticsEngine::Warning,
-                ("implicit conversion (%0) of integer constant expression of"
-                 " type %1 to %2"),
-                expr->getLocStart())
-                << expr->getCastKindName() << expr->getSubExpr()->getType()
-                << expr->getType() << expr->getSourceRange();
-        }
+    } else if (sub->isIntegerConstantExpr(res, compiler.getASTContext())) {
+        report(
+            DiagnosticsEngine::Warning,
+            ("implicit conversion (%0) of integer constant expression of type"
+             " %1 with value %2 to %3"),
+            expr->getLocStart())
+            << expr->getCastKindName() << expr->getSubExpr()->getType()
+            << res.toString(10) << expr->getType() << expr->getSourceRange();
     }
     return true;
 }


More information about the Libreoffice-commits mailing list