summaryrefslogtreecommitdiff
path: root/compilerplugins/clang
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-04-12 11:23:58 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-04-16 08:21:36 +0200
commitd911b3d37d13e84e0c6cb8eb990e58a0939a6f6a (patch)
tree96b7982104f483923a4e4adca76e49e43eac6f05 /compilerplugins/clang
parenta0b3e81aeb10488c4746360dc1669f3aed71cb67 (diff)
loplugin:useuniqueptr in OStorePageBIOS
update the plugin to check all methods for deleting fields. Also remove the dead checks for new failing here, can never have worked, because it is not calling the std::nothrow variant. Change-Id: I139410e42f83ae2db0cd38ceee81c8b4c310268c Reviewed-on: https://gerrit.libreoffice.org/52881 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins/clang')
-rw-r--r--compilerplugins/clang/useuniqueptr.cxx62
1 files changed, 31 insertions, 31 deletions
diff --git a/compilerplugins/clang/useuniqueptr.cxx b/compilerplugins/clang/useuniqueptr.cxx
index 5d00c1a637e8..192ae50a4eba 100644
--- a/compilerplugins/clang/useuniqueptr.cxx
+++ b/compilerplugins/clang/useuniqueptr.cxx
@@ -46,40 +46,40 @@ public:
TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
}
- bool VisitCXXDestructorDecl(const CXXDestructorDecl* );
+ bool VisitCXXMethodDecl(const CXXMethodDecl* );
bool VisitCompoundStmt(const CompoundStmt* );
private:
- void CheckForUnconditionalDelete(const CXXDestructorDecl*, const CompoundStmt* );
- void CheckForSimpleDelete(const CXXDestructorDecl*, const CompoundStmt* );
- void CheckRangedLoopDelete(const CXXDestructorDecl*, const CXXForRangeStmt* );
- void CheckLoopDelete(const CXXDestructorDecl*, const Stmt* );
- void CheckLoopDelete(const CXXDestructorDecl*, const CXXDeleteExpr* );
- void CheckDeleteExpr(const CXXDestructorDecl*, const CXXDeleteExpr*);
- void CheckDeleteExpr(const CXXDestructorDecl*, const CXXDeleteExpr*,
+ void CheckForUnconditionalDelete(const CXXMethodDecl*, const CompoundStmt* );
+ void CheckForSimpleDelete(const CXXMethodDecl*, const CompoundStmt* );
+ void CheckRangedLoopDelete(const CXXMethodDecl*, const CXXForRangeStmt* );
+ void CheckLoopDelete(const CXXMethodDecl*, const Stmt* );
+ void CheckLoopDelete(const CXXMethodDecl*, const CXXDeleteExpr* );
+ void CheckDeleteExpr(const CXXMethodDecl*, const CXXDeleteExpr*);
+ void CheckDeleteExpr(const CXXMethodDecl*, const CXXDeleteExpr*,
const MemberExpr*, StringRef message);
};
-bool UseUniquePtr::VisitCXXDestructorDecl(const CXXDestructorDecl* destructorDecl)
+bool UseUniquePtr::VisitCXXMethodDecl(const CXXMethodDecl* methodDecl)
{
- if (ignoreLocation(destructorDecl))
+ if (ignoreLocation(methodDecl))
return true;
- if (isInUnoIncludeFile(destructorDecl))
+ if (isInUnoIncludeFile(methodDecl))
return true;
- const CompoundStmt* compoundStmt = dyn_cast_or_null< CompoundStmt >( destructorDecl->getBody() );
+ const CompoundStmt* compoundStmt = dyn_cast_or_null< CompoundStmt >( methodDecl->getBody() );
if (!compoundStmt || compoundStmt->size() == 0)
return true;
- CheckForSimpleDelete(destructorDecl, compoundStmt);
+ CheckForSimpleDelete(methodDecl, compoundStmt);
for (auto i = compoundStmt->body_begin(); i != compoundStmt->body_end(); ++i)
{
if (auto cxxForRangeStmt = dyn_cast<CXXForRangeStmt>(*i))
- CheckRangedLoopDelete(destructorDecl, cxxForRangeStmt);
+ CheckRangedLoopDelete(methodDecl, cxxForRangeStmt);
else if (auto forStmt = dyn_cast<ForStmt>(*i))
- CheckLoopDelete(destructorDecl, forStmt->getBody());
+ CheckLoopDelete(methodDecl, forStmt->getBody());
else if (auto whileStmt = dyn_cast<WhileStmt>(*i))
- CheckLoopDelete(destructorDecl, whileStmt->getBody());
+ CheckLoopDelete(methodDecl, whileStmt->getBody());
}
return true;
@@ -88,14 +88,14 @@ bool UseUniquePtr::VisitCXXDestructorDecl(const CXXDestructorDecl* destructorDec
/**
* check for simple call to delete in a destructor i.e. direct unconditional call, or if-guarded call
*/
-void UseUniquePtr::CheckForSimpleDelete(const CXXDestructorDecl* destructorDecl, const CompoundStmt* compoundStmt)
+void UseUniquePtr::CheckForSimpleDelete(const CXXMethodDecl* methodDecl, const CompoundStmt* compoundStmt)
{
for (auto i = compoundStmt->body_begin(); i != compoundStmt->body_end(); ++i)
{
auto deleteExpr = dyn_cast<CXXDeleteExpr>(*i);
if (deleteExpr)
{
- CheckDeleteExpr(destructorDecl, deleteExpr);
+ CheckDeleteExpr(methodDecl, deleteExpr);
continue;
}
// Check for conditional deletes like:
@@ -125,7 +125,7 @@ void UseUniquePtr::CheckForSimpleDelete(const CXXDestructorDecl* destructorDecl,
deleteExpr = dyn_cast<CXXDeleteExpr>(ifStmt->getThen());
if (deleteExpr)
{
- CheckDeleteExpr(destructorDecl, deleteExpr);
+ CheckDeleteExpr(methodDecl, deleteExpr);
continue;
}
@@ -136,7 +136,7 @@ void UseUniquePtr::CheckForSimpleDelete(const CXXDestructorDecl* destructorDecl,
{
auto ifDeleteExpr = dyn_cast<CXXDeleteExpr>(*j);
if (ifDeleteExpr)
- CheckDeleteExpr(destructorDecl, ifDeleteExpr);
+ CheckDeleteExpr(methodDecl, ifDeleteExpr);
}
}
}
@@ -144,7 +144,7 @@ void UseUniquePtr::CheckForSimpleDelete(const CXXDestructorDecl* destructorDecl,
/**
* Check the delete expression in a destructor.
*/
-void UseUniquePtr::CheckDeleteExpr(const CXXDestructorDecl* destructorDecl, const CXXDeleteExpr* deleteExpr)
+void UseUniquePtr::CheckDeleteExpr(const CXXMethodDecl* methodDecl, const CXXDeleteExpr* deleteExpr)
{
const ImplicitCastExpr* castExpr = dyn_cast<ImplicitCastExpr>(deleteExpr->getArgument());
if (!castExpr)
@@ -152,14 +152,14 @@ void UseUniquePtr::CheckDeleteExpr(const CXXDestructorDecl* destructorDecl, cons
const MemberExpr* memberExpr = dyn_cast<MemberExpr>(castExpr->getSubExpr());
if (!memberExpr)
return;
- CheckDeleteExpr(destructorDecl, deleteExpr, memberExpr,
+ CheckDeleteExpr(methodDecl, deleteExpr, memberExpr,
"unconditional call to delete on a member, should be using std::unique_ptr");
}
/**
* Check the delete expression in a destructor.
*/
-void UseUniquePtr::CheckDeleteExpr(const CXXDestructorDecl* destructorDecl, const CXXDeleteExpr* deleteExpr,
+void UseUniquePtr::CheckDeleteExpr(const CXXMethodDecl* methodDecl, const CXXDeleteExpr* deleteExpr,
const MemberExpr* memberExpr, StringRef message)
{
// ignore union games
@@ -171,7 +171,7 @@ void UseUniquePtr::CheckDeleteExpr(const CXXDestructorDecl* destructorDecl, cons
return;
// ignore calling delete on someone else's field
- if (fieldDecl->getParent() != destructorDecl->getParent() )
+ if (fieldDecl->getParent() != methodDecl->getParent() )
return;
if (ignoreLocation(fieldDecl))
@@ -240,21 +240,21 @@ void UseUniquePtr::CheckDeleteExpr(const CXXDestructorDecl* destructorDecl, cons
<< fieldDecl->getSourceRange();
}
-void UseUniquePtr::CheckLoopDelete(const CXXDestructorDecl* destructorDecl, const Stmt* bodyStmt)
+void UseUniquePtr::CheckLoopDelete(const CXXMethodDecl* methodDecl, const Stmt* bodyStmt)
{
if (auto deleteExpr = dyn_cast<CXXDeleteExpr>(bodyStmt))
- CheckLoopDelete(destructorDecl, deleteExpr);
+ CheckLoopDelete(methodDecl, deleteExpr);
else if (auto compoundStmt = dyn_cast<CompoundStmt>(bodyStmt))
{
for (auto i = compoundStmt->body_begin(); i != compoundStmt->body_end(); ++i)
{
if (auto deleteExpr = dyn_cast<CXXDeleteExpr>(*i))
- CheckLoopDelete(destructorDecl, deleteExpr);
+ CheckLoopDelete(methodDecl, deleteExpr);
}
}
}
-void UseUniquePtr::CheckLoopDelete(const CXXDestructorDecl* destructorDecl, const CXXDeleteExpr* deleteExpr)
+void UseUniquePtr::CheckLoopDelete(const CXXMethodDecl* methodDecl, const CXXDeleteExpr* deleteExpr)
{
const MemberExpr* memberExpr = nullptr;
const Expr* subExpr = deleteExpr->getArgument();
@@ -280,10 +280,10 @@ void UseUniquePtr::CheckLoopDelete(const CXXDestructorDecl* destructorDecl, cons
if (!memberExpr)
return;
- CheckDeleteExpr(destructorDecl, deleteExpr, memberExpr, "rather manage with std::some_container<std::unique_ptr<T>>");
+ CheckDeleteExpr(methodDecl, deleteExpr, memberExpr, "rather manage with std::some_container<std::unique_ptr<T>>");
}
-void UseUniquePtr::CheckRangedLoopDelete(const CXXDestructorDecl* destructorDecl, const CXXForRangeStmt* cxxForRangeStmt)
+void UseUniquePtr::CheckRangedLoopDelete(const CXXMethodDecl* methodDecl, const CXXForRangeStmt* cxxForRangeStmt)
{
CXXDeleteExpr const * deleteExpr = nullptr;
if (auto compoundStmt = dyn_cast<CompoundStmt>(cxxForRangeStmt->getBody()))
@@ -299,7 +299,7 @@ void UseUniquePtr::CheckRangedLoopDelete(const CXXDestructorDecl* destructorDecl
if (!fieldDecl)
return;
- CheckDeleteExpr(destructorDecl, deleteExpr, memberExpr, "rather manage with std::some_container<std::unique_ptr<T>>");
+ CheckDeleteExpr(methodDecl, deleteExpr, memberExpr, "rather manage with std::some_container<std::unique_ptr<T>>");
}
bool UseUniquePtr::VisitCompoundStmt(const CompoundStmt* compoundStmt)