improve unusedfields loplugin
to ignore assignments when doing writeonly analysis Change-Id: I9eb6f2594003a610582dbc20acb7ccf14ef72c6c
This commit is contained in:
@@ -194,8 +194,7 @@ bool ConstParams::checkIfCanBeConst(const Stmt* stmt)
|
|||||||
return checkIfCanBeConst(parent);
|
return checkIfCanBeConst(parent);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else if (isa<BinaryOperator>(parent)) {
|
} else if (auto binaryOp = dyn_cast<BinaryOperator>(parent)) {
|
||||||
const BinaryOperator* binaryOp = dyn_cast<BinaryOperator>(parent);
|
|
||||||
BinaryOperator::Opcode op = binaryOp->getOpcode();
|
BinaryOperator::Opcode op = binaryOp->getOpcode();
|
||||||
// TODO could do better, but would require tracking the LHS
|
// TODO could do better, but would require tracking the LHS
|
||||||
if (binaryOp->getRHS() == stmt && op == BO_Assign) {
|
if (binaryOp->getRHS() == stmt && op == BO_Assign) {
|
||||||
|
@@ -271,11 +271,30 @@ bool UnusedFields::VisitMemberExpr( const MemberExpr* memberExpr )
|
|||||||
bPotentiallyReadFrom = true;
|
bPotentiallyReadFrom = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (isa<ReturnStmt>(parent) || isa<CXXConstructExpr>(parent)
|
else if (auto binaryOp = dyn_cast<BinaryOperator>(parent))
|
||||||
|| isa<ConditionalOperator>(parent) || isa<SwitchStmt>(parent) || isa<ArraySubscriptExpr>(parent)
|
{
|
||||||
|| isa<DeclStmt>(parent) || isa<WhileStmt>(parent) || isa<CXXNewExpr>(parent)
|
BinaryOperator::Opcode op = binaryOp->getOpcode();
|
||||||
|| isa<ForStmt>(parent) || isa<InitListExpr>(parent)
|
// If the child is on the LHS and it is an assignment, we are obviously not reading from it,
|
||||||
|| isa<BinaryOperator>(parent) || isa<CXXDependentScopeMemberExpr>(parent)
|
// so walk up the tree.
|
||||||
|
if (binaryOp->getLHS() == child && op == BO_Assign) {
|
||||||
|
child = parent;
|
||||||
|
parent = parentStmt(parent);
|
||||||
|
} else {
|
||||||
|
bPotentiallyReadFrom = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (isa<ReturnStmt>(parent)
|
||||||
|
|| isa<CXXConstructExpr>(parent)
|
||||||
|
|| isa<ConditionalOperator>(parent)
|
||||||
|
|| isa<SwitchStmt>(parent)
|
||||||
|
|| isa<ArraySubscriptExpr>(parent)
|
||||||
|
|| isa<DeclStmt>(parent)
|
||||||
|
|| isa<WhileStmt>(parent)
|
||||||
|
|| isa<CXXNewExpr>(parent)
|
||||||
|
|| isa<ForStmt>(parent)
|
||||||
|
|| isa<InitListExpr>(parent)
|
||||||
|
|| isa<CXXDependentScopeMemberExpr>(parent)
|
||||||
|| isa<UnresolvedMemberExpr>(parent)
|
|| isa<UnresolvedMemberExpr>(parent)
|
||||||
|| isa<MaterializeTemporaryExpr>(parent)) //???
|
|| isa<MaterializeTemporaryExpr>(parent)) //???
|
||||||
{
|
{
|
||||||
@@ -283,9 +302,13 @@ bool UnusedFields::VisitMemberExpr( const MemberExpr* memberExpr )
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (isa<CXXDeleteExpr>(parent)
|
else if (isa<CXXDeleteExpr>(parent)
|
||||||
|| isa<UnaryExprOrTypeTraitExpr>(parent)
|
|| isa<UnaryExprOrTypeTraitExpr>(parent)
|
||||||
|| isa<CXXUnresolvedConstructExpr>(parent) || isa<CompoundStmt>(parent)
|
|| isa<CXXUnresolvedConstructExpr>(parent)
|
||||||
|| isa<CXXTypeidExpr>(parent) || isa<DefaultStmt>(parent))
|
|| isa<CompoundStmt>(parent)
|
||||||
|
|| isa<LabelStmt>(parent)
|
||||||
|
|| isa<CXXForRangeStmt>(parent)
|
||||||
|
|| isa<CXXTypeidExpr>(parent)
|
||||||
|
|| isa<DefaultStmt>(parent))
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -305,7 +328,9 @@ bool UnusedFields::VisitMemberExpr( const MemberExpr* memberExpr )
|
|||||||
parent->dump();
|
parent->dump();
|
||||||
}
|
}
|
||||||
if (bPotentiallyReadFrom)
|
if (bPotentiallyReadFrom)
|
||||||
|
{
|
||||||
readFromSet.insert(fieldInfo);
|
readFromSet.insert(fieldInfo);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user