[Libreoffice-commits] core.git: compilerplugins/clang sc/source solenv/CompilerTest_compilerplugins_clang.mk vcl/unx
compilerplugins/clang/intvsfloat.cxx |6 +-- compilerplugins/clang/test/intvsfloat.cxx| 43 +++ sc/source/ui/app/inputwin.cxx|2 - solenv/CompilerTest_compilerplugins_clang.mk |1 vcl/unx/gtk3/gtk3salnativewidgets-gtk.cxx|2 - 5 files changed, 24 insertions(+), 30 deletions(-) New commits: commit 93e0622d0097c90effc8bec5f31cf0c12a20d88b Author: Noel Grandin AuthorDate: Fri Nov 30 13:25:01 2018 +0200 Commit: Noel Grandin CommitDate: Sun Dec 2 11:46:39 2018 +0100 loplugin:intvsfloat get this working reliably Change-Id: Ifdf1a152f6bc2e2f6edae97a5191120f630f7e49 Reviewed-on: https://gerrit.libreoffice.org/64374 Tested-by: Jenkins Reviewed-by: Mike Kaganski Reviewed-by: Noel Grandin diff --git a/compilerplugins/clang/store/intvsfloat.cxx b/compilerplugins/clang/intvsfloat.cxx similarity index 96% rename from compilerplugins/clang/store/intvsfloat.cxx rename to compilerplugins/clang/intvsfloat.cxx index 3189d982d9c0..e9ee3fa9b306 100644 --- a/compilerplugins/clang/store/intvsfloat.cxx +++ b/compilerplugins/clang/intvsfloat.cxx @@ -16,9 +16,7 @@ TODO multiplying/otherop on a combination of a float and int, and then truncating to int. like this: float getRotation() {} -int moRotation; -moRotation = -F_PI180 * 90 * getRotation(); - +int moRotation = -F_PI180 * 90 * getRotation(); */ namespace { @@ -90,6 +88,8 @@ llvm::Optional IntVsFloat::getExprValue(Expr const* expr) // Of the available clang Evaluate* APIs, this is the __only__ one that produces useful output // (as of 17 Aug 2018 checkout of clang, ie. towards clang 7) +if (expr->isValueDependent()) +return llvm::Optional(); Expr::EvalResult evalResult; if (!expr->EvaluateAsRValue(evalResult, compiler.getASTContext())) return llvm::Optional(); diff --git a/compilerplugins/clang/test/intvsfloat.cxx b/compilerplugins/clang/test/intvsfloat.cxx index 7c753c3667ab..4746873e7bba 100644 --- a/compilerplugins/clang/test/intvsfloat.cxx +++ b/compilerplugins/clang/test/intvsfloat.cxx @@ -18,26 +18,22 @@ struct Class1 void func1(Class1 const& class1) { -if (1 -== PI) // expected-error {{comparing integer to float constant, can never be true [loplugin:intvsfloat]}} +// expected-error@+1 {{comparing integer to float constant, can never be true [loplugin:intvsfloat]}} +if (1 == PI) return; -if (1 -== class1 - .PI) // expected-error {{comparing integer to float constant, can never be true [loplugin:intvsfloat]}} +// expected-error@+1 {{comparing integer to float constant, can never be true [loplugin:intvsfloat]}} +if (1 == class1.PI) return; -if (true -== class1 - .PI) // expected-error {{comparing integer to float constant, can never be true [loplugin:intvsfloat]}} +// expected-error@+1 {{comparing integer to float constant, can never be true [loplugin:intvsfloat]}} +if (true == class1.PI) return; if (1 == class1.getInt()) // no warning expected return; -if (1 -== class1 - .E()) // expected-error {{comparing integer to float constant, can never be true [loplugin:intvsfloat]}} +// expected-error@+1 {{comparing integer to float constant, can never be true [loplugin:intvsfloat]}} +if (1 == class1.E()) return; -if (true -== class1 - .E()) // expected-error {{comparing integer to float constant, can never be true [loplugin:intvsfloat]}} +// expected-error@+1 {{comparing integer to float constant, can never be true [loplugin:intvsfloat]}} +if (true == class1.E()) return; if (1 == class1.getFloat()) // no warning expected return; @@ -45,24 +41,21 @@ void func1(Class1 const& class1) void func2(Class1 const& class1) { -int i0 -= PI; // expected-error {{assigning constant float value to int truncates data [loplugin:intvsfloat]}} +// expected-error@+1 {{assigning constant float value to int truncates data [loplugin:intvsfloat]}} +int i0 = PI; (void)i0; -int i1 -= class1 - .PI; // expected-error {{assigning constant float value to int truncates data [loplugin:intvsfloat]}} +// expected-error@+1 {{assigning constant float value to int truncates data [loplugin:intvsfloat]}} +int i1 = class1.PI; (void)i1; -int i2 -= class1 - .E(); // expected-error {{assigning constant float value to int truncates data [loplugin:intvsfloat]}} +// expected-error@+1 {{assigning constant float value to int truncates data [loplugin:intvsfloat]}} +int i2 = class1.E(); (void)i2; int i3 = class1.getFloat(); // no warning expected (void)i3; int i4 = class1.getInt(); // no warning expected (void)i4; -bool b1 -= class1 - .E(); //
[Libreoffice-commits] core.git: compilerplugins/clang sc/source solenv/CompilerTest_compilerplugins_clang.mk
compilerplugins/clang/doubleconvert.cxx | 84 +++ compilerplugins/clang/test/doubleconvert.cxx | 22 +++ sc/source/core/tool/detfunc.cxx |6 - sc/source/ui/dbgui/csvgrid.cxx | 10 +-- solenv/CompilerTest_compilerplugins_clang.mk |1 5 files changed, 115 insertions(+), 8 deletions(-) New commits: commit 64ada386b9e67b2cb5823a333ec2b289781459ba Author: Noel GrandinDate: Thu Feb 22 15:39:56 2018 +0200 new loplugin:doubleconvert to with ColorData work Change-Id: Ib8f2ef485f548645c4b0e7cf080b72b28c4e278d Reviewed-on: https://gerrit.libreoffice.org/50226 Reviewed-by: Noel Grandin Tested-by: Noel Grandin diff --git a/compilerplugins/clang/doubleconvert.cxx b/compilerplugins/clang/doubleconvert.cxx new file mode 100644 index ..a0478e9e5f1f --- /dev/null +++ b/compilerplugins/clang/doubleconvert.cxx @@ -0,0 +1,84 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "check.hxx" +#include "compat.hxx" +#include "plugin.hxx" + +/** + * Look for places where we are converting from type A through a conversion operator and back to type A, + * which is redundant. At the moment only look for Color, to aid my ColorData->Color conversion + */ +namespace +{ +class DoubleConvert final : public RecursiveASTVisitor, public loplugin::Plugin +{ +public: +explicit DoubleConvert(loplugin::InstantiationData const& data) +: Plugin(data) +{ +} +void run() override { TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); } + +bool VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr const*); +}; + +/** + The AST looks like: + + CXXOperatorCallExpr 0x8e5b840 'class Color' lvalue +|-ImplicitCastExpr 0x8e5b828 'class Color &(*)(class Color &&) noexcept' +| `-DeclRefExpr 0x8e5b800 'class Color &(class Color &&) noexcept' lvalue CXXMethod 0x8e59a08 'operator=' 'class Color &(class Color &&) noexcept' +|-DeclRefExpr 0x8e5b678 'class Color' lvalue Var 0x8e5b5d0 'col2' 'class Color' +`-MaterializeTemporaryExpr 0x8e5b7e8 'class Color' xvalue + `-CXXConstructExpr 0x8e5b7b0 'class Color' 'void (ColorData)' +`-ImplicitCastExpr 0x8e5b798 'ColorData':'unsigned int' + `-CXXFunctionalCastExpr 0x8e5b770 'sal_Int32':'int' functional cast to sal_Int32 +`-ImplicitCastExpr 0x8e5b758 'sal_Int32':'int' + `-CXXMemberCallExpr 0x8e5b730 'sal_Int32':'int' +`-MemberExpr 0x8e5b6f8 '' .operator int 0x8e51048 + `-ImplicitCastExpr 0x8e5b6e0 'const class Color' lvalue +`-DeclRefExpr 0x8e5b6b0 'class Color' lvalue Var 0x8e5b518 'col1' 'class Color' +*/ +bool DoubleConvert::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr const* materializetemp) +{ +if (ignoreLocation(materializetemp)) +return true; +auto cxxConstruct += dyn_cast(materializetemp->GetTemporaryExpr()->IgnoreParenCasts()); +if (!cxxConstruct) +return true; +if (cxxConstruct->getNumArgs() == 0) +return true; +auto cxxMemberCallExpr += dyn_cast(cxxConstruct->getArg(0)->IgnoreParenCasts()); +if (!cxxMemberCallExpr) +return true; +if (!isa(cxxMemberCallExpr->getMethodDecl())) +return true; +if (materializetemp->getType().getCanonicalType().getTypePtr() +!= cxxMemberCallExpr->getImplicitObjectArgument() + ->getType() + .getCanonicalType() + .getTypePtr()) +return true; +if (!loplugin::TypeCheck(materializetemp->getType().getCanonicalType()) + .Class("Color") + .GlobalNamespace()) +return true; + +report(DiagnosticsEngine::Warning, "redundant double conversion", materializetemp->getExprLoc()) +<< materializetemp->getSourceRange(); +return true; +} + +static loplugin::Plugin::Registration reg("doubleconvert"); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/compilerplugins/clang/test/doubleconvert.cxx b/compilerplugins/clang/test/doubleconvert.cxx new file mode 100644 index ..d0fd8b787bdb --- /dev/null +++ b/compilerplugins/clang/test/doubleconvert.cxx @@ -0,0 +1,22 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can
[Libreoffice-commits] core.git: compilerplugins/clang sc/source solenv/CompilerTest_compilerplugins_clang.mk
compilerplugins/clang/stringconstant.cxx | 366 -- compilerplugins/clang/test/stringconstant.cxx | 52 +++ sc/source/core/tool/interpr2.cxx |4 solenv/CompilerTest_compilerplugins_clang.mk |1 4 files changed, 288 insertions(+), 135 deletions(-) New commits: commit 236f69e710b1ce00a68d25c26da82724c658b0d4 Author: Stephan BergmannDate: Wed Jan 25 07:58:10 2017 +0100 Minor loplugin:stringconstant improvements Change-Id: I0b39526c0f0854ddbb29e77ece303cf2bdd842c4 diff --git a/compilerplugins/clang/stringconstant.cxx b/compilerplugins/clang/stringconstant.cxx index 34a5421..464fe06 100644 --- a/compilerplugins/clang/stringconstant.cxx +++ b/compilerplugins/clang/stringconstant.cxx @@ -75,6 +75,24 @@ bool hasOverloads(FunctionDecl const * decl, unsigned arguments) { return false; } +CXXConstructExpr const * lookForCXXConstructExpr(Expr const * expr) { +if (auto e = dyn_cast(expr)) { +expr = e->GetTemporaryExpr(); +} +if (auto e = dyn_cast(expr)) { +expr = e->getSubExpr(); +} +if (auto e = dyn_cast(expr)) { +expr = e->getSubExpr(); +} +return dyn_cast(expr); +} + +char const * adviseNonArray(bool nonArray) { +return nonArray +? ", and turn the non-array string constant into an array" : ""; +} + class StringConstant: public RecursiveASTVisitor, public loplugin::RewritePlugin { @@ -113,7 +131,7 @@ private: void reportChange( Expr const * expr, ChangeKind kind, std::string const & original, -std::string const & replacement, PassThrough pass, +std::string const & replacement, PassThrough pass, bool nonArray, char const * rewriteFrom, char const * rewriteTo); void checkEmpty( @@ -134,6 +152,9 @@ private: CallExpr const * expr, unsigned arg, FunctionDecl const * callee, bool explicitFunctionalCastNotation); +void handleFunArgOstring( +CallExpr const * expr, unsigned arg, FunctionDecl const * callee); + std::stack calls_; }; @@ -490,7 +511,7 @@ bool StringConstant::VisitCallExpr(CallExpr const * expr) { if (non) { report( DiagnosticsEngine::Warning, -("call of %0 with string constant argument containging" +("call of '%0' with string constant argument containging" " non-ASCII characters"), expr->getExprLoc()) << fdecl->getQualifiedNameAsString() << expr->getSourceRange(); @@ -498,16 +519,16 @@ bool StringConstant::VisitCallExpr(CallExpr const * expr) { if (emb) { report( DiagnosticsEngine::Warning, -("call of %0 with string constant argument containging embedded" - " NULs"), +("call of '%0' with string constant argument containging" + " embedded NULs"), expr->getExprLoc()) << fdecl->getQualifiedNameAsString() << expr->getSourceRange(); } if (n == 0) { report( DiagnosticsEngine::Warning, -("rewrite call of %0 with empty string constant argument as" - " call of rtl::OUString::isEmpty"), +("rewrite call of '%0' with empty string constant argument as" + " call of 'rtl::OUString::isEmpty'"), expr->getExprLoc()) << fdecl->getQualifiedNameAsString() << expr->getSourceRange(); return true; @@ -531,7 +552,7 @@ bool StringConstant::VisitCallExpr(CallExpr const * expr) { if (non) { report( DiagnosticsEngine::Warning, -("call of %0 with string constant argument containging" +("call of '%0' with string constant argument containging" " non-ASCII characters"), expr->getExprLoc()) << fdecl->getQualifiedNameAsString() @@ -540,7 +561,7 @@ bool StringConstant::VisitCallExpr(CallExpr const * expr) { if (emb) { report( DiagnosticsEngine::Warning, -("call of %0 with string constant argument containging" +("call of '%0' with string constant argument containging" " embedded NULs"), expr->getExprLoc()) << fdecl->getQualifiedNameAsString() @@ -549,8 +570,8 @@ bool StringConstant::VisitCallExpr(CallExpr const * expr) { if (n == 0) { report( DiagnosticsEngine::Warning, -("rewrite call of %0 with empty string constant argument as" - " call of rtl::OUString::isEmpty"), +("rewrite call of '%0' with empty string constant argument" + " as call