summaryrefslogtreecommitdiffstats
path: root/compilerplugins/clang/plugin.cxx
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2020-03-06 14:40:40 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2020-03-09 11:33:43 +0100
commitabe39f7781f59b96c5a8d3dd5b41c60fdf04ad84 (patch)
tree0f72d1968e5f25e3f280688a414398e3f4a7cce8 /compilerplugins/clang/plugin.cxx
parenttdf43157:Clean up OSL_ASSERT, DBG_ASSERT, etc.. (diff)
downloadcore-abe39f7781f59b96c5a8d3dd5b41c60fdf04ad84.tar.gz
core-abe39f7781f59b96c5a8d3dd5b41c60fdf04ad84.zip
improve loplugin:unusedfields
noticed something that wasn't being picked up, wrote some tests, and found an unhandled case in Plugin::getParentFunctionDecl Change-Id: I52b4ea273be6614e197392dfc4d6053bbc1704de Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90141 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins/clang/plugin.cxx')
-rw-r--r--compilerplugins/clang/plugin.cxx24
1 files changed, 23 insertions, 1 deletions
diff --git a/compilerplugins/clang/plugin.cxx b/compilerplugins/clang/plugin.cxx
index c6591d6b4fd5..d2555eb034c2 100644
--- a/compilerplugins/clang/plugin.cxx
+++ b/compilerplugins/clang/plugin.cxx
@@ -217,9 +217,31 @@ static const Decl* getDeclContext(ASTContext& context, const Stmt* stmt)
return nullptr;
}
+static const Decl* getFunctionDeclContext(ASTContext& context, const Stmt* stmt)
+{
+ auto it = context.getParents(*stmt).begin();
+
+ if (it == context.getParents(*stmt).end())
+ return nullptr;
+
+ const Decl *decl = it->get<Decl>();
+ if (decl)
+ {
+ if (isa<VarDecl>(decl))
+ return dyn_cast<FunctionDecl>(decl->getDeclContext());
+ return decl;
+ }
+
+ stmt = it->get<Stmt>();
+ if (stmt)
+ return getFunctionDeclContext(context, stmt);
+
+ return nullptr;
+}
+
const FunctionDecl* Plugin::getParentFunctionDecl( const Stmt* stmt )
{
- const Decl *decl = getDeclContext(compiler.getASTContext(), stmt);
+ const Decl *decl = getFunctionDeclContext(compiler.getASTContext(), stmt);
if (decl)
return static_cast<const FunctionDecl*>(decl->getNonClosureContext());