summaryrefslogtreecommitdiff
path: root/compilerplugins/clang/unusedvarsglobal.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'compilerplugins/clang/unusedvarsglobal.cxx')
-rw-r--r--compilerplugins/clang/unusedvarsglobal.cxx42
1 files changed, 15 insertions, 27 deletions
diff --git a/compilerplugins/clang/unusedvarsglobal.cxx b/compilerplugins/clang/unusedvarsglobal.cxx
index 508da0cb451f..f74bfedb6c0d 100644
--- a/compilerplugins/clang/unusedvarsglobal.cxx
+++ b/compilerplugins/clang/unusedvarsglobal.cxx
@@ -25,9 +25,7 @@
#include "compat.hxx"
#include "check.hxx"
-#if CLANG_VERSION >= 110000
#include "clang/AST/ParentMapContext.h"
-#endif
/**
This performs two analyses:
@@ -167,7 +165,7 @@ private:
bool checkForWriteWhenUsingCollectionType(const CXXMethodDecl* calleeMethodDecl);
bool IsPassedByNonConst(const VarDecl* fieldDecl, const Stmt* child, CallerWrapper callExpr,
CalleeWrapper calleeFunctionDecl);
- llvm::Optional<CalleeWrapper> getCallee(CallExpr const*);
+ compat::optional<CalleeWrapper> getCallee(CallExpr const*);
// For reasons I do not understand, parentFunctionDecl() is not reliable, so
// we store the parent function on the way down the AST.
@@ -177,6 +175,8 @@ private:
void UnusedVarsGlobal::run()
{
+ handler.enableTreeWideAnalysisMode();
+
TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
if (!isUnitTestMode())
@@ -199,9 +199,9 @@ void UnusedVarsGlobal::run()
else
{
for (const MyVarInfo& s : readFromSet)
- report(DiagnosticsEngine::Warning, "read", compat::getBeginLoc(s.varDecl));
+ report(DiagnosticsEngine::Warning, "read", s.varDecl->getBeginLoc());
for (const MyVarInfo& s : writeToSet)
- report(DiagnosticsEngine::Warning, "write", compat::getBeginLoc(s.varDecl));
+ report(DiagnosticsEngine::Warning, "write", s.varDecl->getBeginLoc());
}
}
@@ -334,8 +334,8 @@ bool UnusedVarsGlobal::isSomeKindOfZero(const Expr* arg)
// Get the expression contents.
// This helps us find params which are always initialised with something like "OUString()".
SourceManager& SM = compiler.getSourceManager();
- SourceLocation startLoc = compat::getBeginLoc(arg);
- SourceLocation endLoc = compat::getEndLoc(arg);
+ SourceLocation startLoc = arg->getBeginLoc();
+ SourceLocation endLoc = arg->getEndLoc();
const char* p1 = SM.getCharacterData(startLoc);
const char* p2 = SM.getCharacterData(endLoc);
if (!p1 || !p2 || (p2 - p1) < 0 || (p2 - p1) > 40)
@@ -352,12 +352,6 @@ bool UnusedVarsGlobal::isSomeKindOfZero(const Expr* arg)
return true;
else if (s == "OString()")
return true;
- else if (s == "aEmptyOUStr") //sw
- return true;
- else if (s == "EMPTY_OUSTRING") //sc
- return true;
- else if (s == "GetEmptyOUString()") //sc
- return true;
return false;
}
@@ -610,10 +604,7 @@ void UnusedVarsGlobal::checkIfReadFrom(const VarDecl* varDecl, const DeclRefExpr
|| isa<CXXTypeidExpr>(parent) || isa<DefaultStmt>(parent)
|| isa<GCCAsmStmt>(parent) || isa<LambdaExpr>(parent) // TODO
|| isa<CXXDefaultArgExpr>(parent) || isa<AtomicExpr>(parent)
- || isa<VAArgExpr>(parent) || isa<DeclRefExpr>(parent)
-#if CLANG_VERSION >= 80000
- || isa<ConstantExpr>(parent)
-#endif
+ || isa<VAArgExpr>(parent) || isa<DeclRefExpr>(parent) || isa<ConstantExpr>(parent)
|| isa<SubstNonTypeTemplateParmExpr>(parent))
{
break;
@@ -629,9 +620,9 @@ void UnusedVarsGlobal::checkIfReadFrom(const VarDecl* varDecl, const DeclRefExpr
if (bDump)
{
report(DiagnosticsEngine::Warning, "oh dear, what can the matter be?",
- compat::getBeginLoc(declRefExpr))
+ declRefExpr->getBeginLoc())
<< declRefExpr->getSourceRange();
- report(DiagnosticsEngine::Note, "parent over here", compat::getBeginLoc(parent))
+ report(DiagnosticsEngine::Note, "parent over here", parent->getBeginLoc())
<< parent->getSourceRange();
parent->dump();
declRefExpr->dump();
@@ -819,10 +810,7 @@ void UnusedVarsGlobal::checkIfWrittenTo(const VarDecl* varDecl, const DeclRefExp
|| isa<UnaryExprOrTypeTraitExpr>(parent) || isa<CXXUnresolvedConstructExpr>(parent)
|| isa<CompoundStmt>(parent) || isa<LabelStmt>(parent)
|| isa<CXXForRangeStmt>(parent) || isa<CXXTypeidExpr>(parent)
- || isa<DefaultStmt>(parent) || isa<GCCAsmStmt>(parent)
-#if CLANG_VERSION >= 80000
- || isa<ConstantExpr>(parent)
-#endif
+ || isa<DefaultStmt>(parent) || isa<GCCAsmStmt>(parent) || isa<ConstantExpr>(parent)
|| isa<AtomicExpr>(parent) || isa<CXXDefaultArgExpr>(parent)
|| isa<VAArgExpr>(parent) || isa<DeclRefExpr>(parent)
|| isa<SubstNonTypeTemplateParmExpr>(parent) || isa<LambdaExpr>(parent)) // TODO
@@ -840,11 +828,11 @@ void UnusedVarsGlobal::checkIfWrittenTo(const VarDecl* varDecl, const DeclRefExp
if (bDump)
{
report(DiagnosticsEngine::Warning, "oh dear, what can the matter be? writtenTo=%0",
- compat::getBeginLoc(declRefExpr))
+ declRefExpr->getBeginLoc())
<< bPotentiallyWrittenTo << declRefExpr->getSourceRange();
if (parent)
{
- report(DiagnosticsEngine::Note, "parent over here", compat::getBeginLoc(parent))
+ report(DiagnosticsEngine::Note, "parent over here", parent->getBeginLoc())
<< parent->getSourceRange();
parent->dump();
}
@@ -944,7 +932,7 @@ bool UnusedVarsGlobal::IsPassedByNonConst(const VarDecl* varDecl, const Stmt* ch
return false;
}
-llvm::Optional<CalleeWrapper> UnusedVarsGlobal::getCallee(CallExpr const* callExpr)
+compat::optional<CalleeWrapper> UnusedVarsGlobal::getCallee(CallExpr const* callExpr)
{
FunctionDecl const* functionDecl = callExpr->getDirectCallee();
if (functionDecl)
@@ -962,7 +950,7 @@ llvm::Optional<CalleeWrapper> UnusedVarsGlobal::getCallee(CallExpr const* callEx
}
}
- return llvm::Optional<CalleeWrapper>();
+ return compat::optional<CalleeWrapper>();
}
loplugin::Plugin::Registration<UnusedVarsGlobal> X("unusedvarsglobal", false);