summaryrefslogtreecommitdiff
path: root/compilerplugins/clang/writeonlyvars.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'compilerplugins/clang/writeonlyvars.cxx')
-rw-r--r--compilerplugins/clang/writeonlyvars.cxx49
1 files changed, 17 insertions, 32 deletions
diff --git a/compilerplugins/clang/writeonlyvars.cxx b/compilerplugins/clang/writeonlyvars.cxx
index 51a967dac8a0..3fb3f769b72d 100644
--- a/compilerplugins/clang/writeonlyvars.cxx
+++ b/compilerplugins/clang/writeonlyvars.cxx
@@ -22,12 +22,10 @@
#include "config_clang.h"
#include "plugin.hxx"
-#include "compat.hxx"
#include "check.hxx"
+#include "compat.hxx"
-#if CLANG_VERSION >= 110000
#include "clang/AST/ParentMapContext.h"
-#endif
/**
Finds variables that are effectively write-only.
@@ -164,7 +162,7 @@ private:
bool checkForWriteWhenUsingCollectionType(const CXXMethodDecl* calleeMethodDecl);
bool IsPassedByNonConst(const VarDecl* varDecl, 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.
@@ -188,9 +186,6 @@ void WriteOnlyVars::run()
// false+
if (loplugin::isSamePathname(fn, SRCDIR "/store/source/storpage.cxx"))
return;
- // yydebug?
- if (loplugin::isSamePathname(fn, SRCDIR "/idlc/source/idlccompile.cxx"))
- return;
if (fn.contains("/qa/"))
return;
if (fn.contains("/vcl/workben/"))
@@ -420,8 +415,6 @@ void WriteOnlyVars::run()
return;
if (loplugin::isSamePathname(fn, SRCDIR "/sd/source/filter/xml/sdxmlwrp.cxx"))
return;
- if (loplugin::isSamePathname(fn, SRCDIR "/sd/source/filter/html/pubdlg.cxx"))
- return;
if (loplugin::isSamePathname(fn, SRCDIR "/sw/source/core/txtnode/thints.cxx"))
return;
if (loplugin::isSamePathname(fn, SRCDIR "/sw/source/core/doc/docbm.cxx"))
@@ -484,18 +477,16 @@ void WriteOnlyVars::run()
bool read = readFromSet.find(v) != readFromSet.end();
bool write = writeToSet.find(v) != writeToSet.end();
if (!read && write)
- report(DiagnosticsEngine::Warning, "write-only %0", compat::getBeginLoc(v.varDecl))
+ report(DiagnosticsEngine::Warning, "write-only %0", v.varDecl->getBeginLoc())
<< v.varName;
}
}
else
{
for (const MyVarInfo& s : readFromSet)
- report(DiagnosticsEngine::Warning, "read %0", compat::getBeginLoc(s.varDecl))
- << s.varName;
+ report(DiagnosticsEngine::Warning, "read %0", s.varDecl->getBeginLoc()) << s.varName;
for (const MyVarInfo& s : writeToSet)
- report(DiagnosticsEngine::Warning, "write %0", compat::getBeginLoc(s.varDecl))
- << s.varName;
+ report(DiagnosticsEngine::Warning, "write %0", s.varDecl->getBeginLoc()) << s.varName;
}
}
@@ -550,9 +541,9 @@ bool WriteOnlyVars::VisitVarDecl(const VarDecl* varDecl)
return true;
if (!compiler.getSourceManager().isInMainFile(varDecl->getLocation()))
return true;
- if (compiler.getSourceManager().isMacroBodyExpansion(compat::getBeginLoc(varDecl)))
+ if (compiler.getSourceManager().isMacroBodyExpansion(varDecl->getBeginLoc()))
return true;
- if (compiler.getSourceManager().isMacroArgExpansion(compat::getBeginLoc(varDecl)))
+ if (compiler.getSourceManager().isMacroArgExpansion(varDecl->getBeginLoc()))
return true;
// ignore stuff that forms part of the stable URE interface
if (isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc(varDecl->getLocation())))
@@ -763,10 +754,7 @@ void WriteOnlyVars::checkIfReadFrom(const VarDecl* varDecl, const Expr* memberEx
|| isa<CXXUnresolvedConstructExpr>(parent) || isa<CompoundStmt>(parent)
|| isa<LabelStmt>(parent) || isa<CXXForRangeStmt>(parent)
|| isa<CXXTypeidExpr>(parent) || isa<DefaultStmt>(parent)
- || isa<GCCAsmStmt>(parent) || isa<VAArgExpr>(parent)
-#if CLANG_VERSION >= 80000
- || isa<ConstantExpr>(parent)
-#endif
+ || isa<GCCAsmStmt>(parent) || isa<VAArgExpr>(parent) || isa<ConstantExpr>(parent)
|| isa<CXXDefaultArgExpr>(parent) || isa<LambdaExpr>(parent))
{
break;
@@ -782,9 +770,9 @@ void WriteOnlyVars::checkIfReadFrom(const VarDecl* varDecl, const Expr* memberEx
if (bDump)
{
report(DiagnosticsEngine::Warning, "oh dear, what can the matter be?",
- compat::getBeginLoc(memberExpr))
+ memberExpr->getBeginLoc())
<< memberExpr->getSourceRange();
- report(DiagnosticsEngine::Note, "parent over here", compat::getBeginLoc(parent))
+ report(DiagnosticsEngine::Note, "parent over here", parent->getBeginLoc())
<< parent->getSourceRange();
parent->dump();
memberExpr->dump();
@@ -975,12 +963,9 @@ void WriteOnlyVars::checkIfWrittenTo(const VarDecl* varDecl, const Expr* memberE
|| isa<UnaryExprOrTypeTraitExpr>(parent) || isa<CXXUnresolvedConstructExpr>(parent)
|| isa<CompoundStmt>(parent) || isa<LabelStmt>(parent)
|| isa<CXXForRangeStmt>(parent) || isa<CXXTypeidExpr>(parent)
- || isa<DefaultStmt>(parent)
-#if CLANG_VERSION >= 80000
- || isa<ConstantExpr>(parent)
-#endif
- || isa<GCCAsmStmt>(parent) || isa<VAArgExpr>(parent)
- || isa<CXXDefaultArgExpr>(parent) || isa<LambdaExpr>(parent))
+ || isa<DefaultStmt>(parent) || isa<ConstantExpr>(parent) || isa<GCCAsmStmt>(parent)
+ || isa<VAArgExpr>(parent) || isa<CXXDefaultArgExpr>(parent)
+ || isa<LambdaExpr>(parent))
{
break;
}
@@ -995,11 +980,11 @@ void WriteOnlyVars::checkIfWrittenTo(const VarDecl* varDecl, const Expr* memberE
if (bDump)
{
report(DiagnosticsEngine::Warning, "oh dear2, what can the matter be? writtenTo=%0",
- compat::getBeginLoc(memberExpr))
+ memberExpr->getBeginLoc())
<< bPotentiallyWrittenTo << memberExpr->getSourceRange();
if (parent)
{
- report(DiagnosticsEngine::Note, "parent over here", compat::getBeginLoc(parent))
+ report(DiagnosticsEngine::Note, "parent over here", parent->getBeginLoc())
<< parent->getSourceRange();
parent->dump();
}
@@ -1124,7 +1109,7 @@ bool WriteOnlyVars::VisitDeclRefExpr(const DeclRefExpr* declRefExpr)
return true;
}
-llvm::Optional<CalleeWrapper> WriteOnlyVars::getCallee(CallExpr const* callExpr)
+compat::optional<CalleeWrapper> WriteOnlyVars::getCallee(CallExpr const* callExpr)
{
FunctionDecl const* functionDecl = callExpr->getDirectCallee();
if (functionDecl)
@@ -1142,7 +1127,7 @@ llvm::Optional<CalleeWrapper> WriteOnlyVars::getCallee(CallExpr const* callExpr)
}
}
- return llvm::Optional<CalleeWrapper>();
+ return compat::optional<CalleeWrapper>();
}
loplugin::Plugin::Registration<WriteOnlyVars> X("writeonlyvars", false);