From 907ffec4907eac13bfe51c98d4f27b433b7bb36f Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Tue, 25 Feb 2014 19:03:12 +0100 Subject: 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 --- compilerplugins/clang/literaltoboolconversion.cxx | 29 ++++++++++------------- 1 file changed, 12 insertions(+), 17 deletions(-) (limited to 'compilerplugins') diff --git a/compilerplugins/clang/literaltoboolconversion.cxx b/compilerplugins/clang/literaltoboolconversion.cxx index bbb0cbf76973..5c87f474ec23 100644 --- a/compilerplugins/clang/literaltoboolconversion.cxx +++ b/compilerplugins/clang/literaltoboolconversion.cxx @@ -1,4 +1,3 @@ -#include /* -*- 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(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(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(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; } -- cgit v1.2.3