From 979d58c9a96884e36d1585df0c04c89b1f53fa99 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Fri, 30 Jun 2017 11:08:36 +0200 Subject: loplugin:unusedfields in toolkit..xmloff Change-Id: I4964ff97e0a1735dc08c6ad204cae0b08e9ffc2c Reviewed-on: https://gerrit.libreoffice.org/39406 Tested-by: Jenkins Reviewed-by: Noel Grandin --- compilerplugins/clang/unusedfields.cxx | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'compilerplugins/clang/unusedfields.cxx') diff --git a/compilerplugins/clang/unusedfields.cxx b/compilerplugins/clang/unusedfields.cxx index 50e41b7f7023..7b39b0e71148 100644 --- a/compilerplugins/clang/unusedfields.cxx +++ b/compilerplugins/clang/unusedfields.cxx @@ -258,6 +258,11 @@ void UnusedFields::checkWriteOnly(const FieldDecl* fieldDecl, const Expr* member // walk up the tree until we find something interesting bool bPotentiallyReadFrom = false; bool bDump = false; + auto walkupUp = [&]() { + child = parent; + auto parentsRange = compiler.getASTContext().getParents(*parent); + parent = parentsRange.begin() == parentsRange.end() ? nullptr : parentsRange.begin()->get(); + }; do { if (!parent) @@ -280,9 +285,7 @@ void UnusedFields::checkWriteOnly(const FieldDecl* fieldDecl, const Expr* member #endif || isa(parent)) { - child = parent; - auto parentsRange = compiler.getASTContext().getParents(*parent); - parent = parentsRange.begin() == parentsRange.end() ? nullptr : parentsRange.begin()->get(); + walkupUp(); } else if (auto unaryOperator = dyn_cast(parent)) { @@ -300,9 +303,7 @@ void UnusedFields::checkWriteOnly(const FieldDecl* fieldDecl, const Expr* member bPotentiallyReadFrom = true; break; } - child = parent; - auto parentsRange = compiler.getASTContext().getParents(*parent); - parent = parentsRange.begin() == parentsRange.end() ? nullptr : parentsRange.begin()->get(); + walkupUp(); } else if (auto caseStmt = dyn_cast(parent)) { @@ -319,6 +320,15 @@ void UnusedFields::checkWriteOnly(const FieldDecl* fieldDecl, const Expr* member bPotentiallyReadFrom = doStmt->getCond() == child; break; } + else if (auto arraySubscriptExpr = dyn_cast(parent)) + { + if (arraySubscriptExpr->getIdx() == child) + { + bPotentiallyReadFrom = true; + break; + } + walkupUp(); + } else if (auto callExpr = dyn_cast(parent)) { // check for calls to ReadXXX() type methods and the operator>>= methods on Any. @@ -378,7 +388,6 @@ void UnusedFields::checkWriteOnly(const FieldDecl* fieldDecl, const Expr* member || isa(parent) || isa(parent) || isa(parent) - || isa(parent) || isa(parent)) { break; -- cgit