summaryrefslogtreecommitdiff
path: root/compilerplugins/clang/unusedfields.cxx
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2017-06-30 11:08:36 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-06-30 19:50:30 +0200
commit979d58c9a96884e36d1585df0c04c89b1f53fa99 (patch)
treebce40aad53ac5123a2864da59b8d889b8a51e577 /compilerplugins/clang/unusedfields.cxx
parent3c1fc723ff622d8a541fa26a3397ca4258332e4a (diff)
loplugin:unusedfields in toolkit..xmloff
Change-Id: I4964ff97e0a1735dc08c6ad204cae0b08e9ffc2c Reviewed-on: https://gerrit.libreoffice.org/39406 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins/clang/unusedfields.cxx')
-rw-r--r--compilerplugins/clang/unusedfields.cxx23
1 files changed, 16 insertions, 7 deletions
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<Stmt>();
+ };
do
{
if (!parent)
@@ -280,9 +285,7 @@ void UnusedFields::checkWriteOnly(const FieldDecl* fieldDecl, const Expr* member
#endif
|| isa<ExprWithCleanups>(parent))
{
- child = parent;
- auto parentsRange = compiler.getASTContext().getParents(*parent);
- parent = parentsRange.begin() == parentsRange.end() ? nullptr : parentsRange.begin()->get<Stmt>();
+ walkupUp();
}
else if (auto unaryOperator = dyn_cast<UnaryOperator>(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<Stmt>();
+ walkupUp();
}
else if (auto caseStmt = dyn_cast<CaseStmt>(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<ArraySubscriptExpr>(parent))
+ {
+ if (arraySubscriptExpr->getIdx() == child)
+ {
+ bPotentiallyReadFrom = true;
+ break;
+ }
+ walkupUp();
+ }
else if (auto callExpr = dyn_cast<CallExpr>(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<LabelStmt>(parent)
|| isa<CXXForRangeStmt>(parent)
|| isa<CXXTypeidExpr>(parent)
- || isa<ArraySubscriptExpr>(parent)
|| isa<DefaultStmt>(parent))
{
break;