diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-10-27 10:54:31 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-10-27 13:55:43 +0200 |
commit | 569c7da252be05366980ae88ce30ef17f6e61d8c (patch) | |
tree | 2506933ed4caae9602d042f1eaddaf7bd73814d0 /compilerplugins/clang/constparams.cxx | |
parent | 5670f65ccea6c47b17ec010fd15edcee5522086b (diff) |
extract some common code for checking if a functions address was taken
Change-Id: I292b4e9bf17c83f83ff43ac4c5870d33092d0c71
Diffstat (limited to 'compilerplugins/clang/constparams.cxx')
-rw-r--r-- | compilerplugins/clang/constparams.cxx | 91 |
1 files changed, 5 insertions, 86 deletions
diff --git a/compilerplugins/clang/constparams.cxx b/compilerplugins/clang/constparams.cxx index bf715d16e91a..8396f2dad6ec 100644 --- a/compilerplugins/clang/constparams.cxx +++ b/compilerplugins/clang/constparams.cxx @@ -16,6 +16,7 @@ #include "plugin.hxx" #include "compat.hxx" #include "check.hxx" +#include "functionaddress.hxx" /** Find pointer and reference params that can be declared const. @@ -31,10 +32,10 @@ static bool startswith(const std::string& rStr, const char* pSubStr) { } class ConstParams: - public RecursiveASTVisitor<ConstParams>, public loplugin::Plugin + public loplugin::FunctionAddress<ConstParams> { public: - explicit ConstParams(InstantiationData const & data): Plugin(data) {} + explicit ConstParams(InstantiationData const & data): loplugin::FunctionAddress<ConstParams>(data) {} virtual void run() override { std::string fn( compiler.getSourceManager().getFileEntryForID( @@ -63,8 +64,8 @@ public: if (paramCannotBeConstSet.find(pParmVarDecl) == paramCannotBeConstSet.end()) { auto functionDecl = parmToFunction[pParmVarDecl]; auto canonicalDecl = functionDecl->getCanonicalDecl(); - if (ignoredFunctions_.find(canonicalDecl) - != ignoredFunctions_.end()) + if (getFunctionsWithAddressTaken().find(canonicalDecl) + != getFunctionsWithAddressTaken().end()) { continue; } @@ -86,86 +87,6 @@ public: } } - bool TraverseCallExpr(CallExpr * expr) { - auto const saved = callee_; - callee_ = expr->getCallee(); - auto const ret = RecursiveASTVisitor::TraverseCallExpr(expr); - callee_ = saved; - return ret; - } - - bool TraverseCXXOperatorCallExpr(CXXOperatorCallExpr * expr) { - auto const saved = callee_; - callee_ = expr->getCallee(); - auto const ret = RecursiveASTVisitor::TraverseCXXOperatorCallExpr(expr); - callee_ = saved; - return ret; - } - - bool TraverseCXXMemberCallExpr(CXXMemberCallExpr * expr) { - auto const saved = callee_; - callee_ = expr->getCallee(); - auto const ret = RecursiveASTVisitor::TraverseCXXMemberCallExpr(expr); - callee_ = saved; - return ret; - } - - bool TraverseCUDAKernelCallExpr(CUDAKernelCallExpr * expr) { - auto const saved = callee_; - callee_ = expr->getCallee(); - auto const ret = RecursiveASTVisitor::TraverseCUDAKernelCallExpr(expr); - callee_ = saved; - return ret; - } - - bool TraverseUserDefinedLiteral(UserDefinedLiteral * expr) { - auto const saved = callee_; - callee_ = expr->getCallee(); - auto const ret = RecursiveASTVisitor::TraverseUserDefinedLiteral(expr); - callee_ = saved; - return ret; - } - - bool VisitImplicitCastExpr(ImplicitCastExpr const * expr) { - if (expr == callee_) { - return true; - } - if (ignoreLocation(expr)) { - return true; - } - if (expr->getCastKind() != CK_FunctionToPointerDecay) { - return true; - } - auto const dre = dyn_cast<DeclRefExpr>( - expr->getSubExpr()->IgnoreParens()); - if (dre == nullptr) { - return true; - } - auto const fd = dyn_cast<FunctionDecl>(dre->getDecl()); - if (fd == nullptr) { - return true; - } - ignoredFunctions_.insert(fd->getCanonicalDecl()); - return true; - } - - bool VisitUnaryAddrOf(UnaryOperator const * expr) { - if (ignoreLocation(expr)) { - return true; - } - auto const dre = dyn_cast<DeclRefExpr>( - expr->getSubExpr()->IgnoreParenImpCasts()); - if (dre == nullptr) { - return true; - } - auto const fd = dyn_cast<FunctionDecl>(dre->getDecl()); - if (fd == nullptr) { - return true; - } - ignoredFunctions_.insert(fd->getCanonicalDecl()); - return true; - } - bool VisitFunctionDecl(const FunctionDecl *); bool VisitDeclRefExpr(const DeclRefExpr *); @@ -176,8 +97,6 @@ private: std::unordered_set<const ParmVarDecl*> interestingParamSet; std::unordered_map<const ParmVarDecl*, const FunctionDecl*> parmToFunction; std::unordered_set<const ParmVarDecl*> paramCannotBeConstSet; - std::unordered_set<FunctionDecl const *> ignoredFunctions_; - Expr const * callee_ = nullptr; }; bool ConstParams::VisitFunctionDecl(const FunctionDecl * functionDecl) |