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

Stephan Bergmann sbergman at redhat.com
Thu Feb 4 10:04:26 UTC 2016


 compilerplugins/clang/fpcomparison.cxx |   12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

New commits:
commit 39accf65cdfd62693d2b46b822215d88b462c2f3
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Thu Feb 4 10:57:25 2016 +0100

    loplugin:fpcomparison: Fix check for floating-point zero
    
    ...so that isZeroConstant doesn't trigger an assert inside Clang's
    isCXX11ConstantExpr when expr is sizeof(x) with x being dependent on a template
    argument.
    
    Change-Id: I6bab46e64cc085d597db25994d8bfdc66417fe83

diff --git a/compilerplugins/clang/fpcomparison.cxx b/compilerplugins/clang/fpcomparison.cxx
index b374da7..8d20b8c 100644
--- a/compilerplugins/clang/fpcomparison.cxx
+++ b/compilerplugins/clang/fpcomparison.cxx
@@ -97,8 +97,7 @@ bool FpComparison::ignore(FunctionDecl* function)
 
 static bool isZeroConstant(ASTContext& context, const Expr* expr)
 {
-    // calling isCXX11ConstantExpr with non-arithmetic types sometimes results in a crash
-    if (!expr->getType()->isArithmeticType()) {
+    if (!expr->getType()->isFloatingType()) {
         return false;
     }
     // prevent clang crash
@@ -106,12 +105,11 @@ static bool isZeroConstant(ASTContext& context, const Expr* expr)
         return false;
     }
     APValue result;
-    if (expr->isCXX11ConstantExpr(context, &result)
-        && result.isFloat() && result.getFloat().isZero())
-    {
-        return true;
+    if (!expr->isCXX11ConstantExpr(context, &result)) {
+        return false;
     }
-    return false;
+    assert(result.isFloat());
+    return result.getFloat().isZero();
 }
 bool FpComparison::VisitBinaryOperator(const BinaryOperator* binaryOp)
 {


More information about the Libreoffice-commits mailing list