diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2022-02-15 15:03:24 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2022-02-17 21:45:06 +0100 |
commit | d1a2b80b9dc146c7fe63d2657e5506f49d6e5c0d (patch) | |
tree | 7ceeb7e977c660d5b69bc93e8327674b7ea1ae5d /compilerplugins | |
parent | eed401bc7429f29f1b21cf8e3b08969e011d5692 (diff) |
Bump compiler plugins Clang baseline to 12.0.1
...as discussed in the mail thread starting at
<https://lists.freedesktop.org/archives/libreoffice/2020-November/086234.html>
"Bump --enable-compiler-plugins Clang baseline?" (and now picked up again at
<https://lists.freedesktop.org/archives/libreoffice/2022-February/088459.html>
"Re: Bump --enable-compiler-plugins Clang baseline?"), and clean up
compilerplugins/clang/ accordingly
Change-Id: I5e81c6fdcc363aeefd6227606225b526fdf7ac16
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129989
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'compilerplugins')
141 files changed, 723 insertions, 1193 deletions
diff --git a/compilerplugins/clang/automem.cxx b/compilerplugins/clang/automem.cxx index 099c05458e13..92478b9fbb95 100644 --- a/compilerplugins/clang/automem.cxx +++ b/compilerplugins/clang/automem.cxx @@ -13,6 +13,7 @@ #include <iostream> #include <fstream> #include <set> +#include "config_clang.h" #include "plugin.hxx" /** @@ -51,7 +52,7 @@ bool AutoMem::VisitCXXDeleteExpr(const CXXDeleteExpr* expr) { if (ignoreLocation( expr )) return true; - StringRef aFileName = getFilenameOfLocation(compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(expr))); + StringRef aFileName = getFilenameOfLocation(compiler.getSourceManager().getSpellingLoc(expr->getBeginLoc())); if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/include/salhelper/") || loplugin::hasPathnamePrefix(aFileName, SRCDIR "/include/osl/") || loplugin::hasPathnamePrefix(aFileName, SRCDIR "/salhelper/") @@ -79,7 +80,7 @@ bool AutoMem::VisitCXXDeleteExpr(const CXXDeleteExpr* expr) report( DiagnosticsEngine::Warning, "calling delete on object field, rather use std::unique_ptr or std::scoped_ptr", - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getSourceRange(); return true; } diff --git a/compilerplugins/clang/blockblock.cxx b/compilerplugins/clang/blockblock.cxx index f1d9ec7a9d61..bfcb0206df0f 100644 --- a/compilerplugins/clang/blockblock.cxx +++ b/compilerplugins/clang/blockblock.cxx @@ -14,6 +14,7 @@ #include <iostream> #include <fstream> #include <set> +#include "config_clang.h" #include "plugin.hxx" /** @@ -55,9 +56,9 @@ bool BlockBlock::VisitCompoundStmt(CompoundStmt const * compound) auto inner = *compound->body_begin(); if (!isa<CompoundStmt>(inner)) return true; - if (compiler.getSourceManager().isMacroBodyExpansion(compat::getBeginLoc(compound))) + if (compiler.getSourceManager().isMacroBodyExpansion(compound->getBeginLoc())) return true; - if (compiler.getSourceManager().isMacroBodyExpansion(compat::getBeginLoc(inner))) + if (compiler.getSourceManager().isMacroBodyExpansion(inner->getBeginLoc())) return true; if (containsPreprocessingConditionalInclusion(compound->getSourceRange())) { return true; @@ -65,12 +66,12 @@ bool BlockBlock::VisitCompoundStmt(CompoundStmt const * compound) report( DiagnosticsEngine::Warning, "block directly inside block", - compat::getBeginLoc(compound)) + compound->getBeginLoc()) << compound->getSourceRange(); report( DiagnosticsEngine::Note, "inner block here", - compat::getBeginLoc(inner)) + inner->getBeginLoc()) << inner->getSourceRange(); return true; } @@ -94,7 +95,7 @@ bool BlockBlock::VisitCaseStmt(CaseStmt const * caseStmt) report( DiagnosticsEngine::Warning, "block directly inside block", - compat::getBeginLoc(compoundStmt)) + compoundStmt->getBeginLoc()) << compoundStmt->getSourceRange(); return true; } diff --git a/compilerplugins/clang/bufferadd.cxx b/compilerplugins/clang/bufferadd.cxx index cf2b6a011b4a..7b3eaf7e416e 100644 --- a/compilerplugins/clang/bufferadd.cxx +++ b/compilerplugins/clang/bufferadd.cxx @@ -15,6 +15,7 @@ #include "plugin.hxx" #include "check.hxx" +#include "config_clang.h" #include "clang/AST/CXXInheritance.h" #include "clang/AST/StmtVisitor.h" @@ -65,7 +66,7 @@ public: && badMap.find(pair.first) == badMap.end()) report(DiagnosticsEngine::Warning, "convert this append sequence into a *String + sequence", - compat::getBeginLoc(pair.first)) + pair.first->getBeginLoc()) << pair.first->getSourceRange(); } @@ -290,7 +291,7 @@ bool BufferAdd::isMethodOkToMerge(CXXMemberCallExpr const* memberCall) Expr const* BufferAdd::ignore(Expr const* expr) { - return compat::IgnoreImplicit(compat::IgnoreImplicit(expr)->IgnoreParens()); + return expr->IgnoreImplicit()->IgnoreParens()->IgnoreImplicit(); } bool BufferAdd::isSideEffectFree(Expr const* expr) diff --git a/compilerplugins/clang/buriedassign.cxx b/compilerplugins/clang/buriedassign.cxx index e1932c821e21..acc8bfe7dd67 100644 --- a/compilerplugins/clang/buriedassign.cxx +++ b/compilerplugins/clang/buriedassign.cxx @@ -14,6 +14,7 @@ #include "plugin.hxx" #include "check.hxx" +#include "config_clang.h" #include "clang/AST/CXXInheritance.h" #include "clang/AST/StmtVisitor.h" @@ -257,13 +258,13 @@ static bool isAssignmentOp(clang::OverloadedOperatorKind Opc) static const Expr* IgnoreImplicitAndConversionOperator(const Expr* expr) { - expr = compat::IgnoreImplicit(expr); + expr = expr->IgnoreImplicit(); if (auto memberCall = dyn_cast<CXXMemberCallExpr>(expr)) { if (auto conversionDecl = dyn_cast_or_null<CXXConversionDecl>(memberCall->getMethodDecl())) { if (!conversionDecl->isExplicit()) - expr = compat::IgnoreImplicit(memberCall->getImplicitObjectArgument()); + expr = memberCall->getImplicitObjectArgument()->IgnoreImplicit(); } } return expr; @@ -273,7 +274,7 @@ bool BuriedAssign::VisitBinaryOperator(BinaryOperator const* binaryOp) { if (ignoreLocation(binaryOp)) return true; - if (compat::getBeginLoc(binaryOp).isMacroID()) + if (binaryOp->getBeginLoc().isMacroID()) return true; if (!isAssignmentOp(binaryOp->getOpcode())) return true; @@ -302,12 +303,12 @@ bool BuriedAssign::VisitBinaryOperator(BinaryOperator const* binaryOp) // assignment in constructor StringRef aFileName = getFilenameOfLocation( - compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(binaryOp))); + compiler.getSourceManager().getSpellingLoc(binaryOp->getBeginLoc())); if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/include/comphelper/flagguard.hxx")) return true; report(DiagnosticsEngine::Warning, "buried assignment, rather put on own line", - compat::getBeginLoc(binaryOp)) + binaryOp->getBeginLoc()) << binaryOp->getSourceRange(); //getParentStmt(getParentStmt(getParentStmt(getParentStmt(getParentStmt(getParentStmt(binaryOp))))))->dump(); return true; @@ -317,7 +318,7 @@ bool BuriedAssign::VisitCXXOperatorCallExpr(CXXOperatorCallExpr const* cxxOper) { if (ignoreLocation(cxxOper)) return true; - if (compat::getBeginLoc(cxxOper).isMacroID()) + if (cxxOper->getBeginLoc().isMacroID()) return true; if (!isAssignmentOp(cxxOper->getOperator())) return true; @@ -344,7 +345,7 @@ bool BuriedAssign::VisitCXXOperatorCallExpr(CXXOperatorCallExpr const* cxxOper) if (!m_handled.insert(cxxOper).second) return true; report(DiagnosticsEngine::Warning, "buried assignment, rather put on own line", - compat::getBeginLoc(cxxOper)) + cxxOper->getBeginLoc()) << cxxOper->getSourceRange(); //getParentStmt(getParentStmt(getParentStmt(getParentStmt(getParentStmt(cxxOper)))))->dump(); return true; @@ -358,7 +359,7 @@ bool BuriedAssign::VisitCompoundStmt(CompoundStmt const* compoundStmt) { if (auto expr = dyn_cast<Expr>(*i)) { - expr = compat::IgnoreImplicit(expr); + expr = expr->IgnoreImplicit(); if (auto binaryOp = dyn_cast<BinaryOperator>(expr)) { // ignore comma-chained statements at this level @@ -379,7 +380,7 @@ void BuriedAssign::MarkIfAssignment(Stmt const* stmt) { if (auto expr = dyn_cast_or_null<Expr>(stmt)) { - expr = compat::IgnoreImplicit(expr); + expr = expr->IgnoreImplicit(); if (auto binaryOp = dyn_cast<BinaryOperator>(expr)) { if (isAssignmentOp(binaryOp->getOpcode())) @@ -434,7 +435,7 @@ bool BuriedAssign::VisitIfStmt(IfStmt const* ifStmt) if (isAssignmentOp(binaryOp->getOpcode())) { report(DiagnosticsEngine::Warning, "buried assignment, rather put on own line", - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getSourceRange(); } else if (binaryOp->isComparisonOp()) @@ -446,7 +447,7 @@ bool BuriedAssign::VisitIfStmt(IfStmt const* ifStmt) && binaryOp->getRHS()->isCXX11ConstantExpr(compiler.getASTContext()) && isAssignmentOp(binaryOp2->getOpcode())) report(DiagnosticsEngine::Warning, "buried assignment, rather put on own line", - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getSourceRange(); } if (auto binaryOp2 @@ -456,7 +457,7 @@ bool BuriedAssign::VisitIfStmt(IfStmt const* ifStmt) && binaryOp->getLHS()->isCXX11ConstantExpr(compiler.getASTContext()) && isAssignmentOp(binaryOp2->getOpcode())) report(DiagnosticsEngine::Warning, "buried assignment, rather put on own line", - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getSourceRange(); } } @@ -467,7 +468,7 @@ bool BuriedAssign::VisitIfStmt(IfStmt const* ifStmt) { if (isAssignmentOp(binaryOp2->getOpcode())) report(DiagnosticsEngine::Warning, "buried assignment, rather put on own line", - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getSourceRange(); } } @@ -479,7 +480,7 @@ bool BuriedAssign::VisitIfStmt(IfStmt const* ifStmt) if (isAssignmentOp(operCall->getOperator())) { report(DiagnosticsEngine::Warning, "buried assignment, rather put on own line", - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getSourceRange(); } } @@ -531,7 +532,7 @@ void BuriedAssign::MarkConditionForControlLoops(Expr const* expr) { if (!expr) return; - expr = compat::IgnoreImplicit(expr); + expr = expr->IgnoreImplicit(); if (auto binaryOp = dyn_cast<BinaryOperator>(expr)) { @@ -550,7 +551,7 @@ void BuriedAssign::MarkConditionForControlLoops(Expr const* expr) if (memberCall->getMethodDecl() && isa<CXXConversionDecl>(memberCall->getMethodDecl())) { // TODO check that the conversion is converting to bool - expr = compat::IgnoreImplicit(memberCall->getImplicitObjectArgument()); + expr = memberCall->getImplicitObjectArgument()->IgnoreImplicit(); } } @@ -559,31 +560,31 @@ void BuriedAssign::MarkConditionForControlLoops(Expr const* expr) // handle: ((xxx = foo()) != error) if (binaryOp->isComparisonOp()) { - MarkIfAssignment(compat::IgnoreImplicit(binaryOp->getLHS())->IgnoreParens()); - MarkIfAssignment(compat::IgnoreImplicit(binaryOp->getRHS())->IgnoreParens()); + MarkIfAssignment(binaryOp->getLHS()->IgnoreImplicit()->IgnoreParens()); + MarkIfAssignment(binaryOp->getRHS()->IgnoreImplicit()->IgnoreParens()); } } else if (auto cxxOper = dyn_cast<CXXOperatorCallExpr>(expr)) { // handle: ((xxx = foo()) != error) - if (compat::isComparisonOp(cxxOper)) + if (cxxOper->isComparisonOp()) { - MarkIfAssignment(compat::IgnoreImplicit(cxxOper->getArg(0))->IgnoreParens()); - MarkIfAssignment(compat::IgnoreImplicit(cxxOper->getArg(1))->IgnoreParens()); + MarkIfAssignment(cxxOper->getArg(0)->IgnoreImplicit()->IgnoreParens()); + MarkIfAssignment(cxxOper->getArg(1)->IgnoreImplicit()->IgnoreParens()); } // handle: (!(xxx = foo())) else if (cxxOper->getOperator() == OO_Exclaim) - MarkIfAssignment(compat::IgnoreImplicit(cxxOper->getArg(0))->IgnoreParens()); + MarkIfAssignment(cxxOper->getArg(0)->IgnoreImplicit()->IgnoreParens()); } else if (auto parenExpr = dyn_cast<ParenExpr>(expr)) { // handle: ((xxx = foo())) - MarkIfAssignment(compat::IgnoreImplicit(parenExpr->getSubExpr())); + MarkIfAssignment(parenExpr->getSubExpr()->IgnoreImplicit()); } else if (auto unaryOp = dyn_cast<UnaryOperator>(expr)) { // handle: (!(xxx = foo())) - MarkIfAssignment(compat::IgnoreImplicit(unaryOp->getSubExpr())->IgnoreParens()); + MarkIfAssignment(unaryOp->getSubExpr()->IgnoreImplicit()->IgnoreParens()); } else MarkIfAssignment(expr); diff --git a/compilerplugins/clang/casttovoid.cxx b/compilerplugins/clang/casttovoid.cxx index 1717fa09a516..63f1efdd85a5 100644 --- a/compilerplugins/clang/casttovoid.cxx +++ b/compilerplugins/clang/casttovoid.cxx @@ -15,7 +15,6 @@ #include "clang/AST/Attr.h" #include "check.hxx" -#include "compat.hxx" #include "plugin.hxx" namespace { @@ -464,7 +463,7 @@ private: return nullptr; } if (compiler.getSourceManager().isMacroBodyExpansion( - compat::getBeginLoc(expr))) + expr->getBeginLoc())) { return nullptr; } @@ -511,7 +510,7 @@ private: if (usage.firstConsumption != nullptr) { return; } - auto const loc = compat::getBeginLoc(dre); + auto const loc = dre->getBeginLoc(); if (compiler.getSourceManager().isMacroArgExpansion(loc) && (Lexer::getImmediateMacroNameForDiagnostics( loc, compiler.getSourceManager(), compiler.getLangOpts()) diff --git a/compilerplugins/clang/changetoolsgen.cxx b/compilerplugins/clang/changetoolsgen.cxx index a8e9faf74014..f4b9b6168a57 100644 --- a/compilerplugins/clang/changetoolsgen.cxx +++ b/compilerplugins/clang/changetoolsgen.cxx @@ -111,7 +111,7 @@ bool ChangeToolsGen::VisitCXXMemberCallExpr(CXXMemberCallExpr const* call) if (auto unaryOp = dyn_cast<UnaryOperator>(parent)) { if (!ChangeUnaryOperator(unaryOp, call, methodName)) - report(DiagnosticsEngine::Warning, "Could not fix, unary", compat::getBeginLoc(call)); + report(DiagnosticsEngine::Warning, "Could not fix, unary", call->getBeginLoc()); return true; } auto binaryOp = dyn_cast<BinaryOperator>(parent); @@ -130,7 +130,7 @@ bool ChangeToolsGen::VisitCXXMemberCallExpr(CXXMemberCallExpr const* call) if (parent2 && isa<Expr>(parent2)) { report(DiagnosticsEngine::Warning, "Could not fix, embedded assign", - compat::getBeginLoc(call)); + call->getBeginLoc()); return true; } // Check for @@ -139,25 +139,25 @@ bool ChangeToolsGen::VisitCXXMemberCallExpr(CXXMemberCallExpr const* call) if (rhs->getOpcode() == BO_Assign) { report(DiagnosticsEngine::Warning, "Could not fix, double assign", - compat::getBeginLoc(call)); + call->getBeginLoc()); return true; } if (!ChangeAssignment(parent, methodName, setPrefix)) - report(DiagnosticsEngine::Warning, "Could not fix, assign", compat::getBeginLoc(call)); + report(DiagnosticsEngine::Warning, "Could not fix, assign", call->getBeginLoc()); return true; } if (opcode == BO_AddAssign || opcode == BO_SubAssign) { if (!ChangeBinaryOperatorPlusMinus(binaryOp, call, methodName)) report(DiagnosticsEngine::Warning, "Could not fix, assign-and-change", - compat::getBeginLoc(call)); + call->getBeginLoc()); return true; } else if (opcode == BO_RemAssign || opcode == BO_MulAssign || opcode == BO_DivAssign) { if (!ChangeBinaryOperatorOther(binaryOp, call, methodName, setPrefix)) report(DiagnosticsEngine::Warning, "Could not fix, assign-and-change", - compat::getBeginLoc(call)); + call->getBeginLoc()); return true; } else @@ -173,8 +173,8 @@ bool ChangeToolsGen::ChangeAssignment(Stmt const* parent, std::string const& met // and replace with // aRect.SetLeft( ... ); SourceManager& SM = compiler.getSourceManager(); - SourceLocation startLoc = SM.getExpansionLoc(compat::getBeginLoc(parent)); - SourceLocation endLoc = SM.getExpansionLoc(compat::getEndLoc(parent)); + SourceLocation startLoc = SM.getExpansionLoc(parent->getBeginLoc()); + SourceLocation endLoc = SM.getExpansionLoc(parent->getEndLoc()); const char* p1 = SM.getCharacterData(startLoc); const char* p2 = SM.getCharacterData(endLoc); unsigned n = Lexer::MeasureTokenLength(endLoc, SM, compiler.getLangOpts()); @@ -201,8 +201,8 @@ bool ChangeToolsGen::ChangeBinaryOperatorPlusMinus(BinaryOperator const* binaryO // and replace with // aRect.MoveLeft( ... ); SourceManager& SM = compiler.getSourceManager(); - SourceLocation startLoc = SM.getExpansionLoc(compat::getBeginLoc(binaryOp)); - SourceLocation endLoc = SM.getExpansionLoc(compat::getEndLoc(binaryOp)); + SourceLocation startLoc = SM.getExpansionLoc(binaryOp->getBeginLoc()); + SourceLocation endLoc = SM.getExpansionLoc(binaryOp->getEndLoc()); const char* p1 = SM.getCharacterData(startLoc); const char* p2 = SM.getCharacterData(endLoc); if (p2 < p1) // clang is misbehaving, appears to be macro constant related @@ -228,7 +228,7 @@ bool ChangeToolsGen::ChangeBinaryOperatorPlusMinus(BinaryOperator const* binaryO if (newText == callText) { report(DiagnosticsEngine::Warning, "binaryop-plusminus regex match failed", - compat::getBeginLoc(call)); + call->getBeginLoc()); return false; } @@ -245,8 +245,8 @@ bool ChangeToolsGen::ChangeBinaryOperatorOther(BinaryOperator const* binaryOp, // and replace with // aRect.SetLeft( aRect.GetLeft() + ... ); SourceManager& SM = compiler.getSourceManager(); - SourceLocation startLoc = SM.getExpansionLoc(compat::getBeginLoc(binaryOp)); - SourceLocation endLoc = SM.getExpansionLoc(compat::getEndLoc(binaryOp)); + SourceLocation startLoc = SM.getExpansionLoc(binaryOp->getBeginLoc()); + SourceLocation endLoc = SM.getExpansionLoc(binaryOp->getEndLoc()); const char* p1 = SM.getCharacterData(startLoc); const char* p2 = SM.getCharacterData(endLoc); if (p2 < p1) // clang is misbehaving, appears to be macro constant related @@ -284,7 +284,7 @@ bool ChangeToolsGen::ChangeBinaryOperatorOther(BinaryOperator const* binaryOp, if (newText == callText) { report(DiagnosticsEngine::Warning, "binaryop-other regex match failed %0", - compat::getBeginLoc(call)) + call->getBeginLoc()) << reString; return false; } @@ -308,8 +308,8 @@ bool ChangeToolsGen::ChangeUnaryOperator(UnaryOperator const* unaryOp, // aRect.MoveLeft( 1 ); SourceManager& SM = compiler.getSourceManager(); - SourceLocation startLoc = SM.getExpansionLoc(compat::getBeginLoc(unaryOp)); - SourceLocation endLoc = SM.getExpansionLoc(compat::getEndLoc(unaryOp)); + SourceLocation startLoc = SM.getExpansionLoc(unaryOp->getBeginLoc()); + SourceLocation endLoc = SM.getExpansionLoc(unaryOp->getEndLoc()); const char* p1 = SM.getCharacterData(startLoc); const char* p2 = SM.getCharacterData(endLoc); if (p2 < p1) // clang is misbehaving, appears to be macro constant related @@ -352,8 +352,7 @@ bool ChangeToolsGen::ChangeUnaryOperator(UnaryOperator const* unaryOp, } if (newText == callText) { - report(DiagnosticsEngine::Warning, "unaryop regex match failed %0", - compat::getBeginLoc(call)) + report(DiagnosticsEngine::Warning, "unaryop regex match failed %0", call->getBeginLoc()) << reString; return false; } diff --git a/compilerplugins/clang/checkconfigmacros.cxx b/compilerplugins/clang/checkconfigmacros.cxx index 6daa9ed2a17e..aea60ed561b5 100644 --- a/compilerplugins/clang/checkconfigmacros.cxx +++ b/compilerplugins/clang/checkconfigmacros.cxx @@ -14,6 +14,8 @@ #include "plugin.hxx" +#include "config_clang.h" + #include <clang/Lex/Preprocessor.h> namespace loplugin diff --git a/compilerplugins/clang/checkunusedparams.cxx b/compilerplugins/clang/checkunusedparams.cxx index fa930ba959c8..2f45049632d3 100644 --- a/compilerplugins/clang/checkunusedparams.cxx +++ b/compilerplugins/clang/checkunusedparams.cxx @@ -12,6 +12,8 @@ #include <set> #include <iostream> +#include "config_clang.h" + #include "plugin.hxx" /** @@ -205,7 +207,7 @@ bool CheckUnusedParams::VisitFunctionDecl(FunctionDecl const * decl) { return true; if (isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc(canon->getLocation()))) return true; - StringRef fn = getFilenameOfLocation(compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(canon))); + StringRef fn = getFilenameOfLocation(compiler.getSourceManager().getSpellingLoc(canon->getBeginLoc())); // Some backwards compat magic. // TODO Can probably be removed, but need to do some checking if (loplugin::isSamePathname(fn, SRCDIR "/include/sax/fshelper.hxx")) @@ -477,7 +479,7 @@ bool CheckUnusedParams::VisitFunctionDecl(FunctionDecl const * decl) { continue; } report( DiagnosticsEngine::Warning, - "unused param %0 in %1", compat::getBeginLoc(param)) + "unused param %0 in %1", param->getBeginLoc()) << param->getSourceRange() << param->getName() << fqn; @@ -486,7 +488,7 @@ bool CheckUnusedParams::VisitFunctionDecl(FunctionDecl const * decl) { unsigned idx = param->getFunctionScopeIndex(); const ParmVarDecl* pOther = canon->getParamDecl(idx); report( DiagnosticsEngine::Note, "declaration is here", - compat::getBeginLoc(pOther)) + pOther->getBeginLoc()) << pOther->getSourceRange(); } } diff --git a/compilerplugins/clang/collapseif.cxx b/compilerplugins/clang/collapseif.cxx index b3f192c2ce1d..c50bf3352440 100644 --- a/compilerplugins/clang/collapseif.cxx +++ b/compilerplugins/clang/collapseif.cxx @@ -77,7 +77,7 @@ bool CollapseIf::VisitIfStmt(IfStmt const* ifStmt) return true; report(DiagnosticsEngine::Warning, "nested if should be collapsed into one statement %0 %1", - compat::getBeginLoc(ifStmt)) + ifStmt->getBeginLoc()) << noChars1 << noChars2 << ifStmt->getSourceRange(); return true; } @@ -88,8 +88,8 @@ int CollapseIf::getNoCharsInSourceCodeOfExpr(IfStmt const* ifStmt) // measuring the size of the condition expression is unreliable, because clang // does not report the location of the last token accurately. SourceManager& SM = compiler.getSourceManager(); - SourceLocation startLoc = compat::getBeginLoc(ifStmt); - SourceLocation endLoc = compat::getBeginLoc(ifStmt->getThen()); + SourceLocation startLoc = ifStmt->getBeginLoc(); + SourceLocation endLoc = ifStmt->getThen()->getBeginLoc(); char const* p1 = SM.getCharacterData(startLoc); char const* p2 = SM.getCharacterData(endLoc); diff --git a/compilerplugins/clang/colorcheck.cxx b/compilerplugins/clang/colorcheck.cxx index 83f9a9688381..55f9034c675a 100644 --- a/compilerplugins/clang/colorcheck.cxx +++ b/compilerplugins/clang/colorcheck.cxx @@ -15,6 +15,8 @@ #include <fstream> #include <set> +#include "config_clang.h" + #include "check.hxx" #include "plugin.hxx" @@ -53,7 +55,7 @@ bool ColorCheck::VisitCXXConstructExpr(const CXXConstructExpr* constructExpr) return true; StringRef aFileName = getFilenameOfLocation( - compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(constructExpr))); + compiler.getSourceManager().getSpellingLoc(constructExpr->getBeginLoc())); if (loplugin::isSamePathname(aFileName, SRCDIR "/include/tools/color.hxx")) return true; @@ -71,7 +73,7 @@ bool ColorCheck::VisitCXXConstructExpr(const CXXConstructExpr* constructExpr) if (!arg0->isValueDependent()) { llvm::Optional<llvm::APSInt> xVal - = compat::getIntegerConstantExpr(arg0, compiler.getASTContext()); + = arg0->getIntegerConstantExpr(compiler.getASTContext()); if (xVal && *xVal > 0xffffff) report(DiagnosticsEngine::Warning, "Rather use the ColorTransparency or ColorAlpha version of this constructor", diff --git a/compilerplugins/clang/commaoperator.cxx b/compilerplugins/clang/commaoperator.cxx index 3da4c18d1e10..3ba1c89c4be2 100644 --- a/compilerplugins/clang/commaoperator.cxx +++ b/compilerplugins/clang/commaoperator.cxx @@ -13,8 +13,6 @@ #include <fstream> #include <set> -#include "config_clang.h" - #include "plugin.hxx" /** @@ -84,10 +82,6 @@ public: return ret; } -#if CLANG_VERSION < 110000 - bool TraverseBinComma(BinaryOperator * expr) { return TraverseBinaryOperator(expr); } -#endif - bool VisitBinaryOperator(const BinaryOperator* ); private: @@ -110,11 +104,11 @@ bool CommaOperator::VisitBinaryOperator(const BinaryOperator* binaryOp) // winsock2.h (TODO: improve heuristic of determining that the whole // binaryOp is part of a single macro body expansion): if (compiler.getSourceManager().isMacroBodyExpansion( - compat::getBeginLoc(binaryOp)) + binaryOp->getBeginLoc()) && compiler.getSourceManager().isMacroBodyExpansion( binaryOp->getOperatorLoc()) && compiler.getSourceManager().isMacroBodyExpansion( - compat::getEndLoc(binaryOp)) + binaryOp->getEndLoc()) && ignoreLocation( compiler.getSourceManager().getSpellingLoc( binaryOp->getOperatorLoc()))) diff --git a/compilerplugins/clang/comparisonwithconstant.cxx b/compilerplugins/clang/comparisonwithconstant.cxx index b5dfe8cc6e7f..d796b7c3a3a1 100644 --- a/compilerplugins/clang/comparisonwithconstant.cxx +++ b/compilerplugins/clang/comparisonwithconstant.cxx @@ -13,8 +13,6 @@ #include <fstream> #include <set> -#include "config_clang.h" - #include "compat.hxx" #include "plugin.hxx" @@ -51,11 +49,6 @@ public: return ret; } -#if CLANG_VERSION < 110000 - bool TraverseBinEQ(BinaryOperator * expr) { return TraverseBinaryOperator(expr); } - bool TraverseBinNE(BinaryOperator * expr) { return TraverseBinaryOperator(expr); } -#endif - bool VisitBinaryOperator(const BinaryOperator *); private: bool rewrite(const BinaryOperator *); diff --git a/compilerplugins/clang/compat.hxx b/compilerplugins/clang/compat.hxx index bc1c5dfcd2ee..350263da6854 100644 --- a/compilerplugins/clang/compat.hxx +++ b/compilerplugins/clang/compat.hxx @@ -12,15 +12,11 @@ #include <string> #include <utility> -#include "clang/AST/Decl.h" -#include "clang/AST/DeclCXX.h" #include "clang/AST/Expr.h" #include "clang/AST/ExprCXX.h" #include "clang/Basic/SourceManager.h" #include "clang/Basic/Specifiers.h" #include "llvm/ADT/StringExtras.h" -#include "llvm/Support/Casting.h" -#include "llvm/Support/Compiler.h" #include "llvm/Support/FileSystem.h" #include "config_clang.h" @@ -28,18 +24,6 @@ // Compatibility wrapper to abstract over (trivial) changes in the Clang API: namespace compat { -// Copies code from LLVM's include/llvm/Support/Casting.h: -template<typename... X, typename Y> LLVM_NODISCARD inline bool isa_and_nonnull(Y const & Val) { -#if CLANG_VERSION >= 90000 - return llvm::isa_and_nonnull<X...>(Val); -#else - if (!Val) { - return false; - } - return llvm::isa<X...>(Val); -#endif -} - inline std::string toString(llvm::APSInt const & i, unsigned radix) { #if CLANG_VERSION >= 130000 return llvm::toString(i, radix); @@ -48,138 +32,17 @@ inline std::string toString(llvm::APSInt const & i, unsigned radix) { #endif } -inline clang::SourceLocation getBeginLoc(clang::Decl const * decl) { -#if CLANG_VERSION >= 80000 - return decl->getBeginLoc(); -#else - return decl->getLocStart(); -#endif -} - -inline clang::SourceLocation getEndLoc(clang::Decl const * decl) { -#if CLANG_VERSION >= 80000 - return decl->getEndLoc(); -#else - return decl->getLocEnd(); -#endif -} - -inline clang::SourceLocation getBeginLoc(clang::DeclarationNameInfo const & info) { -#if CLANG_VERSION >= 80000 - return info.getBeginLoc(); -#else - return info.getLocStart(); -#endif -} - -inline clang::SourceLocation getEndLoc(clang::DeclarationNameInfo const & info) { -#if CLANG_VERSION >= 80000 - return info.getEndLoc(); -#else - return info.getLocEnd(); -#endif -} - -inline clang::SourceLocation getBeginLoc(clang::Stmt const * stmt) { -#if CLANG_VERSION >= 80000 - return stmt->getBeginLoc(); -#else - return stmt->getLocStart(); -#endif -} - -inline clang::SourceLocation getEndLoc(clang::Stmt const * stmt) { -#if CLANG_VERSION >= 80000 - return stmt->getEndLoc(); -#else - return stmt->getLocEnd(); -#endif -} - -inline clang::SourceLocation getBeginLoc(clang::CXXBaseSpecifier const * spec) { -#if CLANG_VERSION >= 80000 - return spec->getBeginLoc(); -#else - return spec->getLocStart(); -#endif -} - -inline clang::SourceLocation getEndLoc(clang::CXXBaseSpecifier const * spec) { -#if CLANG_VERSION >= 80000 - return spec->getEndLoc(); -#else - return spec->getLocEnd(); -#endif -} - inline std::pair<clang::SourceLocation, clang::SourceLocation> getImmediateExpansionRange( clang::SourceManager const & SM, clang::SourceLocation Loc) { -#if CLANG_VERSION >= 70000 auto const csr = SM.getImmediateExpansionRange(Loc); if (csr.isCharRange()) { /*TODO*/ } return {csr.getBegin(), csr.getEnd()}; -#else - return SM.getImmediateExpansionRange(Loc); -#endif -} - -inline bool isPointWithin( - clang::SourceManager const & SM, clang::SourceLocation Location, clang::SourceLocation Start, - clang::SourceLocation End) -{ -#if CLANG_VERSION >= 60000 - return SM.isPointWithin(Location, Start, End); -#else - return - Location == Start || Location == End - || (SM.isBeforeInTranslationUnit(Start, Location) - && SM.isBeforeInTranslationUnit(Location, End)); -#endif -} - -inline clang::Expr const * IgnoreImplicit(clang::Expr const * expr) { -#if CLANG_VERSION >= 80000 - return expr->IgnoreImplicit(); -#else - using namespace clang; - // Copy from Clang's lib/AST/Stmt.cpp, including <https://reviews.llvm.org/D50666> "Fix - // Stmt::ignoreImplicit": - Stmt const *s = expr; - - Stmt const *lasts = nullptr; - - while (s != lasts) { - lasts = s; - - if (auto *ewc = dyn_cast<ExprWithCleanups>(s)) - s = ewc->getSubExpr(); - - if (auto *mte = dyn_cast<MaterializeTemporaryExpr>(s)) - s = mte->GetTemporaryExpr(); - - if (auto *bte = dyn_cast<CXXBindTemporaryExpr>(s)) - s = bte->getSubExpr(); - - if (auto *ice = dyn_cast<ImplicitCastExpr>(s)) - s = ice->getSubExpr(); - } - - return static_cast<Expr const *>(s); -#endif } /// Utility method inline clang::Expr const * IgnoreParenImplicit(clang::Expr const * expr) { - return compat::IgnoreImplicit(compat::IgnoreImplicit(expr)->IgnoreParens()); -} - -inline bool CPlusPlus17(clang::LangOptions const & opts) { -#if CLANG_VERSION >= 60000 - return opts.CPlusPlus17; -#else - return opts.CPlusPlus1z; -#endif + return expr->IgnoreImplicit()->IgnoreParens()->IgnoreImplicit(); } #if CLANG_VERSION >= 130000 @@ -189,40 +52,13 @@ constexpr clang::ExprValueKind VK_PRValue = clang::VK_RValue; #endif inline bool EvaluateAsInt(clang::Expr const * expr, llvm::APSInt& intRes, const clang::ASTContext& ctx) { -#if CLANG_VERSION >= 80000 clang::Expr::EvalResult res; bool b = expr->EvaluateAsInt(res, ctx); if (b && res.Val.isInt()) intRes = res.Val.getInt(); return b; -#else - return expr->EvaluateAsInt(intRes, ctx); -#endif } -inline llvm::Optional<llvm::APSInt> getIntegerConstantExpr( - clang::Expr const * expr, clang::ASTContext const & context) -{ -#if CLANG_VERSION >= 120000 - return expr->getIntegerConstantExpr(context); -#else - llvm::APSInt res; - return expr->isIntegerConstantExpr(res, context) ? res : llvm::Optional<llvm::APSInt>(); -#endif -} - -inline clang::Expr * getSubExpr(clang::MaterializeTemporaryExpr const * expr) { -#if CLANG_VERSION >= 100000 - return expr->getSubExpr(); -#else - return expr->GetTemporaryExpr(); -#endif -} - -#if CLANG_VERSION < 80000 -inline clang::Expr const * getSubExprAsWritten(clang::CastExpr const * expr) -{ return expr->getSubExprAsWritten(); } -#else // Work around CastExpr::getSubExprAsWritten firing // // include/llvm/Support/Casting.h:269: typename llvm::cast_retty<X, Y*>::ret_type llvm::cast(Y*) @@ -251,7 +87,7 @@ namespace detail { // Skip through reference binding to temporary. if (clang::MaterializeTemporaryExpr *Materialize = clang::dyn_cast<clang::MaterializeTemporaryExpr>(expr)) - expr = compat::getSubExpr(Materialize); + expr = Materialize->getSubExpr(); // Skip any temporary bindings; they're implicit. if (clang::CXXBindTemporaryExpr *Binder = clang::dyn_cast<clang::CXXBindTemporaryExpr>(expr)) @@ -288,74 +124,6 @@ inline clang::Expr *getSubExprAsWritten(clang::CastExpr *This) { inline const clang::Expr *getSubExprAsWritten(const clang::CastExpr *This) { return getSubExprAsWritten(const_cast<clang::CastExpr *>(This)); } -#endif - -inline clang::QualType getObjectType(clang::CXXMemberCallExpr const * expr) { -#if CLANG_VERSION >= 100000 - return expr->getObjectType(); -#else - // <https://github.com/llvm/llvm-project/commit/88559637641e993895337e1047a0bd787fecc647> - // "[OpenCL] Improve destructor support in C++ for OpenCL": - clang::QualType Ty = expr->getImplicitObjectArgument()->getType(); - if (Ty->isPointerType()) - Ty = Ty->getPointeeType(); - return Ty; -#endif -} - -inline bool isExplicitSpecified(clang::CXXConstructorDecl const * decl) { -#if CLANG_VERSION >= 90000 - return decl->getExplicitSpecifier().isExplicit(); -#else - return decl->isExplicitSpecified(); -#endif -} - -inline bool isExplicitSpecified(clang::CXXConversionDecl const * decl) { -#if CLANG_VERSION >= 90000 - return decl->getExplicitSpecifier().isExplicit(); -#else - return decl->isExplicitSpecified(); -#endif -} - -inline clang::QualType getDeclaredReturnType(clang::FunctionDecl const * decl) { -#if CLANG_VERSION >= 80000 - return decl->getDeclaredReturnType(); -#else - // <https://github.com/llvm/llvm-project/commit/4576a77b809649f5b8d0ff8c7a4be57eeee0ecf9> - // "PR33222: Require the declared return type not the actual return type to": - auto *TSI = decl->getTypeSourceInfo(); - clang::QualType T = TSI ? TSI->getType() : decl->getType(); - return T->castAs<clang::FunctionType>()->getReturnType(); -#endif -} - -inline bool isComparisonOp(clang::CXXOperatorCallExpr const * callExpr) -{ -#if CLANG_VERSION >= 110000 - return callExpr->isComparisonOp(); -#else - using namespace clang; - auto op = callExpr->getOperator(); - return op == OO_Less || op == OO_Greater || op == OO_LessEqual || op == OO_GreaterEqual - || op == OO_EqualEqual || op == OO_ExclaimEqual; -#endif -} - -inline bool isPtrMemOp(clang::BinaryOperatorKind op) { -#if CLANG_VERSION >= 80000 - return clang::BinaryOperator::isPtrMemOp(op); -#else - return op == clang::BO_PtrMemD || op == clang::BO_PtrMemI; -#endif -} - -#if CLANG_VERSION >= 70000 -constexpr llvm::sys::fs::OpenFlags OF_None = llvm::sys::fs::OF_None; -#else -constexpr llvm::sys::fs::OpenFlags OF_None = llvm::sys::fs::F_None; -#endif } diff --git a/compilerplugins/clang/conditionalstring.cxx b/compilerplugins/clang/conditionalstring.cxx index bf6c196846dc..cf858601ea0a 100644 --- a/compilerplugins/clang/conditionalstring.cxx +++ b/compilerplugins/clang/conditionalstring.cxx @@ -12,7 +12,6 @@ #include <cassert> #include "check.hxx" -#include "compat.hxx" #include "plugin.hxx" // Find uses of OUString in conditional expressions that could be rewritten as std::u16string_view, @@ -32,15 +31,13 @@ Expr const* ignoreImplicit(Expr const* expr) { e = e1->getSubExprAsWritten(); } -#if CLANG_VERSION >= 80000 else if (auto const e2 = dyn_cast<FullExpr>(e)) { e = e2->getSubExpr(); } -#endif else if (auto const e3 = dyn_cast<MaterializeTemporaryExpr>(e)) { - e = compat::getSubExpr(e3); + e = e3->getSubExpr(); } else if (auto const e4 = dyn_cast<CXXBindTemporaryExpr>(e)) { @@ -398,8 +395,7 @@ private: { e = e1->getSubExpr(); } - if (auto const e1 - = dyn_cast<CXXConstructExpr>(compat::IgnoreImplicit(e)->IgnoreParens())) + if (auto const e1 = dyn_cast<CXXConstructExpr>(e->IgnoreImplicit()->IgnoreParens())) { if (e1->getNumArgs() != 0 //TODO && isa<clang::StringLiteral>(e1->getArg(0)->IgnoreParenImpCasts())) diff --git a/compilerplugins/clang/constantparam.cxx b/compilerplugins/clang/constantparam.cxx index da1ee7841ebe..f9f87b361bc5 100644 --- a/compilerplugins/clang/constantparam.cxx +++ b/compilerplugins/clang/constantparam.cxx @@ -104,10 +104,6 @@ void ConstantParam::addToCallSet(const FunctionDecl* functionDecl, int paramInde { if (functionDecl->getInstantiatedFromMemberFunction()) functionDecl = functionDecl->getInstantiatedFromMemberFunction(); -#if CLANG_VERSION < 90000 - else if (functionDecl->getClassScopeSpecializationPattern()) - functionDecl = functionDecl->getClassScopeSpecializationPattern(); -#endif else if (functionDecl->getTemplateInstantiationPattern()) functionDecl = functionDecl->getTemplateInstantiationPattern(); @@ -202,8 +198,8 @@ std::string ConstantParam::getCallValue(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) { @@ -249,10 +245,6 @@ bool ConstantParam::VisitCallExpr(const CallExpr * callExpr) { // work our way back to the root definition for template methods if (functionDecl->getInstantiatedFromMemberFunction()) functionDecl = functionDecl->getInstantiatedFromMemberFunction(); -#if CLANG_VERSION < 90000 - else if (functionDecl->getClassScopeSpecializationPattern()) - functionDecl = functionDecl->getClassScopeSpecializationPattern(); -#endif else if (functionDecl->getTemplateInstantiationPattern()) functionDecl = functionDecl->getTemplateInstantiationPattern(); diff --git a/compilerplugins/clang/constfields.cxx b/compilerplugins/clang/constfields.cxx index c576d00bd9f5..692c84daeb8c 100644 --- a/compilerplugins/clang/constfields.cxx +++ b/compilerplugins/clang/constfields.cxx @@ -22,12 +22,9 @@ #include "config_clang.h" #include "plugin.hxx" -#include "compat.hxx" #include "check.hxx" -#if CLANG_VERSION >= 110000 #include "clang/AST/ParentMapContext.h" -#endif /** Look for fields that are only assigned to in the constructor using field-init, and can therefore be const. @@ -205,7 +202,7 @@ void ConstFields::run() else { for (const MyFieldInfo& s : cannotBeConstSet) - report(DiagnosticsEngine::Warning, "notconst %0", compat::getBeginLoc(s.parentRecord)) + report(DiagnosticsEngine::Warning, "notconst %0", s.parentRecord->getBeginLoc()) << s.fieldName; } } @@ -527,11 +524,11 @@ void ConstFields::check(const FieldDecl* fieldDecl, const Expr* memberExpr) if (bDump) { report(DiagnosticsEngine::Warning, "oh dear, what can the matter be? writtenTo=%0", - compat::getBeginLoc(memberExpr)) + memberExpr->getBeginLoc()) << bCannotBeConst << 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(); } diff --git a/compilerplugins/clang/constfieldsrewrite.cxx b/compilerplugins/clang/constfieldsrewrite.cxx index 52da9a153455..d72bb43aad7a 100644 --- a/compilerplugins/clang/constfieldsrewrite.cxx +++ b/compilerplugins/clang/constfieldsrewrite.cxx @@ -14,6 +14,7 @@ #include <iostream> #include "plugin.hxx" #include "check.hxx" +#include "config_clang.h" #include <sys/mman.h> #include <sys/types.h> #include <fcntl.h> @@ -154,7 +155,7 @@ bool ConstFieldsRewrite::VisitFieldDecl(const FieldDecl* fieldDecl) if (!success) { report(DiagnosticsEngine::Warning, "Could not mark field as const", - compat::getBeginLoc(fieldDecl)) + fieldDecl->getBeginLoc()) << fieldDecl->getSourceRange(); } return true; diff --git a/compilerplugins/clang/constmethod.cxx b/compilerplugins/clang/constmethod.cxx index da5a64aea9b4..bd9c4db18d17 100644 --- a/compilerplugins/clang/constmethod.cxx +++ b/compilerplugins/clang/constmethod.cxx @@ -16,13 +16,10 @@ #include "config_clang.h" #include "plugin.hxx" -#include "compat.hxx" #include "check.hxx" #include "functionaddress.hxx" -#if CLANG_VERSION >= 110000 #include "clang/AST/ParentMapContext.h" -#endif /** Find methods that can be declared const. @@ -96,7 +93,7 @@ public: || fqn == "OutputDevice::SelectClipRegion" || fqn == "OutputDevice::BlendBitmap") continue; - StringRef aFileName = getFilenameOfLocation(compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(canonicalDecl))); + StringRef aFileName = getFilenameOfLocation(compiler.getSourceManager().getSpellingLoc(canonicalDecl->getBeginLoc())); // leave the kit API alone if (loplugin::isSamePathname(aFileName, SRCDIR "/include/LibreOfficeKit/LibreOfficeKit.hxx")) continue; @@ -106,13 +103,13 @@ public: report( DiagnosticsEngine::Warning, "this method can be const", - compat::getBeginLoc(pMethodDecl)) + pMethodDecl->getBeginLoc()) << pMethodDecl->getSourceRange(); if (canonicalDecl->getLocation() != pMethodDecl->getLocation()) { report( DiagnosticsEngine::Note, "canonical method declaration here", - compat::getBeginLoc(canonicalDecl)) + canonicalDecl->getBeginLoc()) << canonicalDecl->getSourceRange(); } } @@ -223,7 +220,7 @@ bool ConstMethod::VisitCXXThisExpr( const CXXThisExpr* cxxThisExpr ) if (ignoreLocation(cxxThisExpr)) return true; // ignore stuff that forms part of the stable URE interface - if (isInUnoIncludeFile(compat::getBeginLoc(cxxThisExpr))) + if (isInUnoIncludeFile(cxxThisExpr->getBeginLoc())) return true; if (interestingMethodSet.find(currCXXMethodDecl) == interestingMethodSet.end()) return true; @@ -251,7 +248,7 @@ bool ConstMethod::checkIfCanBeConst(const Stmt* stmt, const CXXMethodDecl* cxxMe report( DiagnosticsEngine::Warning, "no parent?", - compat::getBeginLoc(stmt)) + stmt->getBeginLoc()) << stmt->getSourceRange(); return false; } @@ -534,7 +531,7 @@ bool ConstMethod::checkIfCanBeConst(const Stmt* stmt, const CXXMethodDecl* cxxMe report( DiagnosticsEngine::Warning, "oh dear, what can the matter be?", - compat::getBeginLoc(parent)) + parent->getBeginLoc()) << parent->getSourceRange(); return false; } diff --git a/compilerplugins/clang/constparams.cxx b/compilerplugins/clang/constparams.cxx index 950ae91e0b27..dac7322d0130 100644 --- a/compilerplugins/clang/constparams.cxx +++ b/compilerplugins/clang/constparams.cxx @@ -20,9 +20,7 @@ #include "check.hxx" #include "functionaddress.hxx" -#if CLANG_VERSION >= 110000 #include "clang/AST/ParentMapContext.h" -#endif /** Find pointer and reference params that can be declared const. @@ -82,7 +80,7 @@ public: report( DiagnosticsEngine::Warning, "this parameter can be const %0", - compat::getBeginLoc(pParmVarDecl)) + pParmVarDecl->getBeginLoc()) << fname << pParmVarDecl->getSourceRange(); if (canonicalDecl->getLocation() != functionDecl->getLocation()) { unsigned idx = pParmVarDecl->getFunctionScopeIndex(); @@ -90,7 +88,7 @@ public: report( DiagnosticsEngine::Note, "canonical parameter declaration here", - compat::getBeginLoc(pOther)) + pOther->getBeginLoc()) << pOther->getSourceRange(); } //functionDecl->dump(); @@ -170,13 +168,13 @@ bool ConstParams::CheckTraverseFunctionDecl(FunctionDecl * functionDecl) // ignore the macros from include/tools/link.hxx auto canonicalDecl = functionDecl->getCanonicalDecl(); - if (compiler.getSourceManager().isMacroBodyExpansion(compat::getBeginLoc(canonicalDecl)) - || compiler.getSourceManager().isMacroArgExpansion(compat::getBeginLoc(canonicalDecl))) { + if (compiler.getSourceManager().isMacroBodyExpansion(canonicalDecl->getBeginLoc()) + || compiler.getSourceManager().isMacroArgExpansion(canonicalDecl->getBeginLoc())) { StringRef name { Lexer::getImmediateMacroName( - compat::getBeginLoc(canonicalDecl), compiler.getSourceManager(), compiler.getLangOpts()) }; + canonicalDecl->getBeginLoc(), compiler.getSourceManager(), compiler.getLangOpts()) }; if (name.startswith("DECL_LINK") || name.startswith("DECL_STATIC_LINK")) return false; - auto loc2 = compat::getImmediateExpansionRange(compiler.getSourceManager(), compat::getBeginLoc(canonicalDecl)).first; + auto loc2 = compat::getImmediateExpansionRange(compiler.getSourceManager(), canonicalDecl->getBeginLoc()).first; if (compiler.getSourceManager().isMacroBodyExpansion(loc2)) { StringRef name2 { Lexer::getImmediateMacroName( @@ -329,7 +327,7 @@ bool ConstParams::checkIfCanBeConst(const Stmt* stmt, const ParmVarDecl* parmVar // report( // DiagnosticsEngine::Warning, // "no parent?", -// compat::getBeginLoc(stmt)) +// stmt->getBeginLoc()) // << stmt->getSourceRange(); return false; } @@ -580,7 +578,7 @@ bool ConstParams::checkIfCanBeConst(const Stmt* stmt, const ParmVarDecl* parmVar report( DiagnosticsEngine::Warning, "oh dear, what can the matter be?", - compat::getBeginLoc(parent)) + parent->getBeginLoc()) << parent->getSourceRange(); return true; } diff --git a/compilerplugins/clang/consttobool.cxx b/compilerplugins/clang/consttobool.cxx index 4f4755cd8c3c..d20a0d5c9b48 100644 --- a/compilerplugins/clang/consttobool.cxx +++ b/compilerplugins/clang/consttobool.cxx @@ -15,8 +15,6 @@ #include "clang/Basic/Builtins.h" -#include "config_clang.h" - #include "check.hxx" #include "plugin.hxx" @@ -87,10 +85,6 @@ public: return ret; } -#if CLANG_VERSION < 110000 - bool TraverseUnaryLNot(UnaryOperator* expr) { return TraverseUnaryOperator(expr); } -#endif - bool PreTraverseBinaryOperator(BinaryOperator* expr) { if (expr->getOpcode() == BO_LAnd) @@ -121,10 +115,6 @@ public: return ret; } -#if CLANG_VERSION < 110000 - bool TraverseBinLAnd(BinaryOperator* expr) { return TraverseBinaryOperator(expr); } -#endif - bool VisitImplicitCastExpr(ImplicitCastExpr const* expr) { if (ignoreLocation(expr)) diff --git a/compilerplugins/clang/constvars.cxx b/compilerplugins/clang/constvars.cxx index e496d5f0ad15..2b06f54ea343 100644 --- a/compilerplugins/clang/constvars.cxx +++ b/compilerplugins/clang/constvars.cxx @@ -19,15 +19,10 @@ #include <sys/file.h> #include <unistd.h> -#include "config_clang.h" - #include "plugin.hxx" -#include "compat.hxx" #include "check.hxx" -#if CLANG_VERSION >= 110000 #include "clang/AST/ParentMapContext.h" -#endif /** Look for static vars that are only assigned to once, and never written to, they can be const. @@ -175,7 +170,7 @@ void ConstVars::run() // Implement a marker that disables this plugins warning at a specific site if (sourceString.contains("loplugin:constvars:ignore")) continue; - report(DiagnosticsEngine::Warning, "var can be const", compat::getBeginLoc(v)); + report(DiagnosticsEngine::Warning, "var can be const", v->getBeginLoc()); } } @@ -213,7 +208,7 @@ bool ConstVars::VisitVarDecl(const VarDecl* varDecl) bool ConstVars::VisitCXXForRangeStmt(const CXXForRangeStmt* forStmt) { - if (compat::getBeginLoc(forStmt).isValid() && ignoreLocation(forStmt)) + if (forStmt->getBeginLoc().isValid() && ignoreLocation(forStmt)) return true; const VarDecl* varDecl = forStmt->getLoopVariable(); if (!varDecl) @@ -491,11 +486,11 @@ void ConstVars::check(const VarDecl* varDecl, const Expr* memberExpr) if (bDump) { report(DiagnosticsEngine::Warning, "oh dear, what can the matter be? writtenTo=%0", - compat::getBeginLoc(memberExpr)) + memberExpr->getBeginLoc()) << bCannotBeConst << 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(); } diff --git a/compilerplugins/clang/convertlong.cxx b/compilerplugins/clang/convertlong.cxx index 5d2ac82f5849..87b65a43f38b 100644 --- a/compilerplugins/clang/convertlong.cxx +++ b/compilerplugins/clang/convertlong.cxx @@ -13,6 +13,7 @@ #include <iostream> #include <fstream> #include <set> +#include "config_clang.h" #include "plugin.hxx" #include "check.hxx" diff --git a/compilerplugins/clang/countusersofdefaultparams.cxx b/compilerplugins/clang/countusersofdefaultparams.cxx index 073c58e104f7..c336509b3ef6 100644 --- a/compilerplugins/clang/countusersofdefaultparams.cxx +++ b/compilerplugins/clang/countusersofdefaultparams.cxx @@ -14,8 +14,9 @@ #include "clang/AST/Attr.h" +#include "config_clang.h" + #include "plugin.hxx" -#include "compat.hxx" /* Count call sites that are actually using the defaulted values on params on methods that declare such. @@ -93,10 +94,6 @@ void CountUsersOfDefaultParams::niceName(const FunctionDecl* functionDecl, MyFun { if (functionDecl->getInstantiatedFromMemberFunction()) functionDecl = functionDecl->getInstantiatedFromMemberFunction(); -#if CLANG_VERSION < 90000 - else if (functionDecl->getClassScopeSpecializationPattern()) - functionDecl = functionDecl->getClassScopeSpecializationPattern(); -#endif else if (functionDecl->getTemplateInstantiationPattern()) functionDecl = functionDecl->getTemplateInstantiationPattern(); @@ -157,10 +154,6 @@ bool CountUsersOfDefaultParams::VisitCallExpr(const CallExpr * callExpr) { // work our way back to the root definition for template methods if (functionDecl->getInstantiatedFromMemberFunction()) functionDecl = functionDecl->getInstantiatedFromMemberFunction(); -#if CLANG_VERSION < 90000 - else if (functionDecl->getClassScopeSpecializationPattern()) - functionDecl = functionDecl->getClassScopeSpecializationPattern(); -#endif else if (functionDecl->getTemplateInstantiationPattern()) functionDecl = functionDecl->getTemplateInstantiationPattern(); int n = functionDecl->getNumParams() - 1; @@ -174,7 +167,7 @@ bool CountUsersOfDefaultParams::VisitCallExpr(const CallExpr * callExpr) { if ( n < (int)callExpr->getNumArgs() && callExpr->getArg(n)->isDefaultArgument()) { MyCallInfo callInfo; niceName(functionDecl, callInfo); - callInfo.sourceLocationOfCall = locationToString(compat::getBeginLoc(callExpr)); + callInfo.sourceLocationOfCall = locationToString(callExpr->getBeginLoc()); callSet.insert(callInfo); } return true; @@ -188,10 +181,6 @@ bool CountUsersOfDefaultParams::VisitCXXConstructExpr(const CXXConstructExpr * c // work our way back to the root definition for template methods if (constructorDecl->getInstantiatedFromMemberFunction()) constructorDecl = dyn_cast<CXXConstructorDecl>(constructorDecl->getInstantiatedFromMemberFunction()); -#if CLANG_VERSION < 90000 - else if (constructorDecl->getClassScopeSpecializationPattern()) - constructorDecl = dyn_cast<CXXConstructorDecl>(constructorDecl->getClassScopeSpecializationPattern()); -#endif else if (constructorDecl->getTemplateInstantiationPattern()) constructorDecl = dyn_cast<CXXConstructorDecl>(constructorDecl->getTemplateInstantiationPattern()); int n = constructorDecl->getNumParams() - 1; @@ -205,7 +194,7 @@ bool CountUsersOfDefaultParams::VisitCXXConstructExpr(const CXXConstructExpr * c if ( n < (int)constructExpr->getNumArgs() && constructExpr->getArg(n)->isDefaultArgument()) { MyCallInfo callInfo; niceName(constructorDecl, callInfo); - callInfo.sourceLocationOfCall = locationToString(compat::getBeginLoc(constructExpr)); + callInfo.sourceLocationOfCall = locationToString(constructExpr->getBeginLoc()); callSet.insert(callInfo); } return true; diff --git a/compilerplugins/clang/cow_wrapper.cxx b/compilerplugins/clang/cow_wrapper.cxx index aed9d609d289..c98f70cbeb87 100644 --- a/compilerplugins/clang/cow_wrapper.cxx +++ b/compilerplugins/clang/cow_wrapper.cxx @@ -53,7 +53,7 @@ bool Cow_Wrapper::VisitCXXMemberCallExpr(const CXXMemberCallExpr* memberCallExpr if (!methodDecl || !methodDecl->isConst()) return true; - auto expr = compat::IgnoreImplicit(memberCallExpr->getImplicitObjectArgument())->IgnoreParens(); + auto expr = memberCallExpr->getImplicitObjectArgument()->IgnoreImplicit()->IgnoreParens(); auto operatorCallExpr = dyn_cast<CXXOperatorCallExpr>(expr); if (operatorCallExpr && operatorCallExpr->getOperator() == OO_Arrow) @@ -107,7 +107,7 @@ bool Cow_Wrapper::VisitCXXMemberCallExpr(const CXXMemberCallExpr* memberCallExpr report(DiagnosticsEngine::Warning, "calling const method on o3tl::cow_wrapper impl class via non-const pointer, rather use " "std::as_const to prevent triggering an unnecessary copy", - compat::getBeginLoc(memberCallExpr)) + memberCallExpr->getBeginLoc()) << memberCallExpr->getSourceRange(); return true; } diff --git a/compilerplugins/clang/cstylecast.cxx b/compilerplugins/clang/cstylecast.cxx index 7fa2ce0ae1b0..35292ecd8fb6 100644 --- a/compilerplugins/clang/cstylecast.cxx +++ b/compilerplugins/clang/cstylecast.cxx @@ -240,7 +240,7 @@ bool CStyleCast::VisitCStyleCastExpr(const CStyleCastExpr * expr) { if( expr->getCastKind() == CK_ToVoid ) { return true; } - if (isSharedCAndCppCode(compat::getBeginLoc(expr))) { + if (isSharedCAndCppCode(expr->getBeginLoc())) { return true; } char const * perf = nullptr; @@ -416,8 +416,8 @@ bool CStyleCast::rewriteArithmeticCast(CStyleCastExpr const * expr, char const * firstBegin = compiler.getSourceManager().getSpellingLoc(firstBegin); secondBegin = compiler.getSourceManager().getSpellingLoc(secondBegin); } - auto third = compat::getBeginLoc(sub); - auto fourth = compat::getEndLoc(sub); + auto third = sub->getBeginLoc(); + auto fourth = sub->getEndLoc(); bool macro = false; // Ensure that // diff --git a/compilerplugins/clang/datamembershadow.cxx b/compilerplugins/clang/datamembershadow.cxx index 7a5bf4bc3e87..93f65de66726 100644 --- a/compilerplugins/clang/datamembershadow.cxx +++ b/compilerplugins/clang/datamembershadow.cxx @@ -15,6 +15,7 @@ #include <set> #include "plugin.hxx" +#include "config_clang.h" #include "clang/AST/CXXInheritance.h" /** @@ -47,7 +48,7 @@ bool DataMemberShadow::VisitFieldDecl(FieldDecl const * fieldDecl) return true; } StringRef aFileName = getFilenameOfLocation( - compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(fieldDecl))); + compiler.getSourceManager().getSpellingLoc(fieldDecl->getBeginLoc())); // FIXME complex stuff to fix later @@ -99,13 +100,13 @@ bool DataMemberShadow::VisitFieldDecl(FieldDecl const * fieldDecl) sPath += baseCXXRecordDecl->getNameAsString(); report(DiagnosticsEngine::Warning, "data member %0 is shadowing member in superclass, through inheritance path %1", - compat::getBeginLoc(fieldDecl)) + fieldDecl->getBeginLoc()) << fieldDecl->getName() << sPath << fieldDecl->getSourceRange(); report(DiagnosticsEngine::Note, "superclass member here", - compat::getBeginLoc(baseFieldDecl)) + baseFieldDecl->getBeginLoc()) << baseFieldDecl->getSourceRange(); } return false; diff --git a/compilerplugins/clang/dbgunhandledexception.cxx b/compilerplugins/clang/dbgunhandledexception.cxx index d1406c18a9dd..e6c1f157cc9d 100644 --- a/compilerplugins/clang/dbgunhandledexception.cxx +++ b/compilerplugins/clang/dbgunhandledexception.cxx @@ -88,7 +88,7 @@ bool DbgUnhandledException::VisitCallExpr(const CallExpr* call) if (currCatchStmt.empty()) { report(DiagnosticsEngine::Warning, "DBG_UNHANDLED_EXCEPTION outside catch block", - compat::getBeginLoc(call)); + call->getBeginLoc()); return true; } auto catchBlock = dyn_cast<CompoundStmt>(currCatchStmt.top()->getHandlerBlock()); @@ -96,14 +96,14 @@ bool DbgUnhandledException::VisitCallExpr(const CallExpr* call) { report(DiagnosticsEngine::Warning, "something wrong with DBG_UNHANDLED_EXCEPTION, no CompoundStmt?", - compat::getBeginLoc(call)); + call->getBeginLoc()); return true; } if (catchBlock->size() < 1) { report(DiagnosticsEngine::Warning, "something wrong with DBG_UNHANDLED_EXCEPTION, CompoundStmt size == 0?", - compat::getBeginLoc(call)); + call->getBeginLoc()); return true; } @@ -114,7 +114,7 @@ bool DbgUnhandledException::VisitCallExpr(const CallExpr* call) { report(DiagnosticsEngine::Warning, "DBG_UNHANDLED_EXCEPTION must be first statement in catch block", - compat::getBeginLoc(call)); + call->getBeginLoc()); } return true; } diff --git a/compilerplugins/clang/derefnullptr.cxx b/compilerplugins/clang/derefnullptr.cxx index b1c9d6da6747..35c4c7adcf6c 100644 --- a/compilerplugins/clang/derefnullptr.cxx +++ b/compilerplugins/clang/derefnullptr.cxx @@ -37,7 +37,7 @@ bool DerefNullPtr::VisitUnaryOperator(UnaryOperator const * op) { { report( DiagnosticsEngine::Warning, "null pointer dereference", - compat::getBeginLoc(op)) + op->getBeginLoc()) << op->getSourceRange(); } return true; diff --git a/compilerplugins/clang/dodgyswitch.cxx b/compilerplugins/clang/dodgyswitch.cxx index d0674b3632b0..43958f1364ad 100644 --- a/compilerplugins/clang/dodgyswitch.cxx +++ b/compilerplugins/clang/dodgyswitch.cxx @@ -41,7 +41,7 @@ bool DodgySwitch::VisitDefaultStmt(DefaultStmt const * defaultStmt) if (!IsParentSwitch(defaultStmt)) report( DiagnosticsEngine::Warning, "default statement not directly under switch", - compat::getBeginLoc(defaultStmt)) + defaultStmt->getBeginLoc()) << defaultStmt->getSourceRange(); return true; } @@ -55,7 +55,7 @@ bool DodgySwitch::VisitCaseStmt(CaseStmt const * caseStmt) //parentStmt(parentStmt(caseStmt))->dump(); report( DiagnosticsEngine::Warning, "case statement not directly under switch", - compat::getBeginLoc(caseStmt)) + caseStmt->getBeginLoc()) << caseStmt->getSourceRange(); } return true; diff --git a/compilerplugins/clang/doubleconvert.cxx b/compilerplugins/clang/doubleconvert.cxx index 6a08ae376a95..6f9cc88df742 100644 --- a/compilerplugins/clang/doubleconvert.cxx +++ b/compilerplugins/clang/doubleconvert.cxx @@ -10,7 +10,6 @@ #ifndef LO_CLANG_SHARED_PLUGINS #include "check.hxx" -#include "compat.hxx" #include "plugin.hxx" /** @@ -58,7 +57,7 @@ bool DoubleConvert::VisitCXXConstructExpr(CXXConstructExpr const* cxxConstruct) = dyn_cast<CXXMemberCallExpr>(cxxConstruct->getArg(0)->IgnoreParenCasts()); if (!cxxMemberCallExpr) return true; - if (!compat::isa_and_nonnull<CXXConversionDecl>(cxxMemberCallExpr->getMethodDecl())) + if (!isa_and_nonnull<CXXConversionDecl>(cxxMemberCallExpr->getMethodDecl())) return true; if (cxxConstruct->getType().getCanonicalType().getTypePtr() != cxxMemberCallExpr->getImplicitObjectArgument() diff --git a/compilerplugins/clang/dyncastvisibility.cxx b/compilerplugins/clang/dyncastvisibility.cxx index 3c54f7cf8929..7259374c98ea 100644 --- a/compilerplugins/clang/dyncastvisibility.cxx +++ b/compilerplugins/clang/dyncastvisibility.cxx @@ -15,6 +15,8 @@ #include <set> #include <string> +#include "config_clang.h" + #include "plugin.hxx" namespace { diff --git a/compilerplugins/clang/elidestringvar.cxx b/compilerplugins/clang/elidestringvar.cxx index 412fa8cb09db..89e740d21904 100644 --- a/compilerplugins/clang/elidestringvar.cxx +++ b/compilerplugins/clang/elidestringvar.cxx @@ -14,7 +14,6 @@ #include <map> #include "check.hxx" -#include "compat.hxx" #include "plugin.hxx" // Find cases where a variable of a OString/OUString type is initialized @@ -62,8 +61,8 @@ public: { continue; } - if (containsPreprocessingConditionalInclusion(SourceRange( - compat::getBeginLoc(var.first), compat::getEndLoc(*var.second.singleUse)))) + if (containsPreprocessingConditionalInclusion( + SourceRange(var.first->getBeginLoc(), (*var.second.singleUse)->getEndLoc()))) { // This is not perfect, as additional uses can be hidden in conditional blocks that // only start after the (would-be) single use (as was the case in diff --git a/compilerplugins/clang/empty.cxx b/compilerplugins/clang/empty.cxx index c3cc86520f47..d5129d29dd3c 100644 --- a/compilerplugins/clang/empty.cxx +++ b/compilerplugins/clang/empty.cxx @@ -12,7 +12,6 @@ #include <cassert> #include "check.hxx" -#include "compat.hxx" #include "plugin.hxx" // Warn about checks whether a container is empty done via an (expensive) call to obtain the @@ -77,7 +76,7 @@ private: { return; } - auto const val = compat::getIntegerConstantExpr(rhs, compiler.getASTContext()); + auto const val = rhs->getIntegerConstantExpr(compiler.getASTContext()); if (!val) { return; diff --git a/compilerplugins/clang/emptyif.cxx b/compilerplugins/clang/emptyif.cxx index ef7eac50d048..5412188f8d52 100644 --- a/compilerplugins/clang/emptyif.cxx +++ b/compilerplugins/clang/emptyif.cxx @@ -71,15 +71,14 @@ bool EmptyIf::VisitIfStmt(IfStmt const* ifStmt) if (ifStmt->getElse() && empty(ifStmt->getElse()) && !ContainsComment(ifStmt->getElse())) { - report(DiagnosticsEngine::Warning, "empty else body", - compat::getBeginLoc(ifStmt->getElse())) + report(DiagnosticsEngine::Warning, "empty else body", ifStmt->getElse()->getBeginLoc()) << ifStmt->getElse()->getSourceRange(); return true; } if (!ifStmt->getElse() && empty(ifStmt->getThen()) && !ContainsComment(ifStmt->getThen())) { - report(DiagnosticsEngine::Warning, "empty if body", compat::getBeginLoc(ifStmt)) + report(DiagnosticsEngine::Warning, "empty if body", ifStmt->getBeginLoc()) << ifStmt->getSourceRange(); } diff --git a/compilerplugins/clang/expandablemethods.cxx b/compilerplugins/clang/expandablemethods.cxx index d40dadd90247..5b09345d414c 100644 --- a/compilerplugins/clang/expandablemethods.cxx +++ b/compilerplugins/clang/expandablemethods.cxx @@ -17,8 +17,9 @@ #include "clang/AST/Attr.h" +#include "config_clang.h" + #include "plugin.hxx" -#include "compat.hxx" /** Find methods that are only called from inside their own class, and are only called from one spot. @@ -114,10 +115,6 @@ MyFuncInfo ExpandableMethods::niceName(const FunctionDecl* functionDecl) { if (functionDecl->getInstantiatedFromMemberFunction()) functionDecl = functionDecl->getInstantiatedFromMemberFunction(); -#if CLANG_VERSION < 90000 - else if (functionDecl->getClassScopeSpecializationPattern()) - functionDecl = functionDecl->getClassScopeSpecializationPattern(); -#endif else if (functionDecl->getTemplateInstantiationPattern()) functionDecl = functionDecl->getTemplateInstantiationPattern(); @@ -270,7 +267,7 @@ void ExpandableMethods::functionTouchedFromExpr( const FunctionDecl* calleeFunct return; } - calledFromSet.emplace(toString(compat::getBeginLoc(expr)), niceName(canonicalFunctionDecl)); + calledFromSet.emplace(toString(expr->getBeginLoc()), niceName(canonicalFunctionDecl)); if (const UnaryOperator* unaryOp = dyn_cast_or_null<UnaryOperator>(getParentStmt(expr))) { if (unaryOp->getOpcode() == UO_AddrOf) { diff --git a/compilerplugins/clang/expressionalwayszero.cxx b/compilerplugins/clang/expressionalwayszero.cxx index b5650aa076a2..f741d30c426b 100644 --- a/compilerplugins/clang/expressionalwayszero.cxx +++ b/compilerplugins/clang/expressionalwayszero.cxx @@ -72,7 +72,7 @@ bool ExpressionAlwaysZero::VisitBinaryOperator(BinaryOperator const* binaryOpera { if (ignoreLocation(binaryOperator)) return true; - if (compat::getBeginLoc(binaryOperator).isMacroID()) + if (binaryOperator->getBeginLoc().isMacroID()) return true; auto op = binaryOperator->getOpcode(); @@ -90,7 +90,7 @@ bool ExpressionAlwaysZero::VisitBinaryOperator(BinaryOperator const* binaryOpera else return true; report(DiagnosticsEngine::Warning, "expression always evaluates to zero, lhs=%0 rhs=%1", - compat::getBeginLoc(binaryOperator)) + binaryOperator->getBeginLoc()) << (lhsValue ? compat::toString(*lhsValue, 10) : "unknown") << (rhsValue ? compat::toString(*rhsValue, 10) : "unknown") << binaryOperator->getSourceRange(); @@ -101,7 +101,7 @@ bool ExpressionAlwaysZero::VisitCXXOperatorCallExpr(CXXOperatorCallExpr const* c { if (ignoreLocation(cxxOperatorCallExpr)) return true; - if (compat::getBeginLoc(cxxOperatorCallExpr).isMacroID()) + if (cxxOperatorCallExpr->getBeginLoc().isMacroID()) return true; auto op = cxxOperatorCallExpr->getOperator(); @@ -121,7 +121,7 @@ bool ExpressionAlwaysZero::VisitCXXOperatorCallExpr(CXXOperatorCallExpr const* c else return true; report(DiagnosticsEngine::Warning, "expression always evaluates to zero, lhs=%0 rhs=%1", - compat::getBeginLoc(cxxOperatorCallExpr)) + cxxOperatorCallExpr->getBeginLoc()) << (lhsValue ? compat::toString(*lhsValue, 10) : "unknown") << (rhsValue ? compat::toString(*rhsValue, 10) : "unknown") << cxxOperatorCallExpr->getSourceRange(); diff --git a/compilerplugins/clang/externandnotdefined.cxx b/compilerplugins/clang/externandnotdefined.cxx index c40837fa961a..676f666ba621 100644 --- a/compilerplugins/clang/externandnotdefined.cxx +++ b/compilerplugins/clang/externandnotdefined.cxx @@ -11,6 +11,8 @@ #include <string> +#include "config_clang.h" + #include "plugin.hxx" // Having an extern prototype for a method in a module and not actually declaring that method is dodgy. diff --git a/compilerplugins/clang/faileddyncast.cxx b/compilerplugins/clang/faileddyncast.cxx index 03d4feb48550..078d5c884b27 100644 --- a/compilerplugins/clang/faileddyncast.cxx +++ b/compilerplugins/clang/faileddyncast.cxx @@ -122,7 +122,7 @@ bool FailedDynCast::VisitCXXDynamicCastExpr(CXXDynamicCastExpr const * expr) { if (isAlwaysNull(expr)) { report( DiagnosticsEngine::Warning, - "dynamic_cast from %0 to %1 always fails", compat::getBeginLoc(expr)) + "dynamic_cast from %0 to %1 always fails", expr->getBeginLoc()) << expr->getSubExpr()->getType() << expr->getType() << expr->getSourceRange(); } diff --git a/compilerplugins/clang/fakebool.cxx b/compilerplugins/clang/fakebool.cxx index 277dd915bf0d..3d5120153d0b 100644 --- a/compilerplugins/clang/fakebool.cxx +++ b/compilerplugins/clang/fakebool.cxx @@ -16,8 +16,9 @@ #include "clang/AST/Attr.h" #include "clang/Basic/Builtins.h" +#include "config_clang.h" + #include "check.hxx" -#include "compat.hxx" #include "functionaddress.hxx" #include "plugin.hxx" @@ -237,7 +238,7 @@ void FakeBool::run() { TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); for (auto const & dcl: varDecls_) { auto const decl = dcl.first; auto const fbk = dcl.second; - SourceLocation loc { compat::getBeginLoc(decl) }; + SourceLocation loc { decl->getBeginLoc() }; TypeSourceInfo * tsi = decl->getTypeSourceInfo(); if (tsi != nullptr) { SourceLocation l { @@ -279,7 +280,7 @@ void FakeBool::run() { } for (auto const & dcl: fieldDecls_) { auto const decl = dcl.first; auto const fbk = dcl.second; - SourceLocation loc { compat::getBeginLoc(decl) }; + SourceLocation loc { decl->getBeginLoc() }; TypeSourceInfo * tsi = decl->getTypeSourceInfo(); if (tsi != nullptr) { SourceLocation l { @@ -325,7 +326,7 @@ void FakeBool::run() { if (ignoredFns.find(f) != ignoredFns.end()) { continue; } - SourceLocation loc { compat::getBeginLoc(decl) }; + SourceLocation loc { decl->getBeginLoc() }; TypeSourceInfo * tsi = decl->getTypeSourceInfo(); if (tsi != nullptr) { SourceLocation l { @@ -399,7 +400,7 @@ void FakeBool::run() { if (ignoredFns.find(f) != ignoredFns.end()) { continue; } - SourceLocation loc { compat::getBeginLoc(decl) }; + SourceLocation loc { decl->getBeginLoc() }; SourceLocation l { compiler.getSourceManager().getExpansionLoc( loc) }; SourceLocation end { compiler.getSourceManager().getExpansionLoc( @@ -536,7 +537,7 @@ bool FakeBool::VisitCStyleCastExpr(CStyleCastExpr * expr) { } auto const k = isFakeBool(expr->getType()); if (k != FBK_No) { - SourceLocation loc { compat::getBeginLoc(expr) }; + SourceLocation loc { expr->getBeginLoc() }; while (compiler.getSourceManager().isMacroArgExpansion(loc)) { loc = compiler.getSourceManager().getImmediateMacroCallerLoc(loc); } @@ -549,7 +550,7 @@ bool FakeBool::VisitCStyleCastExpr(CStyleCastExpr * expr) { if (!isSharedCAndCppCode(callLoc)) { SourceLocation argLoc; if (compiler.getSourceManager().isMacroArgExpansion( - compat::getBeginLoc(expr), &argLoc) + expr->getBeginLoc(), &argLoc) //TODO: check it's the complete (first) arg to the macro && (Lexer::getImmediateMacroName( argLoc, compiler.getSourceManager(), @@ -591,7 +592,7 @@ bool FakeBool::VisitCStyleCastExpr(CStyleCastExpr * expr) { report( DiagnosticsEngine::Warning, "CStyleCastExpr, suspicious cast from %0 to %1", - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getSubExpr()->IgnoreParenImpCasts()->getType() << expr->getType() << expr->getSourceRange(); } @@ -608,14 +609,14 @@ bool FakeBool::VisitCXXStaticCastExpr(CXXStaticCastExpr * expr) { } if (k == FBK_sal_Bool && isInSpecialMainFile( - compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(expr)))) + compiler.getSourceManager().getSpellingLoc(expr->getBeginLoc()))) { return true; } report( DiagnosticsEngine::Warning, "CXXStaticCastExpr, suspicious cast from %0 to %1", - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getSubExpr()->IgnoreParenImpCasts()->getType() << expr->getType() << expr->getSourceRange(); return true; @@ -629,7 +630,7 @@ bool FakeBool::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr * expr) { report( DiagnosticsEngine::Warning, "CXXFunctionalCastExpr, suspicious cast from %0 to %1", - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getSubExpr()->IgnoreParenImpCasts()->getType() << expr->getType() << expr->getSourceRange(); } @@ -644,7 +645,7 @@ bool FakeBool::VisitImplicitCastExpr(ImplicitCastExpr * expr) { if (isFakeBool(expr->getType()) == FBK_No) { return true; } - auto l = compat::getBeginLoc(expr); + auto l = expr->getBeginLoc(); while (compiler.getSourceManager().isMacroArgExpansion(l)) { l = compiler.getSourceManager().getImmediateMacroCallerLoc(l); } @@ -675,7 +676,7 @@ bool FakeBool::VisitImplicitCastExpr(ImplicitCastExpr * expr) { } report( DiagnosticsEngine::Warning, "conversion from %0 to %1", - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << t << expr->getType() << expr->getSourceRange(); return true; } @@ -776,7 +777,7 @@ bool FakeBool::VisitVarDecl(VarDecl const * decl) { if (k == FBK_No) { return true; } - auto const loc = compat::getBeginLoc(decl); + auto const loc = decl->getBeginLoc(); if (k == FBK_sal_Bool && isInSpecialMainFile( compiler.getSourceManager().getSpellingLoc(loc))) @@ -816,7 +817,7 @@ bool FakeBool::VisitFieldDecl(FieldDecl const * decl) { } if (k == FBK_sal_Bool && isInSpecialMainFile( - compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(decl)))) + compiler.getSourceManager().getSpellingLoc(decl->getBeginLoc()))) { return true; } @@ -866,11 +867,11 @@ bool FakeBool::VisitValueDecl(ValueDecl const * decl) { return true; } auto const k = isFakeBool(decl->getType()); - if (k != FBK_No && !rewrite(compat::getBeginLoc(decl), k)) { + if (k != FBK_No && !rewrite(decl->getBeginLoc(), k)) { report( DiagnosticsEngine::Warning, "ValueDecl, use \"bool\" instead of %0", - compat::getBeginLoc(decl)) + decl->getBeginLoc()) << decl->getType() << decl->getSourceRange(); } return true; diff --git a/compilerplugins/clang/finalclasses.cxx b/compilerplugins/clang/finalclasses.cxx index 447e3406e5e6..e061bb7c5ef2 100644 --- a/compilerplugins/clang/finalclasses.cxx +++ b/compilerplugins/clang/finalclasses.cxx @@ -11,6 +11,7 @@ #include <set> #include <string> #include <iostream> +#include "config_clang.h" #include "plugin.hxx" #include <fstream> @@ -131,7 +132,7 @@ bool FinalClasses::VisitCXXRecordDecl(const CXXRecordDecl* decl) if (ignoreClass(s)) return true; - SourceLocation spellingLocation = compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(decl)); + SourceLocation spellingLocation = compiler.getSourceManager().getSpellingLoc(decl->getBeginLoc()); auto const filename = getFilenameOfLocation(spellingLocation); auto sourceLocation = filename.substr(strlen(SRCDIR)).str() + ":" + std::to_string(compiler.getSourceManager().getSpellingLineNumber(spellingLocation)); diff --git a/compilerplugins/clang/flatten.cxx b/compilerplugins/clang/flatten.cxx index a615b8366b63..8d7eac9d92b0 100644 --- a/compilerplugins/clang/flatten.cxx +++ b/compilerplugins/clang/flatten.cxx @@ -204,7 +204,7 @@ bool Flatten::VisitIfStmt(IfStmt const * ifStmt) report( DiagnosticsEngine::Warning, "large if statement at end of function, rather invert the condition and exit early, and flatten the function", - compat::getBeginLoc(ifStmt)) + ifStmt->getBeginLoc()) << ifStmt->getSourceRange(); } return true; @@ -238,12 +238,12 @@ bool Flatten::VisitIfStmt(IfStmt const * ifStmt) report( DiagnosticsEngine::Warning, "unconditional throw in else branch, rather invert the condition, throw early, and flatten the normal case", - compat::getBeginLoc(elseThrowExpr)) + elseThrowExpr->getBeginLoc()) << elseThrowExpr->getSourceRange(); report( DiagnosticsEngine::Note, "if condition here", - compat::getBeginLoc(ifStmt)) + ifStmt->getBeginLoc()) << ifStmt->getSourceRange(); } } @@ -260,7 +260,7 @@ bool Flatten::VisitIfStmt(IfStmt const * ifStmt) report( DiagnosticsEngine::Warning, "unconditional throw in then branch, just flatten the else", - compat::getBeginLoc(thenThrowExpr)) + thenThrowExpr->getBeginLoc()) << thenThrowExpr->getSourceRange(); } } diff --git a/compilerplugins/clang/fragiledestructor.cxx b/compilerplugins/clang/fragiledestructor.cxx index c9f8568fdafd..f8ec76a561f8 100644 --- a/compilerplugins/clang/fragiledestructor.cxx +++ b/compilerplugins/clang/fragiledestructor.cxx @@ -12,7 +12,7 @@ #include <iostream> #include "plugin.hxx" -#include "compat.hxx" +#include "config_clang.h" #include "clang/AST/CXXInheritance.h" @@ -113,8 +113,8 @@ bool FragileDestructor::VisitCXXMemberCallExpr(const CXXMemberCallExpr* callExpr return true; // if we see an explicit call to its own method, that's OK - auto s1 = compiler.getSourceManager().getCharacterData(compat::getBeginLoc(callExpr)); - auto s2 = compiler.getSourceManager().getCharacterData(compat::getEndLoc(callExpr)); + auto s1 = compiler.getSourceManager().getCharacterData(callExpr->getBeginLoc()); + auto s2 = compiler.getSourceManager().getCharacterData(callExpr->getEndLoc()); std::string tok(s1, s2-s1); if (tok.find("::") != std::string::npos) return true; @@ -127,12 +127,12 @@ bool FragileDestructor::VisitCXXMemberCallExpr(const CXXMemberCallExpr* callExpr report( DiagnosticsEngine::Warning, "calling virtual method from destructor, either make the virtual method final, or make this class final", - compat::getBeginLoc(callExpr)) + callExpr->getBeginLoc()) << callExpr->getSourceRange(); report( DiagnosticsEngine::Note, "callee method here", - compat::getBeginLoc(methodDecl)) + methodDecl->getBeginLoc()) << methodDecl->getSourceRange(); return true; } diff --git a/compilerplugins/clang/getstr.cxx b/compilerplugins/clang/getstr.cxx index aba53bd6e2e5..671699e73551 100644 --- a/compilerplugins/clang/getstr.cxx +++ b/compilerplugins/clang/getstr.cxx @@ -13,7 +13,6 @@ #include <stack> #include "check.hxx" -#include "compat.hxx" #include "plugin.hxx" // Find matches of @@ -89,7 +88,7 @@ public: castToVoid = true; } } - auto const t = compat::getObjectType(e); + auto const t = e->getObjectType(); auto const tc = loplugin::TypeCheck(t); if (!(tc.Class("OString").Namespace("rtl").GlobalNamespace() || tc.Class("OUString").Namespace("rtl").GlobalNamespace() diff --git a/compilerplugins/clang/implicitboolconversion.cxx b/compilerplugins/clang/implicitboolconversion.cxx index bc0b74932b71..e61f4a14cf0f 100644 --- a/compilerplugins/clang/implicitboolconversion.cxx +++ b/compilerplugins/clang/implicitboolconversion.cxx @@ -17,8 +17,6 @@ #include "clang/Basic/Builtins.h" -#include "config_clang.h" - #include "check.hxx" #include "compat.hxx" #include "plugin.hxx" @@ -32,7 +30,7 @@ Expr const * ignoreParenAndTemporaryMaterialization(Expr const * expr) { if (e == nullptr) { return expr; } - expr = compat::getSubExpr(e); + expr = e->getSubExpr(); } } @@ -253,27 +251,8 @@ public: bool TraverseBinaryOperator(BinaryOperator * expr); -#if CLANG_VERSION < 110000 - bool TraverseBinLT(BinaryOperator * expr) { return TraverseBinaryOperator(expr); } - bool TraverseBinLE(BinaryOperator * expr) { return TraverseBinaryOperator(expr); } - bool TraverseBinGT(BinaryOperator * expr) { return TraverseBinaryOperator(expr); } - bool TraverseBinGE(BinaryOperator * expr) { return TraverseBinaryOperator(expr); } - bool TraverseBinEQ(BinaryOperator * expr) { return TraverseBinaryOperator(expr); } - bool TraverseBinNE(BinaryOperator * expr) { return TraverseBinaryOperator(expr); } - bool TraverseBinAssign(BinaryOperator * expr) { return TraverseBinaryOperator(expr); } -#endif - bool TraverseCompoundAssignOperator(CompoundAssignOperator * expr); -#if CLANG_VERSION < 110000 - bool TraverseBinAndAssign(CompoundAssignOperator * expr) - { return TraverseCompoundAssignOperator(expr); } - bool TraverseBinOrAssign(CompoundAssignOperator * expr) - { return TraverseCompoundAssignOperator(expr); } - bool TraverseBinXorAssign(CompoundAssignOperator * expr) - { return TraverseCompoundAssignOperator(expr); } -#endif - bool TraverseInitListExpr(InitListExpr * expr); bool TraverseReturnStmt(ReturnStmt * stmt); @@ -613,7 +592,7 @@ bool ImplicitBoolConversion::TraverseCompoundAssignOperator(CompoundAssignOperat { report( DiagnosticsEngine::Warning, "mix of %0 and %1 in operator %2", - compat::getBeginLoc(expr->getRHS())) + expr->getRHS()->getBeginLoc()) << expr->getLHS()->getType() << expr->getRHS()->IgnoreParenImpCasts()->getType() << expr->getOpcodeStr() @@ -729,7 +708,7 @@ bool ImplicitBoolConversion::VisitImplicitCastExpr( DiagnosticsEngine::Warning, ("explicit conversion (%0) from %1 to %2 implicitly cast back" " to %3"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << sub->getCastKindName() << subsub->getType() << sub->getType() << expr->getType() << expr->getSourceRange(); return true; @@ -746,7 +725,7 @@ bool ImplicitBoolConversion::VisitImplicitCastExpr( report( DiagnosticsEngine::Warning, "implicit conversion (%0) of call argument from %1 to %2", - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getCastKindName() << expr->getSubExpr()->getType() << expr->getType() << expr->getSourceRange(); return true; @@ -761,7 +740,7 @@ bool ImplicitBoolConversion::VisitMaterializeTemporaryExpr( if (ignoreLocation(expr)) { return true; } - if (auto const sub = dyn_cast<ExplicitCastExpr>(compat::getSubExpr(expr))) { + if (auto const sub = dyn_cast<ExplicitCastExpr>(expr->getSubExpr())) { auto const subsub = compat::getSubExprAsWritten(sub); if (subsub->getType().IgnoreParens() == expr->getType().IgnoreParens() && isBool(subsub)) @@ -770,7 +749,7 @@ bool ImplicitBoolConversion::VisitMaterializeTemporaryExpr( DiagnosticsEngine::Warning, ("explicit conversion (%0) from %1 to %2 implicitly converted" " back to %3"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << sub->getCastKindName() << subsub->getType() << sub->getType() << expr->getType() << expr->getSourceRange(); return true; @@ -895,7 +874,7 @@ void ImplicitBoolConversion::reportWarning(ImplicitCastExpr const * expr) { } report( DiagnosticsEngine::Warning, - "implicit conversion (%0) from %1 to %2", compat::getBeginLoc(expr)) + "implicit conversion (%0) from %1 to %2", expr->getBeginLoc()) << expr->getCastKindName() << expr->getSubExprAsWritten()->getType() << expr->getType() << expr->getSourceRange(); } diff --git a/compilerplugins/clang/includeform.cxx b/compilerplugins/clang/includeform.cxx index 9d6587506a85..d9e603351783 100644 --- a/compilerplugins/clang/includeform.cxx +++ b/compilerplugins/clang/includeform.cxx @@ -29,11 +29,7 @@ private: void InclusionDirective( SourceLocation HashLoc, Token const & IncludeTok, StringRef, bool IsAngled, CharSourceRange FilenameRange, FileEntry const * File, - StringRef SearchPath, StringRef, clang::Module const * -#if CLANG_VERSION >= 70000 - , SrcMgr::CharacteristicKind -#endif - ) override + StringRef SearchPath, StringRef, clang::Module const *, SrcMgr::CharacteristicKind) override { if (ignoreLocation(HashLoc)) { return; diff --git a/compilerplugins/clang/indentation.cxx b/compilerplugins/clang/indentation.cxx index 2dda32f8174c..9ac5f3d7e521 100644 --- a/compilerplugins/clang/indentation.cxx +++ b/compilerplugins/clang/indentation.cxx @@ -16,6 +16,7 @@ #include <fstream> #include <set> #include <unordered_set> +#include "config_clang.h" #include "plugin.hxx" /* @@ -118,7 +119,7 @@ bool Indentation::VisitCompoundStmt(CompoundStmt const* compoundStmt) { auto stmt = *i; auto const actualPrevEnd = prevEnd; - prevEnd = compat::getEndLoc(stmt); // compute early, before below `continue`s + prevEnd = stmt->getEndLoc(); // compute early, before below `continue`s // these show up in macro expansions, not interesting if (isa<NullStmt>(stmt)) @@ -126,28 +127,8 @@ bool Indentation::VisitCompoundStmt(CompoundStmt const* compoundStmt) // these are always weirdly indented if (isa<LabelStmt>(stmt)) continue; -#if CLANG_VERSION < 100000 - // Before - // <https://github.com/llvm/llvm-project/commit/dc3957ec215dd17b8d293461f18696566637a6cd> - // "Include leading attributes in DeclStmt's SourceRange", getBeginLoc of a VarDecl DeclStmt - // with an UnusedAttr pointed after the attr (and getLocation of the attr pointed at - // "maybe_unused", not at the leading "[["), so just ignore those in old compiler versions: - if (auto const declStmt = dyn_cast<DeclStmt>(stmt)) - { - if (declStmt->decl_begin() != declStmt->decl_end()) - { - if (auto const decl = dyn_cast<VarDecl>(*declStmt->decl_begin())) - { - if (decl->hasAttr<UnusedAttr>()) - { - continue; - } - } - } - } -#endif - auto stmtLoc = compat::getBeginLoc(stmt); + auto stmtLoc = stmt->getBeginLoc(); StringRef macroName; bool partOfMacro = false; @@ -165,11 +146,7 @@ bool Indentation::VisitCompoundStmt(CompoundStmt const* compoundStmt) // similar thing in forms/ if (macroName == "DECL_IFACE_PROP_IMPL" || macroName == "DECL_BOOL_PROP_IMPL") continue; -#if CLANG_VERSION >= 70000 stmtLoc = SM.getExpansionRange(stmtLoc).getBegin(); -#else - stmtLoc = SM.getExpansionRange(stmtLoc).first; -#endif } // check for comment to the left of the statement @@ -211,13 +188,12 @@ bool Indentation::VisitCompoundStmt(CompoundStmt const* compoundStmt) { if (containsPreprocessingConditionalInclusion(SourceRange( locationAfterToken(compiler.getSourceManager().getExpansionLoc(actualPrevEnd)), - compiler.getSourceManager().getExpansionLoc(compat::getBeginLoc(stmt))))) + compiler.getSourceManager().getExpansionLoc(stmt->getBeginLoc())))) continue; report(DiagnosticsEngine::Warning, "statement mis-aligned compared to neighbours %0", stmtLoc) << macroName; - report(DiagnosticsEngine::Note, "measured against this one", - compat::getBeginLoc(firstStmt)); + report(DiagnosticsEngine::Note, "measured against this one", firstStmt->getBeginLoc()); //getParentStmt(compoundStmt)->dump(); //stmt->dump(); } @@ -228,7 +204,7 @@ bool Indentation::VisitCompoundStmt(CompoundStmt const* compoundStmt) auto bodyStmt = ifStmt->getThen(); if (bodyStmt && !isa<CompoundStmt>(bodyStmt)) { - stmtLoc = compat::getBeginLoc(bodyStmt); + stmtLoc = bodyStmt->getBeginLoc(); invalid1 = false; invalid2 = false; unsigned bodyColumn = SM.getPresumedColumnNumber(stmtLoc, &invalid1); @@ -243,7 +219,7 @@ bool Indentation::VisitCompoundStmt(CompoundStmt const* compoundStmt) auto elseStmt = ifStmt->getElse(); if (elseStmt && !isa<CompoundStmt>(elseStmt) && !isa<IfStmt>(elseStmt)) { - stmtLoc = compat::getBeginLoc(elseStmt); + stmtLoc = elseStmt->getBeginLoc(); invalid1 = false; invalid2 = false; unsigned elseColumn = SM.getPresumedColumnNumber(stmtLoc, &invalid1); @@ -340,7 +316,7 @@ void Indentation::checkCompoundStmtBraces(const Stmt* parentStmt, const Compound bool invalid1 = false; bool invalid2 = false; - auto parentBeginLoc = compat::getBeginLoc(parentStmt); + auto parentBeginLoc = parentStmt->getBeginLoc(); unsigned parentColumn = SM.getPresumedColumnNumber(parentBeginLoc, &invalid1); if (invalid1) return; @@ -405,7 +381,7 @@ void Indentation::checkCompoundStmtBraces(const Stmt* parentStmt, const Compound auto firstStmt = compoundStmt->body_front(); if (isa<LabelStmt>(firstStmt)) return; - auto firstStmtLoc = compat::getBeginLoc(firstStmt); + auto firstStmtLoc = firstStmt->getBeginLoc(); unsigned firstStmtBeginColumn = SM.getPresumedColumnNumber(firstStmtLoc, &invalid1); if (invalid1) return; @@ -440,7 +416,7 @@ bool Indentation::VisitSwitchStmt(SwitchStmt const* switchStmt) if (!caseStmt) continue; - auto stmtLoc = compat::getBeginLoc(caseStmt); + auto stmtLoc = caseStmt->getBeginLoc(); bool invalid1 = false; bool invalid2 = false; @@ -466,7 +442,7 @@ bool Indentation::VisitSwitchStmt(SwitchStmt const* switchStmt) // report(DiagnosticsEngine::Warning, "statement mis-aligned compared to neighbours", // stmtLoc); // report(DiagnosticsEngine::Note, "measured against this one", - // compat::getBeginLoc(firstStmt)); + // firstStmt->getBeginLoc()); //getParentStmt(compoundStmt)->dump(); //stmt->dump(); } diff --git a/compilerplugins/clang/inlinesimplememberfunctions.cxx b/compilerplugins/clang/inlinesimplememberfunctions.cxx index 668e9f252ab6..760094b5a03a 100644 --- a/compilerplugins/clang/inlinesimplememberfunctions.cxx +++ b/compilerplugins/clang/inlinesimplememberfunctions.cxx @@ -10,7 +10,6 @@ #include <string> #include "plugin.hxx" -#include "compat.hxx" // Methods that purely return a local field should be declared in the header and be declared inline. // So that the compiler can elide the function call and turn it into a simple fixed-offset-load instruction. @@ -243,8 +242,8 @@ bool InlineSimpleMemberFunctions::rewrite(const CXXMethodDecl * functionDecl) { const char *p1, *p2; // get the function body contents - p1 = compiler.getSourceManager().getCharacterData( compat::getBeginLoc(functionDecl->getBody()) ); - p2 = compiler.getSourceManager().getCharacterData( compat::getEndLoc(functionDecl->getBody()) ); + p1 = compiler.getSourceManager().getCharacterData( functionDecl->getBody()->getBeginLoc() ); + p2 = compiler.getSourceManager().getCharacterData( functionDecl->getBody()->getEndLoc() ); std::string s1( p1, p2 - p1 + 1); /* we can't safely move around stuff containing comments, we mess up the resulting code */ @@ -274,18 +273,18 @@ bool InlineSimpleMemberFunctions::rewrite(const CXXMethodDecl * functionDecl) { // remove the function's out of line body and declaration RewriteOptions opts; opts.RemoveLineIfEmpty = true; - if (!removeText(SourceRange(compat::getBeginLoc(functionDecl), compat::getEndLoc(functionDecl->getBody())), opts)) { + if (!removeText(SourceRange(functionDecl->getBeginLoc(), functionDecl->getBody()->getEndLoc()), opts)) { return false; } // scan forward until we find the semicolon const FunctionDecl * canonicalDecl = functionDecl->getCanonicalDecl(); - p1 = compiler.getSourceManager().getCharacterData( compat::getEndLoc(canonicalDecl) ); + p1 = compiler.getSourceManager().getCharacterData( canonicalDecl->getEndLoc() ); p2 = ++p1; while (*p2 != 0 && *p2 != ';') p2++; // insert the function body into the inline function definition (i.e. the one inside the class definition) - return replaceText(compat::getEndLoc(canonicalDecl).getLocWithOffset(p2 - p1 + 1), 1, s1); + return replaceText(canonicalDecl->getEndLoc().getLocWithOffset(p2 - p1 + 1), 1, s1); } loplugin::Plugin::Registration< InlineSimpleMemberFunctions > X("inlinesimplememberfunctions"); diff --git a/compilerplugins/clang/intvsfloat.cxx b/compilerplugins/clang/intvsfloat.cxx index d89b34155cce..771e2bca0db5 100644 --- a/compilerplugins/clang/intvsfloat.cxx +++ b/compilerplugins/clang/intvsfloat.cxx @@ -10,7 +10,6 @@ #include "plugin.hxx" #include "check.hxx" -#include "compat.hxx" #include <iostream> /** @@ -55,7 +54,7 @@ bool IntVsFloat::VisitVarDecl(VarDecl const* varDecl) if (static_cast<long>(*d) == *d) return true; report(DiagnosticsEngine::Warning, "assigning constant float value to int truncates data", - compat::getBeginLoc(init)) + init->getBeginLoc()) << init->getSourceRange(); return true; @@ -67,7 +66,7 @@ bool IntVsFloat::VisitBinaryOperator(BinaryOperator const* op) { return true; } - if (ignoreLocation(compat::getBeginLoc(op))) + if (ignoreLocation(op->getBeginLoc())) return true; auto lhs = op->getLHS()->IgnoreImpCasts(); auto rhs = op->getRHS()->IgnoreImpCasts(); @@ -83,7 +82,7 @@ bool IntVsFloat::VisitBinaryOperator(BinaryOperator const* op) if (static_cast<long>(*d) == *d) return true; report(DiagnosticsEngine::Warning, "comparing integer to float constant, can never be true", - compat::getBeginLoc(op)) + op->getBeginLoc()) << op->getSourceRange(); return true; } diff --git a/compilerplugins/clang/literaltoboolconversion.cxx b/compilerplugins/clang/literaltoboolconversion.cxx index 54521a60a209..9894daec51b6 100644 --- a/compilerplugins/clang/literaltoboolconversion.cxx +++ b/compilerplugins/clang/literaltoboolconversion.cxx @@ -126,10 +126,10 @@ void LiteralToBoolConversion::handleImplicitCastSubExpr( return; } if (!subExpr->isValueDependent()) { - if (auto const res = compat::getIntegerConstantExpr(subExpr, compiler.getASTContext())) { + if (auto const res = subExpr->getIntegerConstantExpr(compiler.getASTContext())) { if (res->getLimitedValue() <= 1) { - SourceLocation loc { compat::getBeginLoc(subExpr) }; + SourceLocation loc { subExpr->getBeginLoc() }; while (compiler.getSourceManager().isMacroArgExpansion(loc)) { loc = compiler.getSourceManager().getImmediateMacroCallerLoc(loc); } @@ -148,7 +148,7 @@ void LiteralToBoolConversion::handleImplicitCastSubExpr( } } if (isa<clang::StringLiteral>(subExpr)) { - SourceLocation loc { compat::getBeginLoc(subExpr) }; + SourceLocation loc { subExpr->getBeginLoc() }; if (compiler.getSourceManager().isMacroArgExpansion(loc) && (Lexer::getImmediateMacroName( loc, compiler.getSourceManager(), compiler.getLangOpts()) @@ -164,25 +164,25 @@ void LiteralToBoolConversion::handleImplicitCastSubExpr( bool bRewritten = false; if (rewriter != nullptr) { SourceLocation loc { compiler.getSourceManager().getExpansionLoc( - compat::getBeginLoc(expr2)) }; - if (compiler.getSourceManager().getExpansionLoc(compat::getEndLoc(expr2)) + expr2->getBeginLoc()) }; + if (compiler.getSourceManager().getExpansionLoc(expr2->getEndLoc()) == loc) { char const * s = compiler.getSourceManager().getCharacterData( loc); unsigned n = Lexer::MeasureTokenLength( - compat::getEndLoc(expr2), compiler.getSourceManager(), + expr2->getEndLoc(), compiler.getSourceManager(), compiler.getLangOpts()); std::string tok { s, n }; if (tok == "sal_False" || tok == "0") { bRewritten = replaceText( compiler.getSourceManager().getExpansionLoc( - compat::getBeginLoc(expr2)), + expr2->getBeginLoc()), n, "false"); } else if (tok == "sal_True" || tok == "1") { bRewritten = replaceText( compiler.getSourceManager().getExpansionLoc( - compat::getBeginLoc(expr2)), + expr2->getBeginLoc()), n, "true"); } } @@ -191,7 +191,7 @@ void LiteralToBoolConversion::handleImplicitCastSubExpr( report( DiagnosticsEngine::Warning, "implicit conversion (%0) of literal of type %1 to %2", - compat::getBeginLoc(expr2)) + expr2->getBeginLoc()) << castExpr->getCastKindName() << subExpr->getType() << castExpr->getType() << expr2->getSourceRange(); } @@ -208,16 +208,16 @@ void LiteralToBoolConversion::handleImplicitCastSubExpr( DiagnosticsEngine::Warning, ("implicit conversion (%0) of null pointer constant of type %1 to" " %2"), - compat::getBeginLoc(expr2)) + expr2->getBeginLoc()) << castExpr->getCastKindName() << subExpr->getType() << castExpr->getType() << expr2->getSourceRange(); } else if (!subExpr->isValueDependent()) { - if (auto const res = compat::getIntegerConstantExpr(subExpr, compiler.getASTContext())) { + if (auto const res = subExpr->getIntegerConstantExpr(compiler.getASTContext())) { report( DiagnosticsEngine::Warning, ("implicit conversion (%0) of integer constant expression of type" " %1 with value %2 to %3"), - compat::getBeginLoc(expr2)) + expr2->getBeginLoc()) << castExpr->getCastKindName() << subExpr->getType() << compat::toString(*res, 10) << castExpr->getType() << expr2->getSourceRange(); diff --git a/compilerplugins/clang/logexceptionnicely.cxx b/compilerplugins/clang/logexceptionnicely.cxx index a262d276b88c..b010b132dfa8 100644 --- a/compilerplugins/clang/logexceptionnicely.cxx +++ b/compilerplugins/clang/logexceptionnicely.cxx @@ -12,7 +12,7 @@ #include "plugin.hxx" #include "check.hxx" -#include "compat.hxx" +#include "config_clang.h" #include <fstream> #include <unordered_set> @@ -101,7 +101,7 @@ public: return true; StringRef fn = getFilenameOfLocation( - compiler.getSourceManager().getExpansionLoc(compat::getBeginLoc(operatorCallExpr))); + compiler.getSourceManager().getExpansionLoc(operatorCallExpr->getBeginLoc())); // these are below tools in the module hierarchy, so we can't use the pretty printing if (loplugin::hasPathnamePrefix(fn, SRCDIR "/include/comphelper/")) return true; @@ -120,7 +120,7 @@ public: return true; if (!isDerivedFromException(cxxRecordDecl)) return true; - auto loc = compat::getBeginLoc(operatorCallExpr); + auto loc = operatorCallExpr->getBeginLoc(); // for some reason, I'm warning multiple times? so just check if I've warned already if (!m_visited.insert(compiler.getSourceManager().getExpansionLoc(loc)).second) return true; diff --git a/compilerplugins/clang/loopvartoosmall.cxx b/compilerplugins/clang/loopvartoosmall.cxx index 896266385dea..bc03e94ca09b 100644 --- a/compilerplugins/clang/loopvartoosmall.cxx +++ b/compilerplugins/clang/loopvartoosmall.cxx @@ -16,6 +16,7 @@ #include <list> #include <map> +#include "compat.hxx" #include "plugin.hxx" //#include "clang/AST/CXXInheritance.h" diff --git a/compilerplugins/clang/makeshared.cxx b/compilerplugins/clang/makeshared.cxx index bac0ea0a5653..902d200ff562 100644 --- a/compilerplugins/clang/makeshared.cxx +++ b/compilerplugins/clang/makeshared.cxx @@ -16,8 +16,9 @@ #include <clang/AST/CXXInheritance.h> +#include "config_clang.h" + #include "check.hxx" -#include "compat.hxx" #include "plugin.hxx" /** @@ -142,14 +143,14 @@ bool MakeShared::VisitCXXConstructExpr(CXXConstructExpr const* constructExpr) } StringRef fn = getFilenameOfLocation( - compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(constructExpr))); + compiler.getSourceManager().getSpellingLoc(constructExpr->getBeginLoc())); if (loplugin::isSamePathname(fn, SRCDIR "/include/o3tl/make_shared.hxx")) return true; if (loplugin::isSamePathname(fn, SRCDIR "/svl/source/items/stylepool.cxx")) return true; report(DiagnosticsEngine::Warning, "rather use make_shared than constructing from %0", - compat::getBeginLoc(constructExpr)) + constructExpr->getBeginLoc()) << arg0->getType() << constructExpr->getSourceRange(); return true; } @@ -184,11 +185,11 @@ bool MakeShared::VisitCXXMemberCallExpr(CXXMemberCallExpr const* cxxMemberCallEx return true; StringRef fn = getFilenameOfLocation( - compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(cxxMemberCallExpr))); + compiler.getSourceManager().getSpellingLoc(cxxMemberCallExpr->getBeginLoc())); if (loplugin::isSamePathname(fn, SRCDIR "/include/o3tl/make_shared.hxx")) return true; - report(DiagnosticsEngine::Warning, "rather use make_shared", compat::getBeginLoc(cxxNewExpr)) + report(DiagnosticsEngine::Warning, "rather use make_shared", cxxNewExpr->getBeginLoc()) << cxxNewExpr->getSourceRange(); return true; @@ -210,7 +211,7 @@ bool MakeShared::VisitCXXOperatorCallExpr(CXXOperatorCallExpr const* operCallExp return true; report(DiagnosticsEngine::Warning, "rather use make_shared than constructing from %0", - compat::getBeginLoc(operCallExpr)) + operCallExpr->getBeginLoc()) << operCallExpr->getArg(1)->getType() << operCallExpr->getSourceRange(); return true; @@ -236,7 +237,7 @@ bool MakeShared::VisitVarDecl(VarDecl const* varDecl) return true; report(DiagnosticsEngine::Warning, "rather use make_shared than constructing from %0", - compat::getBeginLoc(varDecl)) + varDecl->getBeginLoc()) << varDecl->getInit()->getType() << varDecl->getSourceRange(); return true; diff --git a/compilerplugins/clang/memoryvar.cxx b/compilerplugins/clang/memoryvar.cxx index 2354739f458f..14c328ba40dd 100644 --- a/compilerplugins/clang/memoryvar.cxx +++ b/compilerplugins/clang/memoryvar.cxx @@ -13,6 +13,7 @@ #include <map> #include <set> +#include "config_clang.h" #include "plugin.hxx" #include "clang/AST/CXXInheritance.h" diff --git a/compilerplugins/clang/mergeclasses.cxx b/compilerplugins/clang/mergeclasses.cxx index 017f66680ffb..a644677caf76 100644 --- a/compilerplugins/clang/mergeclasses.cxx +++ b/compilerplugins/clang/mergeclasses.cxx @@ -11,6 +11,7 @@ #include <set> #include <string> #include <iostream> +#include "config_clang.h" #include "plugin.hxx" #include <fstream> @@ -144,7 +145,7 @@ bool MergeClasses::VisitCXXRecordDecl(const CXXRecordDecl* decl) } if (decl->isThisDeclarationADefinition()) { - SourceLocation spellingLocation = compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(decl)); + SourceLocation spellingLocation = compiler.getSourceManager().getSpellingLoc(decl->getBeginLoc()); auto filename = getFilenameOfLocation(spellingLocation); filename = filename.substr(strlen(SRCDIR)); std::string s = decl->getQualifiedNameAsString(); diff --git a/compilerplugins/clang/methodcycles.cxx b/compilerplugins/clang/methodcycles.cxx index d495f425ba6b..7b58a4bb52b6 100644 --- a/compilerplugins/clang/methodcycles.cxx +++ b/compilerplugins/clang/methodcycles.cxx @@ -17,6 +17,8 @@ #include "clang/AST/Attr.h" +#include "config_clang.h" + #include "plugin.hxx" /** @@ -126,10 +128,6 @@ MyFuncInfo MethodCycles::niceName(const FunctionDecl* functionDecl) { if (functionDecl->getInstantiatedFromMemberFunction()) functionDecl = functionDecl->getInstantiatedFromMemberFunction(); -#if CLANG_VERSION < 90000 - else if (functionDecl->getClassScopeSpecializationPattern()) - functionDecl = functionDecl->getClassScopeSpecializationPattern(); -#endif else if (functionDecl->getTemplateInstantiationPattern()) functionDecl = functionDecl->getTemplateInstantiationPattern(); diff --git a/compilerplugins/clang/moveparam.cxx b/compilerplugins/clang/moveparam.cxx index 930e8a61a927..dc7a84b4d64d 100644 --- a/compilerplugins/clang/moveparam.cxx +++ b/compilerplugins/clang/moveparam.cxx @@ -15,6 +15,7 @@ #include <fstream> #include <set> #include <unordered_set> +#include "config_clang.h" #include "plugin.hxx" #include "check.hxx" @@ -90,21 +91,21 @@ bool MoveParam::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr* callExpr) return true; StringRef aFileName = getFilenameOfLocation( - compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(parmVarDecl))); + compiler.getSourceManager().getSpellingLoc(parmVarDecl->getBeginLoc())); if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/svx/source/sidebar/line/LineWidthValueSet.cxx")) return true; - report(DiagnosticsEngine::Warning, "rather use move && param1", compat::getBeginLoc(callExpr)); + report(DiagnosticsEngine::Warning, "rather use move && param1", callExpr->getBeginLoc()); return true; } bool MoveParam::VisitCXXConstructExpr(const CXXConstructExpr* constructExpr) { - if (ignoreLocation(compat::getBeginLoc(constructExpr))) + if (ignoreLocation(constructExpr->getBeginLoc())) return true; - if (isInUnoIncludeFile(compat::getBeginLoc(constructExpr))) + if (isInUnoIncludeFile(constructExpr->getBeginLoc())) return true; auto qt = constructExpr->getType(); @@ -126,7 +127,7 @@ bool MoveParam::VisitCXXConstructExpr(const CXXConstructExpr* constructExpr) return true; StringRef aFileName = getFilenameOfLocation( - compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(parmVarDecl))); + compiler.getSourceManager().getSpellingLoc(parmVarDecl->getBeginLoc())); if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/include/drawinglayer/primitive2d/Primitive2DContainer.hxx")) return true; @@ -155,8 +156,7 @@ bool MoveParam::VisitCXXConstructExpr(const CXXConstructExpr* constructExpr) SRCDIR "/stoc/source/servicemanager/servicemanager.cxx")) return true; - report(DiagnosticsEngine::Warning, "rather use move && param3", - compat::getBeginLoc(constructExpr)); + report(DiagnosticsEngine::Warning, "rather use move && param3", constructExpr->getBeginLoc()); return true; } diff --git a/compilerplugins/clang/namespaceindentation.cxx b/compilerplugins/clang/namespaceindentation.cxx index 95182197cbd5..1398efc86adf 100644 --- a/compilerplugins/clang/namespaceindentation.cxx +++ b/compilerplugins/clang/namespaceindentation.cxx @@ -84,8 +84,8 @@ bool NamespaceIndentation::VisitNamespaceDecl(NamespaceDecl const* nsDecl) { bool invalid1 = false; bool invalid2 = false; - unsigned line1 = SM.getPresumedLineNumber(compat::getBeginLoc(nsDecl), &invalid1); - unsigned line2 = SM.getPresumedLineNumber(compat::getBeginLoc(child), &invalid2); + unsigned line1 = SM.getPresumedLineNumber(nsDecl->getBeginLoc(), &invalid1); + unsigned line2 = SM.getPresumedLineNumber(child->getBeginLoc(), &invalid2); if (line1 == line2) return true; } @@ -95,12 +95,12 @@ bool NamespaceIndentation::VisitNamespaceDecl(NamespaceDecl const* nsDecl) // if we are inside the yyy NameSpaceDecl of // namespace xxx::yyy // the beginLoc is just between the "xxx" and the "::" - auto nsDeclBeginLoc = compat::getBeginLoc(nsDecl); + auto nsDeclBeginLoc = nsDecl->getBeginLoc(); bool foundMultiple = false; { constexpr int BACKSCAN = 32; - auto beginLoc = compat::getBeginLoc(nsDecl).getLocWithOffset(-BACKSCAN); - auto endLoc = compat::getBeginLoc(nsDecl).getLocWithOffset(3); + auto beginLoc = nsDecl->getBeginLoc().getLocWithOffset(-BACKSCAN); + auto endLoc = nsDecl->getBeginLoc().getLocWithOffset(3); const char* p1 = SM.getCharacterData(beginLoc); const char* p2 = SM.getCharacterData(endLoc); unsigned n = Lexer::MeasureTokenLength(endLoc, SM, compiler.getLangOpts()); @@ -114,7 +114,7 @@ bool NamespaceIndentation::VisitNamespaceDecl(NamespaceDecl const* nsDecl) if (namespaceToken.find("::") != std::string::npos) { auto idx = s.rfind("\n"); - nsDeclBeginLoc = compat::getBeginLoc(nsDecl).getLocWithOffset(idx - BACKSCAN + 1); + nsDeclBeginLoc = nsDecl->getBeginLoc().getLocWithOffset(idx - BACKSCAN + 1); foundMultiple = true; } } @@ -140,8 +140,8 @@ bool NamespaceIndentation::VisitNamespaceDecl(NamespaceDecl const* nsDecl) nsDecl->getRBraceLoc()); // no easy way to get the position of the left brace - auto endLoc = compat::getBeginLoc(nsDecl).getLocWithOffset(256); - const char* p1 = SM.getCharacterData(SM.getExpansionLoc(compat::getBeginLoc(nsDecl))); + auto endLoc = nsDecl->getBeginLoc().getLocWithOffset(256); + const char* p1 = SM.getCharacterData(SM.getExpansionLoc(nsDecl->getBeginLoc())); const char* p2 = SM.getCharacterData(SM.getExpansionLoc(endLoc)); unsigned n = Lexer::MeasureTokenLength(endLoc, SM, compiler.getLangOpts()); if (p2 < p1 || n > 128 || (p2 - p1 + n) > 2048) @@ -155,7 +155,7 @@ bool NamespaceIndentation::VisitNamespaceDecl(NamespaceDecl const* nsDecl) auto col3 = idx2 - idx1; if (col1 != col3) report(DiagnosticsEngine::Warning, "statement left brace mis-aligned", - compat::getBeginLoc(nsDecl)); + nsDecl->getBeginLoc()); } // extract the comment following the end brace diff --git a/compilerplugins/clang/noexceptmove.cxx b/compilerplugins/clang/noexceptmove.cxx index c2cbdcf0c2a3..4f242848a3c4 100644 --- a/compilerplugins/clang/noexceptmove.cxx +++ b/compilerplugins/clang/noexceptmove.cxx @@ -8,12 +8,10 @@ */ // versions before 9.0 didn't have getExceptionSpecType +#include "check.hxx" #include "plugin.hxx" -// clang before V9 does not have API to report exception spec type -#if CLANG_VERSION >= 90000 - -#include "check.hxx" +#include "config_clang.h" #include <string> #include <set> @@ -120,7 +118,7 @@ bool NoExceptMove::TraverseCXXMethodDecl(CXXMethodDecl* methodDecl) if (isMove) { StringRef fn = getFilenameOfLocation( - compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(methodDecl))); + compiler.getSourceManager().getSpellingLoc(methodDecl->getBeginLoc())); // SfxObjectShellLock::operator= calls SotObject::OwnerLock which in turn calls stuff which cannot be noexcept if (loplugin::isSamePathname(fn, SRCDIR "/include/sfx2/objsh.hxx")) isMove = false; @@ -330,5 +328,4 @@ llvm::Optional<bool> NoExceptMove::IsCallThrows(const CallExpr* callExpr) loplugin::Plugin::Registration<NoExceptMove> noexceptmove("noexceptmove"); } -#endif // CLANG_VERSION /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/compilerplugins/clang/nullptr.cxx b/compilerplugins/clang/nullptr.cxx index 55551ac09292..dcacb1bd2112 100644 --- a/compilerplugins/clang/nullptr.cxx +++ b/compilerplugins/clang/nullptr.cxx @@ -121,7 +121,7 @@ bool Nullptr::VisitImplicitCastExpr(CastExpr const * expr) { case Expr::NPCK_ZeroLiteral: report( DiagnosticsEngine::Warning, - "suspicious ValueDependentIsNull %0", compat::getBeginLoc(expr)) + "suspicious ValueDependentIsNull %0", expr->getBeginLoc()) << kindName(k) << expr->getSourceRange(); break; default: @@ -313,7 +313,7 @@ void Nullptr::handleNull( SourceLocation loc; for (;;) { e = e->IgnoreImpCasts(); - loc = compat::getBeginLoc(e); + loc = e->getBeginLoc(); while (compiler.getSourceManager().isMacroArgExpansion(loc)) { loc = compiler.getSourceManager().getImmediateMacroCallerLoc(loc); } @@ -378,7 +378,7 @@ void Nullptr::rewriteOrWarn( Expr::NullPointerConstantKind nullPointerKind, char const * replacement) { if (rewriter != nullptr) { - SourceLocation locStart(compat::getBeginLoc(expr)); + SourceLocation locStart(expr->getBeginLoc()); while (compiler.getSourceManager().isMacroArgExpansion(locStart)) { locStart = compiler.getSourceManager() .getImmediateMacroCallerLoc(locStart); @@ -393,7 +393,7 @@ void Nullptr::rewriteOrWarn( locStart = compat::getImmediateExpansionRange(compiler.getSourceManager(), locStart) .first; } - SourceLocation locEnd(compat::getEndLoc(expr)); + SourceLocation locEnd(expr->getEndLoc()); while (compiler.getSourceManager().isMacroArgExpansion(locEnd)) { locEnd = compiler.getSourceManager() .getImmediateMacroCallerLoc(locEnd); @@ -412,13 +412,13 @@ void Nullptr::rewriteOrWarn( } } if (castKind == nullptr) { - report(DiagnosticsEngine::Warning, "%0 -> %1", compat::getBeginLoc(expr)) + report(DiagnosticsEngine::Warning, "%0 -> %1", expr->getBeginLoc()) << kindName(nullPointerKind) << replacement << expr->getSourceRange(); } else { report( DiagnosticsEngine::Warning, "%0 ValueDependentIsNotNull %1 -> %2", - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << castKind << kindName(nullPointerKind) << replacement << expr->getSourceRange(); } diff --git a/compilerplugins/clang/oncevar.cxx b/compilerplugins/clang/oncevar.cxx index 0f809b9ebfac..44fcfa950843 100644 --- a/compilerplugins/clang/oncevar.cxx +++ b/compilerplugins/clang/oncevar.cxx @@ -15,6 +15,7 @@ #include "plugin.hxx" #include "check.hxx" +#include "config_clang.h" #include "clang/AST/CXXInheritance.h" #include "clang/AST/StmtVisitor.h" @@ -318,7 +319,7 @@ bool OnceVar::VisitVarDecl( const VarDecl* varDecl ) return true; } // Ignore macros like FD_ZERO - if (compiler.getSourceManager().isMacroBodyExpansion(compat::getBeginLoc(varDecl))) { + if (compiler.getSourceManager().isMacroBodyExpansion(varDecl->getBeginLoc())) { return true; } if (varDecl->hasGlobalStorage()) { diff --git a/compilerplugins/clang/plugin.cxx b/compilerplugins/clang/plugin.cxx index edf91f33d19b..8bf5b4333bdc 100644 --- a/compilerplugins/clang/plugin.cxx +++ b/compilerplugins/clang/plugin.cxx @@ -15,6 +15,7 @@ #include <cstddef> #include <string> +#include <clang/AST/ParentMapContext.h> #include <clang/Basic/FileManager.h> #include <clang/Lex/Lexer.h> @@ -24,10 +25,6 @@ #include "pluginhandler.hxx" #include "check.hxx" -#if CLANG_VERSION >= 110000 -#include "clang/AST/ParentMapContext.h" -#endif - /* Base classes for plugin actions. */ @@ -38,7 +35,7 @@ namespace { Expr const * skipImplicit(Expr const * expr) { if (auto const e = dyn_cast<MaterializeTemporaryExpr>(expr)) { - expr = compat::getSubExpr(e)->IgnoreImpCasts(); + expr = e->getSubExpr()->IgnoreImpCasts(); } if (auto const e = dyn_cast<CXXBindTemporaryExpr>(expr)) { expr = e->getSubExpr(); diff --git a/compilerplugins/clang/plugin.hxx b/compilerplugins/clang/plugin.hxx index 1694bdb0782a..86ca8f825e02 100644 --- a/compilerplugins/clang/plugin.hxx +++ b/compilerplugins/clang/plugin.hxx @@ -22,7 +22,6 @@ #include <clang/Rewrite/Core/Rewriter.h> -#include "compat.hxx" #include "pluginhandler.hxx" using namespace clang; @@ -120,7 +119,7 @@ public: explicit FilteringPlugin( const InstantiationData& data ) : Plugin(data) {} bool TraverseNamespaceDecl(NamespaceDecl * decl) { - if (ignoreLocation(compat::getBeginLoc(decl))) + if (ignoreLocation(decl->getBeginLoc())) return true; return RecursiveASTVisitor<Derived>::TraverseNamespaceDecl(decl); } @@ -220,15 +219,12 @@ bool Plugin::ignoreLocation( const Stmt* stmt ) const { // Invalid location can happen at least for ImplicitCastExpr of // ImplicitParam 'self' in Objective C method declarations: - return compat::getBeginLoc(stmt).isValid() && ignoreLocation( compat::getBeginLoc(stmt)); + return stmt->getBeginLoc().isValid() && ignoreLocation( stmt->getBeginLoc()); } inline bool Plugin::ignoreLocation(TypeLoc tloc) const { - // Invalid locations appear to happen at least with Clang 5.0.2 (but no longer with at least - // recent Clang 10 trunk): - auto const loc = tloc.getBeginLoc(); - return loc.isValid() && ignoreLocation(loc); + return ignoreLocation(tloc.getBeginLoc()); } template< typename T > @@ -266,7 +262,7 @@ public: explicit FilteringRewritePlugin( const InstantiationData& data ) : RewritePlugin(data) {} bool TraverseNamespaceDecl(NamespaceDecl * decl) { - if (ignoreLocation(compat::getBeginLoc(decl))) + if (ignoreLocation(decl->getBeginLoc())) return true; return RecursiveASTVisitor<Derived>::TraverseNamespaceDecl(decl); } diff --git a/compilerplugins/clang/pluginhandler.cxx b/compilerplugins/clang/pluginhandler.cxx index 35b5e03298b4..2856d5a0e378 100644 --- a/compilerplugins/clang/pluginhandler.cxx +++ b/compilerplugins/clang/pluginhandler.cxx @@ -13,18 +13,16 @@ #include <system_error> #include <utility> -#include "compat.hxx" +#include "config_clang.h" + #include "plugin.hxx" #include "pluginhandler.hxx" #include <clang/Frontend/CompilerInstance.h> #include <clang/Frontend/FrontendPluginRegistry.h> #include <clang/Lex/PPCallbacks.h> -#include <stdio.h> - -#if CLANG_VERSION >= 90000 #include <llvm/Support/TimeProfiler.h> -#endif +#include <stdio.h> #if defined _WIN32 #include <process.h> @@ -232,7 +230,6 @@ bool PluginHandler::ignoreLocation(SourceLocation loc) { bool PluginHandler::checkIgnoreLocation(SourceLocation loc) { -#if CLANG_VERSION >= 80000 // If a location comes from a PCH, it is not necessary to check it // in every compilation using the PCH, since with Clang we use // -building-pch-with-obj to build a separate precompiled_foo.cxx file @@ -244,7 +241,6 @@ bool PluginHandler::checkIgnoreLocation(SourceLocation loc) if( !compiler.getLangOpts().BuildingPCHWithObjectFile ) return true; } -#endif SourceLocation expansionLoc = compiler.getSourceManager().getExpansionLoc( loc ); if( compiler.getSourceManager().isInSystemHeader( expansionLoc )) return true; @@ -314,9 +310,7 @@ void PluginHandler::addSourceModification(SourceRange range) void PluginHandler::HandleTranslationUnit( ASTContext& context ) { -#if CLANG_VERSION >= 90000 llvm::TimeTraceScope mainTimeScope("LOPluginMain", StringRef("")); -#endif if( context.getDiagnostics().hasErrorOccurred()) return; if (mainFileName.endswith(".ii")) @@ -330,9 +324,7 @@ void PluginHandler::HandleTranslationUnit( ASTContext& context ) { if( plugins[ i ].object != NULL && !plugins[ i ].disabledRun ) { -#if CLANG_VERSION >= 90000 llvm::TimeTraceScope timeScope("LOPlugin", [&]() { return plugins[i].optionName; }); -#endif plugins[ i ].object->run(); } } @@ -393,7 +385,7 @@ void PluginHandler::HandleTranslationUnit( ASTContext& context ) bool bOk = false; std::error_code ec; std::unique_ptr<raw_fd_ostream> ostream( - new raw_fd_ostream(filename, ec, compat::OF_None)); + new raw_fd_ostream(filename, ec, sys::fs::OF_None)); if( !ec) { it->second.write( *ostream ); diff --git a/compilerplugins/clang/pointerbool.cxx b/compilerplugins/clang/pointerbool.cxx index 6886e1fac63f..3bc87e743e98 100644 --- a/compilerplugins/clang/pointerbool.cxx +++ b/compilerplugins/clang/pointerbool.cxx @@ -16,6 +16,7 @@ #include <clang/AST/CXXInheritance.h> #include "plugin.hxx" #include "check.hxx" +#include "compat.hxx" /** Look for calls where the param is bool but the call-site-arg is pointer. diff --git a/compilerplugins/clang/privatebase.cxx b/compilerplugins/clang/privatebase.cxx index 6819647f88c5..210ce6376d66 100644 --- a/compilerplugins/clang/privatebase.cxx +++ b/compilerplugins/clang/privatebase.cxx @@ -43,7 +43,7 @@ bool PrivateBase::VisitCXXRecordDecl(CXXRecordDecl const * decl) { DiagnosticsEngine::Warning, "base class is private by default; explicitly give an access" " specifier", - compat::getBeginLoc(i)) + i->getBeginLoc()) << i->getSourceRange(); } } diff --git a/compilerplugins/clang/rangedforcopy.cxx b/compilerplugins/clang/rangedforcopy.cxx index 68004a1708ae..01124bb4d117 100644 --- a/compilerplugins/clang/rangedforcopy.cxx +++ b/compilerplugins/clang/rangedforcopy.cxx @@ -53,7 +53,7 @@ bool RangedForCopy::VisitCXXForRangeStmt( const CXXForRangeStmt* stmt ) report( DiagnosticsEngine::Warning, "Loop variable passed by value, pass by reference instead, e.g. 'const %0&'", - compat::getBeginLoc(varDecl)) + varDecl->getBeginLoc()) << name << varDecl->getSourceRange(); } diff --git a/compilerplugins/clang/reducevarscope.cxx b/compilerplugins/clang/reducevarscope.cxx index c293fd432e6a..be7254a2d569 100644 --- a/compilerplugins/clang/reducevarscope.cxx +++ b/compilerplugins/clang/reducevarscope.cxx @@ -18,6 +18,7 @@ #include "plugin.hxx" #include "check.hxx" +#include "config_clang.h" #include "clang/AST/CXXInheritance.h" #include "clang/AST/StmtVisitor.h" @@ -392,7 +393,7 @@ bool ReduceVarScope::VisitVarDecl(const VarDecl* varDecl) if (!compiler.getSourceManager().isInMainFile(varDecl->getLocation())) return true; // Ignore macros like FD_ZERO - if (compiler.getSourceManager().isMacroBodyExpansion(compat::getBeginLoc(varDecl))) + if (compiler.getSourceManager().isMacroBodyExpansion(varDecl->getBeginLoc())) return true; if (varDecl->hasGlobalStorage()) return true; diff --git a/compilerplugins/clang/redundantcast.cxx b/compilerplugins/clang/redundantcast.cxx index 27566809494c..1cfe44c9305e 100644 --- a/compilerplugins/clang/redundantcast.cxx +++ b/compilerplugins/clang/redundantcast.cxx @@ -158,7 +158,7 @@ private: bool isOverloadedFunction(FunctionDecl const * decl); bool isInIgnoredMacroBody(Expr const * expr) { - auto const loc = compat::getBeginLoc(expr); + auto const loc = expr->getBeginLoc(); return compiler.getSourceManager().isMacroBodyExpansion(loc) && ignoreLocation(compiler.getSourceManager().getSpellingLoc(loc)); } @@ -232,7 +232,7 @@ bool RedundantCast::VisitImplicitCastExpr(const ImplicitCastExpr * expr) { dyn_cast<CXXStaticCastExpr>(e)->getSubExpr() ->IgnoreParenImpCasts()->getType()) && !compiler.getSourceManager().isMacroBodyExpansion( - compat::getBeginLoc(e))) + e->getBeginLoc())) { report( DiagnosticsEngine::Warning, @@ -312,7 +312,7 @@ bool RedundantCast::VisitCStyleCastExpr(CStyleCastExpr const * expr) { if (ignoreLocation(expr)) { return true; } - if (isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(expr)))) { + if (isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc(expr->getBeginLoc()))) { return true; } auto t1 = compat::getSubExprAsWritten(expr)->getType(); @@ -333,7 +333,7 @@ bool RedundantCast::VisitCStyleCastExpr(CStyleCastExpr const * expr) { // Ignore FD_ISSET expanding to "...(SOCKET)(fd)..." in some Microsoft // winsock2.h (TODO: improve heuristic of determining that the whole // expr is part of a single macro body expansion): - auto l1 = compat::getBeginLoc(expr); + auto l1 = expr->getBeginLoc(); while (compiler.getSourceManager().isMacroArgExpansion(l1)) { l1 = compiler.getSourceManager().getImmediateMacroCallerLoc(l1); } @@ -341,7 +341,7 @@ bool RedundantCast::VisitCStyleCastExpr(CStyleCastExpr const * expr) { while (compiler.getSourceManager().isMacroArgExpansion(l2)) { l2 = compiler.getSourceManager().getImmediateMacroCallerLoc(l2); } - auto l3 = compat::getEndLoc(expr); + auto l3 = expr->getEndLoc(); while (compiler.getSourceManager().isMacroArgExpansion(l3)) { l3 = compiler.getSourceManager().getImmediateMacroCallerLoc(l3); } @@ -551,7 +551,7 @@ bool RedundantCast::VisitCXXStaticCastExpr(CXXStaticCastExpr const * expr) { // h=b5889d25e9bf944a89fdd7bcabf3b6c6f6bb6f7c> "assert: Support types // without operator== (int) [BZ #21972]": if (t1->isBooleanType() && t2->isBooleanType()) { - auto loc = compat::getBeginLoc(expr); + auto loc = expr->getBeginLoc(); if (compiler.getSourceManager().isMacroBodyExpansion(loc) && (Lexer::getImmediateMacroName( loc, compiler.getSourceManager(), compiler.getLangOpts()) @@ -607,13 +607,13 @@ bool RedundantCast::VisitCXXReinterpretCastExpr( return true; } if (rewriter != nullptr) { - auto loc = compat::getBeginLoc(expr); + auto loc = expr->getBeginLoc(); while (compiler.getSourceManager().isMacroArgExpansion(loc)) { loc = compiler.getSourceManager().getImmediateMacroCallerLoc( loc); } if (compiler.getSourceManager().isMacroBodyExpansion(loc)) { - auto loc2 = compat::getEndLoc(expr); + auto loc2 = expr->getEndLoc(); while (compiler.getSourceManager().isMacroArgExpansion(loc2)) { loc2 = compiler.getSourceManager() .getImmediateMacroCallerLoc(loc2); @@ -795,8 +795,8 @@ bool RedundantCast::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr const * exp // // in sal/osl/unx/socket.cxx: //TODO: Better check that sub is exactly an expansion of FD_ISSET: - if (compat::getEndLoc(sub).isMacroID()) { - for (auto loc = compat::getBeginLoc(sub); + if (sub->getEndLoc().isMacroID()) { + for (auto loc = sub->getBeginLoc(); loc.isMacroID() && (compiler.getSourceManager() .isAtStartOfImmediateMacroExpansion(loc)); diff --git a/compilerplugins/clang/redundantfcast.cxx b/compilerplugins/clang/redundantfcast.cxx index 67ff2c56edef..ac768caf276e 100644 --- a/compilerplugins/clang/redundantfcast.cxx +++ b/compilerplugins/clang/redundantfcast.cxx @@ -42,7 +42,7 @@ public: expr = cxxConstructExpr->getArg(0); } if (auto materializeTemporaryExpr = dyn_cast<MaterializeTemporaryExpr>(expr)) - expr = compat::getSubExpr(materializeTemporaryExpr); + expr = materializeTemporaryExpr->getSubExpr(); auto cxxFunctionalCastExpr = dyn_cast<CXXFunctionalCastExpr>(expr); if (!cxxFunctionalCastExpr) return true; @@ -94,7 +94,7 @@ public: if (!materializeTemporaryExpr) continue; auto functionalCast = dyn_cast<CXXFunctionalCastExpr>( - compat::getSubExpr(materializeTemporaryExpr)->IgnoreImpCasts()); + materializeTemporaryExpr->getSubExpr()->IgnoreImpCasts()); if (!functionalCast) continue; auto const t1 = functionalCast->getTypeAsWritten(); diff --git a/compilerplugins/clang/redundantinline.cxx b/compilerplugins/clang/redundantinline.cxx index 3bda99e397cb..1172dfec33d3 100644 --- a/compilerplugins/clang/redundantinline.cxx +++ b/compilerplugins/clang/redundantinline.cxx @@ -43,11 +43,11 @@ private: assert(inlineLoc->isInvalid()); unsigned n = {}; // avoid -Werror=maybe-uninitialized auto end = Lexer::getLocForEndOfToken( - compiler.getSourceManager().getExpansionLoc(compat::getEndLoc(decl)), 0, + compiler.getSourceManager().getExpansionLoc(decl->getEndLoc()), 0, compiler.getSourceManager(), compiler.getLangOpts()); assert(end.isValid()); for (auto loc = compiler.getSourceManager().getExpansionLoc( - compat::getBeginLoc(decl)); + decl->getBeginLoc()); loc != end; loc = loc.getLocWithOffset(std::max<unsigned>(n, 1))) { n = Lexer::MeasureTokenLength( @@ -116,8 +116,8 @@ private: } bool isInMacroExpansion(FunctionDecl const * decl, StringRef name) { - auto loc = unwindTo(compat::getBeginLoc(decl), name); - return loc.isValid() && loc == unwindTo(compat::getEndLoc(decl), name); + auto loc = unwindTo(decl->getBeginLoc(), name); + return loc.isValid() && loc == unwindTo(decl->getEndLoc(), name); } bool handleImplicitInline(FunctionDecl const * decl) { @@ -134,7 +134,7 @@ private: report( DiagnosticsEngine::Warning, "function definition redundantly declared 'inline'", - inlineLoc.isValid() ? inlineLoc : compat::getBeginLoc(decl)) + inlineLoc.isValid() ? inlineLoc : decl->getBeginLoc()) << decl->getSourceRange(); } return true; @@ -161,7 +161,7 @@ private: report( DiagnosticsEngine::Warning, "function has no external linkage but is explicitly declared 'inline'", - inlineLoc.isValid() ? inlineLoc : compat::getBeginLoc(decl)) + inlineLoc.isValid() ? inlineLoc : decl->getBeginLoc()) << decl->getSourceRange(); } return true; diff --git a/compilerplugins/clang/redundantpointerops.cxx b/compilerplugins/clang/redundantpointerops.cxx index 45b0783af0ab..caf6d4741170 100644 --- a/compilerplugins/clang/redundantpointerops.cxx +++ b/compilerplugins/clang/redundantpointerops.cxx @@ -17,7 +17,6 @@ #include <clang/AST/CXXInheritance.h> #include "check.hxx" -#include "compat.hxx" #include "plugin.hxx" /** @@ -68,7 +67,7 @@ bool RedundantPointerOps::VisitMemberExpr(MemberExpr const * memberExpr) { if (ignoreLocation(memberExpr)) return true; - if (compat::getBeginLoc(memberExpr).isMacroID()) + if (memberExpr->getBeginLoc().isMacroID()) return true; auto base = memberExpr->getBase()->IgnoreParenImpCasts(); //parentStmt(parentStmt(memberExpr))->dump(); @@ -80,7 +79,7 @@ bool RedundantPointerOps::VisitMemberExpr(MemberExpr const * memberExpr) report( DiagnosticsEngine::Warning, "'&' followed by '->' operating on %0, rather use '.'", - compat::getBeginLoc(memberExpr)) + memberExpr->getBeginLoc()) << memberExpr->getBase()->getType()->getPointeeType() << memberExpr->getSourceRange(); @@ -91,7 +90,7 @@ bool RedundantPointerOps::VisitMemberExpr(MemberExpr const * memberExpr) report( DiagnosticsEngine::Warning, "'&' followed by '->' operating on %0, rather use '.'", - compat::getBeginLoc(memberExpr)) + memberExpr->getBeginLoc()) << memberExpr->getBase()->getType()->getPointeeType() << memberExpr->getSourceRange(); @@ -106,7 +105,7 @@ bool RedundantPointerOps::VisitMemberExpr(MemberExpr const * memberExpr) report( DiagnosticsEngine::Warning, "'get()' followed by '->' operating on %0, just use '->'", - compat::getBeginLoc(memberExpr)) + memberExpr->getBeginLoc()) << e->IgnoreImpCasts()->getType().getLocalUnqualifiedType() << memberExpr->getSourceRange(); } @@ -131,7 +130,7 @@ bool RedundantPointerOps::VisitUnaryOperator(UnaryOperator const * unaryOperator { if (ignoreLocation(unaryOperator)) return true; - if (compat::getBeginLoc(unaryOperator).isMacroID()) + if (unaryOperator->getBeginLoc().isMacroID()) return true; if (unaryOperator->getOpcode() != UO_Deref) return true; @@ -140,7 +139,7 @@ bool RedundantPointerOps::VisitUnaryOperator(UnaryOperator const * unaryOperator if (innerOp && innerOp->getOpcode() == UO_AddrOf) report( DiagnosticsEngine::Warning, "'&' followed by '*' operating on %0, rather use '.'", - compat::getBeginLoc(unaryOperator)) + unaryOperator->getBeginLoc()) << innerOp->getSubExpr()->getType() << unaryOperator->getSourceRange(); if (auto cxxMemberCallExpr = dyn_cast<CXXMemberCallExpr>(subExpr)) { @@ -152,7 +151,7 @@ bool RedundantPointerOps::VisitUnaryOperator(UnaryOperator const * unaryOperator report( DiagnosticsEngine::Warning, "'*' followed by '.get()' operating on %0, just use '*'", - compat::getBeginLoc(unaryOperator)) + unaryOperator->getBeginLoc()) << e->IgnoreImpCasts()->getType().getLocalUnqualifiedType() << unaryOperator->getSourceRange(); } diff --git a/compilerplugins/clang/redundantstatic.cxx b/compilerplugins/clang/redundantstatic.cxx index 95a3c85c9d17..40f6ab45f132 100644 --- a/compilerplugins/clang/redundantstatic.cxx +++ b/compilerplugins/clang/redundantstatic.cxx @@ -8,7 +8,6 @@ #ifndef LO_CLANG_SHARED_PLUGINS #include "check.hxx" -#include "compat.hxx" #include "plugin.hxx" /* @@ -42,7 +41,7 @@ class RedundantStatic return true; } if (decl->isInAnonymousNamespace()) { - auto loc = compat::getBeginLoc(decl); + auto loc = decl->getBeginLoc(); while (compiler.getSourceManager().isMacroArgExpansion(loc)) { loc = compiler.getSourceManager().getImmediateMacroCallerLoc(loc); } @@ -105,7 +104,7 @@ bool RedundantStatic::VisitFunctionDecl( const FunctionDecl* func ) { report( DiagnosticsEngine::Warning, "redundant 'static' keyword in unnamed namespace", - compat::getBeginLoc(func)); + func->getBeginLoc()); } } } diff --git a/compilerplugins/clang/refcounting.cxx b/compilerplugins/clang/refcounting.cxx index 9157a1910add..61204b67a470 100644 --- a/compilerplugins/clang/refcounting.cxx +++ b/compilerplugins/clang/refcounting.cxx @@ -12,6 +12,7 @@ #include "check.hxx" #include "plugin.hxx" +#include "config_clang.h" #include "clang/AST/CXXInheritance.h" /** @@ -406,7 +407,7 @@ bool RefCounting::visitTemporaryObjectExpr(Expr const * expr) { DiagnosticsEngine::Warning, ("Temporary object of SvRefBase subclass %0 being directly stack" " managed, should be managed via tools::SvRef"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << t.getUnqualifiedType() << expr->getSourceRange(); } else if (containsSalhelperReferenceObjectSubclass(t.getTypePtr())) { report( @@ -414,7 +415,7 @@ bool RefCounting::visitTemporaryObjectExpr(Expr const * expr) { ("Temporary object of salhelper::SimpleReferenceObject subclass %0" " being directly stack managed, should be managed via" " rtl::Reference"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << t.getUnqualifiedType() << expr->getSourceRange(); } else if (containsXInterfaceSubclass(t)) { report( @@ -422,7 +423,7 @@ bool RefCounting::visitTemporaryObjectExpr(Expr const * expr) { ("Temporary object of css::uno::XInterface subclass %0 being" " directly stack managed, should be managed via" " css::uno::Reference"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << t.getUnqualifiedType() << expr->getSourceRange(); } else if (containsOWeakObjectSubclass(t)) { report( @@ -430,7 +431,7 @@ bool RefCounting::visitTemporaryObjectExpr(Expr const * expr) { ("Temporary object of cppu::OWeakObject subclass %0 being" " directly stack managed, should be managed via" " css::uno::Reference"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << t.getUnqualifiedType() << expr->getSourceRange(); } return true; @@ -501,7 +502,7 @@ bool RefCounting::VisitCXXDeleteExpr(const CXXDeleteExpr * cxxDeleteExpr) if (ignoreLocation(cxxDeleteExpr)) return true; StringRef aFileName = getFilenameOfLocation( - compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(cxxDeleteExpr))); + compiler.getSourceManager().getSpellingLoc(cxxDeleteExpr->getBeginLoc())); if (loplugin::isSamePathname(aFileName, SRCDIR "/cppuhelper/source/weak.cxx")) return true; @@ -516,7 +517,7 @@ bool RefCounting::VisitCXXDeleteExpr(const CXXDeleteExpr * cxxDeleteExpr) report( DiagnosticsEngine::Warning, "cppu::OWeakObject subclass %0 being deleted via delete, should be managed via rtl::Reference", - compat::getBeginLoc(cxxDeleteExpr)) + cxxDeleteExpr->getBeginLoc()) << pointeeType << cxxDeleteExpr->getSourceRange(); } @@ -609,7 +610,7 @@ bool RefCounting::VisitReturnStmt(const ReturnStmt * returnStmt) { if (!returnStmt->getRetValue()) return true; - auto cxxNewExpr = dyn_cast<CXXNewExpr>(compat::IgnoreImplicit(returnStmt->getRetValue())); + auto cxxNewExpr = dyn_cast<CXXNewExpr>(returnStmt->getRetValue()->IgnoreImplicit()); if (!cxxNewExpr) return true; @@ -622,7 +623,7 @@ bool RefCounting::VisitReturnStmt(const ReturnStmt * returnStmt) { report( DiagnosticsEngine::Warning, "new object of cppu::OWeakObject subclass %0 being returned via raw pointer, should be returned by via rtl::Reference", - compat::getBeginLoc(returnStmt)) + returnStmt->getBeginLoc()) << qt << returnStmt->getSourceRange(); } @@ -679,10 +680,10 @@ bool RefCounting::VisitVarDecl(const VarDecl * varDecl) { if (varDecl->getType()->isPointerType() && varDecl->getInit()) { - auto newExpr = dyn_cast<CXXNewExpr>(compat::IgnoreImplicit(varDecl->getInit())); + auto newExpr = dyn_cast<CXXNewExpr>(varDecl->getInit()->IgnoreImplicit()); if (newExpr) { - StringRef fileName = getFilenameOfLocation(compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(varDecl))); + StringRef fileName = getFilenameOfLocation(compiler.getSourceManager().getSpellingLoc(varDecl->getBeginLoc())); if (loplugin::isSamePathname(fileName, SRCDIR "/cppuhelper/source/component_context.cxx")) return true; auto pointeeType = varDecl->getType()->getPointeeType(); @@ -697,7 +698,7 @@ bool RefCounting::VisitVarDecl(const VarDecl * varDecl) { if (isCastingReference(varDecl->getInit())) { // TODO false+ code - StringRef fileName = getFilenameOfLocation(compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(varDecl))); + StringRef fileName = getFilenameOfLocation(compiler.getSourceManager().getSpellingLoc(varDecl->getBeginLoc())); if (loplugin::isSamePathname(fileName, SRCDIR "/sw/source/core/unocore/unotbl.cxx")) return true; auto pointeeType = varDecl->getType()->getPointeeType(); @@ -720,7 +721,7 @@ bool RefCounting::VisitVarDecl(const VarDecl * varDecl) { */ bool RefCounting::isCastingReference(const Expr* expr) { - expr = compat::IgnoreImplicit(expr); + expr = expr->IgnoreImplicit(); auto castExpr = dyn_cast<CastExpr>(expr); if (!castExpr) return false; @@ -733,7 +734,7 @@ bool RefCounting::isCastingReference(const Expr* expr) if (!loplugin::TypeCheck(objectType).Class("Reference")) return false; // ignore "x.get()" where x is a var - auto obj = compat::IgnoreImplicit(memberCallExpr->getImplicitObjectArgument()); + auto obj = memberCallExpr->getImplicitObjectArgument()->IgnoreImplicit(); if (isa<DeclRefExpr>(obj) || isa<MemberExpr>(obj)) return false; // if the foo in foo().get() returns "rtl::Reference<T>&" then the variable @@ -757,11 +758,11 @@ bool RefCounting::VisitBinaryOperator(const BinaryOperator * binaryOperator) if (!binaryOperator->getLHS()->getType()->isPointerType()) return true; - auto newExpr = dyn_cast<CXXNewExpr>(compat::IgnoreImplicit(binaryOperator->getRHS())); + auto newExpr = dyn_cast<CXXNewExpr>(binaryOperator->getRHS()->IgnoreImplicit()); if (newExpr) { // deliberately does not want to keep track at the allocation site - StringRef fileName = getFilenameOfLocation(compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(binaryOperator))); + StringRef fileName = getFilenameOfLocation(compiler.getSourceManager().getSpellingLoc(binaryOperator->getBeginLoc())); if (loplugin::isSamePathname(fileName, SRCDIR "/vcl/unx/generic/dtrans/X11_selection.cxx")) return true; @@ -771,7 +772,7 @@ bool RefCounting::VisitBinaryOperator(const BinaryOperator * binaryOperator) report( DiagnosticsEngine::Warning, "cppu::OWeakObject subclass %0 being managed via raw pointer, should be managed via rtl::Reference", - compat::getBeginLoc(binaryOperator)) + binaryOperator->getBeginLoc()) << pointeeType << binaryOperator->getSourceRange(); } @@ -783,7 +784,7 @@ bool RefCounting::VisitBinaryOperator(const BinaryOperator * binaryOperator) report( DiagnosticsEngine::Warning, "cppu::OWeakObject subclass %0 being managed via raw pointer, should be managed via rtl::Reference", - compat::getBeginLoc(binaryOperator)) + binaryOperator->getBeginLoc()) << pointeeType << binaryOperator->getSourceRange(); } diff --git a/compilerplugins/clang/referencecasting.cxx b/compilerplugins/clang/referencecasting.cxx index 496654237b7d..08895f723920 100644 --- a/compilerplugins/clang/referencecasting.cxx +++ b/compilerplugins/clang/referencecasting.cxx @@ -10,9 +10,9 @@ */ #ifndef LO_CLANG_SHARED_PLUGINS -#include "compat.hxx" #include "plugin.hxx" #include "check.hxx" +#include "config_clang.h" #include <iostream> /* @@ -78,7 +78,7 @@ bool ReferenceCasting::VisitInitListExpr(const InitListExpr* ile) { if (CheckForUnnecessaryGet(expr, /*includeRtlReference*/ true)) { - report(DiagnosticsEngine::Warning, "unnecessary get() call", compat::getBeginLoc(expr)) + report(DiagnosticsEngine::Warning, "unnecessary get() call", expr->getBeginLoc()) << expr->getSourceRange(); return true; } @@ -90,8 +90,8 @@ bool ReferenceCasting::VisitCXXConstructExpr(const CXXConstructExpr* cce) if (ignoreLocation(cce)) return true; // don't bother processing anything in the Reference.h file. Makes my life easier when debugging this. - StringRef aFileName = getFilenameOfLocation( - compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(cce))); + StringRef aFileName + = getFilenameOfLocation(compiler.getSourceManager().getSpellingLoc(cce->getBeginLoc())); if (loplugin::isSamePathname(aFileName, SRCDIR "/include/com/sun/star/uno/Reference.h")) return true; if (loplugin::isSamePathname(aFileName, SRCDIR "/include/com/sun/star/uno/Reference.hxx")) @@ -112,7 +112,7 @@ bool ReferenceCasting::VisitCXXConstructExpr(const CXXConstructExpr* cce) if (CheckForUnnecessaryGet(cce->getArg(0), /*includeRtlReference*/ cce->getNumArgs() == 1)) { report(DiagnosticsEngine::Warning, "unnecessary get() call", - compat::getBeginLoc(cce->getArg(0))) + cce->getArg(0)->getBeginLoc()) << cce->getArg(0)->getSourceRange(); return true; } @@ -120,7 +120,7 @@ bool ReferenceCasting::VisitCXXConstructExpr(const CXXConstructExpr* cce) if (CheckForUnnecessaryGet(cce->getArg(0), /*includeRtlReference*/ true)) { report(DiagnosticsEngine::Warning, "unnecessary get() call", - compat::getBeginLoc(cce->getArg(0))) + cce->getArg(0)->getBeginLoc()) << cce->getArg(0)->getSourceRange(); return true; } @@ -156,7 +156,7 @@ bool ReferenceCasting::VisitCXXConstructExpr(const CXXConstructExpr* cce) } if (auto matTempExpr = dyn_cast<MaterializeTemporaryExpr>(constructorArg0)) { - constructorArg0 = compat::getSubExpr(matTempExpr); + constructorArg0 = matTempExpr->getSubExpr(); continue; } if (auto bindTempExpr = dyn_cast<CXXBindTemporaryExpr>(constructorArg0)) @@ -215,7 +215,7 @@ bool ReferenceCasting::VisitCXXConstructExpr(const CXXConstructExpr* cce) { report(DiagnosticsEngine::Warning, "the source reference is already a subtype of the destination reference, just use =", - compat::getBeginLoc(cce)) + cce->getBeginLoc()) << cce->getSourceRange(); } return true; @@ -226,8 +226,8 @@ bool ReferenceCasting::VisitCXXMemberCallExpr(const CXXMemberCallExpr* mce) if (ignoreLocation(mce)) return true; // don't bother processing anything in the Reference.h file. Makes my life easier when debugging this. - StringRef aFileName = getFilenameOfLocation( - compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(mce))); + StringRef aFileName + = getFilenameOfLocation(compiler.getSourceManager().getSpellingLoc(mce->getBeginLoc())); if (loplugin::isSamePathname(aFileName, SRCDIR "/include/com/sun/star/uno/Reference.h")) return true; if (loplugin::isSamePathname(aFileName, SRCDIR "/include/com/sun/star/uno/Reference.hxx")) @@ -248,8 +248,7 @@ bool ReferenceCasting::VisitCXXMemberCallExpr(const CXXMemberCallExpr* mce) if (CheckForUnnecessaryGet(mce->getArg(0), /*includeRtlReference*/ mce->getNumArgs() == 1)) { - report(DiagnosticsEngine::Warning, "unnecessary get() call", - compat::getBeginLoc(mce->getArg(0))) + report(DiagnosticsEngine::Warning, "unnecessary get() call", mce->getArg(0)->getBeginLoc()) << mce->getArg(0)->getSourceRange(); return true; } @@ -279,7 +278,7 @@ bool ReferenceCasting::VisitCXXMemberCallExpr(const CXXMemberCallExpr* mce) } if (auto matTempExpr = dyn_cast<MaterializeTemporaryExpr>(arg0)) { - arg0 = compat::getSubExpr(matTempExpr); + arg0 = matTempExpr->getSubExpr(); continue; } if (auto bindTempExpr = dyn_cast<CXXBindTemporaryExpr>(arg0)) @@ -337,7 +336,7 @@ bool ReferenceCasting::VisitCXXMemberCallExpr(const CXXMemberCallExpr* mce) { report(DiagnosticsEngine::Warning, "the source reference is already a subtype of the destination reference, just use =", - compat::getBeginLoc(mce)) + mce->getBeginLoc()) << mce->getSourceRange(); } return true; @@ -348,8 +347,8 @@ bool ReferenceCasting::VisitCallExpr(const CallExpr* ce) if (ignoreLocation(ce)) return true; // don't bother processing anything in the Reference.h file. Makes my life easier when debugging this. - StringRef aFileName = getFilenameOfLocation( - compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(ce))); + StringRef aFileName + = getFilenameOfLocation(compiler.getSourceManager().getSpellingLoc(ce->getBeginLoc())); if (loplugin::isSamePathname(aFileName, SRCDIR "/include/com/sun/star/uno/Reference.h")) return true; if (loplugin::isSamePathname(aFileName, SRCDIR "/include/com/sun/star/uno/Reference.hxx")) @@ -368,8 +367,7 @@ bool ReferenceCasting::VisitCallExpr(const CallExpr* ce) return true; if (CheckForUnnecessaryGet(ce->getArg(0), /*includeRtlReference*/ true)) - report(DiagnosticsEngine::Warning, "unnecessary get() call", - compat::getBeginLoc(ce->getArg(0))) + report(DiagnosticsEngine::Warning, "unnecessary get() call", ce->getArg(0)->getBeginLoc()) << ce->getArg(0)->getSourceRange(); // extract the type parameter passed to the template @@ -394,7 +392,7 @@ bool ReferenceCasting::VisitCallExpr(const CallExpr* ce) } if (auto matTempExpr = dyn_cast<MaterializeTemporaryExpr>(arg0)) { - arg0 = compat::getSubExpr(matTempExpr); + arg0 = matTempExpr->getSubExpr(); continue; } if (auto bindTempExpr = dyn_cast<CXXBindTemporaryExpr>(arg0)) @@ -437,7 +435,7 @@ bool ReferenceCasting::VisitCallExpr(const CallExpr* ce) { report(DiagnosticsEngine::Warning, "the source reference is already a subtype of the destination reference, just use =", - compat::getBeginLoc(ce)) + ce->getBeginLoc()) << ce->getSourceRange(); } return true; @@ -450,7 +448,7 @@ bool ReferenceCasting::VisitCallExpr(const CallExpr* ce) */ bool ReferenceCasting::CheckForUnnecessaryGet(const Expr* expr, bool includeRtlReference) { - expr = compat::IgnoreImplicit(expr); + expr = expr->IgnoreImplicit(); auto cxxMemberCallExpr = dyn_cast<CXXMemberCallExpr>(expr); if (!cxxMemberCallExpr) return false; @@ -470,8 +468,8 @@ bool ReferenceCasting::CheckForUnnecessaryGet(const Expr* expr, bool includeRtlR else return false; - StringRef aFileName = getFilenameOfLocation( - compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(expr))); + StringRef aFileName + = getFilenameOfLocation(compiler.getSourceManager().getSpellingLoc(expr->getBeginLoc())); if (loplugin::isSamePathname(aFileName, SRCDIR "/cppu/qa/test_reference.cxx")) return false; diff --git a/compilerplugins/clang/rendercontext.cxx b/compilerplugins/clang/rendercontext.cxx index 8a4e8bd69a9c..2508b449e8eb 100644 --- a/compilerplugins/clang/rendercontext.cxx +++ b/compilerplugins/clang/rendercontext.cxx @@ -121,7 +121,7 @@ bool RenderContext::VisitCXXMemberCallExpr(const CXXMemberCallExpr* pCXXMemberCa report( DiagnosticsEngine::Warning, "Should be calling OutputDevice method through RenderContext.", - compat::getBeginLoc(pCXXMemberCallExpr)) + pCXXMemberCallExpr->getBeginLoc()) << pCXXMemberCallExpr->getSourceRange(); return true; } diff --git a/compilerplugins/clang/reservedid.cxx b/compilerplugins/clang/reservedid.cxx index 2a52e5629b2c..a5790849f02b 100644 --- a/compilerplugins/clang/reservedid.cxx +++ b/compilerplugins/clang/reservedid.cxx @@ -17,6 +17,8 @@ #include "clang/AST/Attr.h" +#include "config_clang.h" + #include "plugin.hxx" namespace { diff --git a/compilerplugins/clang/returnconstant.cxx b/compilerplugins/clang/returnconstant.cxx index 1f50aee860f9..530044c9609d 100644 --- a/compilerplugins/clang/returnconstant.cxx +++ b/compilerplugins/clang/returnconstant.cxx @@ -44,11 +44,11 @@ public: continue; report(DiagnosticsEngine::Warning, "Method only returns a single constant value %0, does it make sense?", - compat::getBeginLoc(functionDecl)) + functionDecl->getBeginLoc()) << pair.second << functionDecl->getSourceRange(); if (functionDecl != functionDecl->getCanonicalDecl()) report(DiagnosticsEngine::Note, "decl here", - compat::getBeginLoc(functionDecl->getCanonicalDecl())) + functionDecl->getCanonicalDecl()->getBeginLoc()) << functionDecl->getCanonicalDecl()->getSourceRange(); } } @@ -118,12 +118,11 @@ bool ReturnConstant::TraverseCXXMethodDecl(CXXMethodDecl* functionDecl) return true; // ignore LINK macro stuff - if (compiler.getSourceManager().isMacroBodyExpansion(compat::getBeginLoc(functionDecl)) - || compiler.getSourceManager().isMacroArgExpansion(compat::getBeginLoc(functionDecl))) + if (compiler.getSourceManager().isMacroBodyExpansion(functionDecl->getBeginLoc()) + || compiler.getSourceManager().isMacroArgExpansion(functionDecl->getBeginLoc())) { - StringRef name{ Lexer::getImmediateMacroName(compat::getBeginLoc(functionDecl), - compiler.getSourceManager(), - compiler.getLangOpts()) }; + StringRef name{ Lexer::getImmediateMacroName( + functionDecl->getBeginLoc(), compiler.getSourceManager(), compiler.getLangOpts()) }; if (name.find("IMPL_LINK") != StringRef::npos || name.find("IMPL_STATIC_LINK") != StringRef::npos || name.find("DECL_LINK") != StringRef::npos diff --git a/compilerplugins/clang/salcall.cxx b/compilerplugins/clang/salcall.cxx index a3f5678a3918..d2b4fc2bfb2b 100644 --- a/compilerplugins/clang/salcall.cxx +++ b/compilerplugins/clang/salcall.cxx @@ -323,7 +323,7 @@ bool SalCall::isSalCallFunction(FunctionDecl const* functionDecl, SourceLocation // qualified names this will point after the qualifiers, but needlessly including those in // the search should be harmless---modulo issues with using "SAL_CALL" as the name of a // function-like macro parameter as discussed below): - endLoc = compat::getBeginLoc(functionDecl->getNameInfo()); + endLoc = functionDecl->getNameInfo().getBeginLoc(); while (SM.isMacroArgExpansion(endLoc, &endLoc)) { } @@ -391,7 +391,7 @@ bool SalCall::isSalCallFunction(FunctionDecl const* functionDecl, SourceLocation endLoc1 = Lexer::getLocForEndOfToken(endLoc1, 0, SM, compiler.getLangOpts()); startLoc = Lexer::getLocForEndOfToken(SM.getSpellingLoc(startLoc), 0, SM, compiler.getLangOpts()); - if (!compat::isPointWithin(SM, endLoc, startLoc, endLoc1)) + if (!SM.isPointWithin(endLoc, startLoc, endLoc1)) { ranges.emplace_back(startLoc, endLoc1); startLoc = Lexer::getLocForEndOfToken(SM.getSpellingLoc(startLoc2), 0, SM, @@ -404,7 +404,7 @@ bool SalCall::isSalCallFunction(FunctionDecl const* functionDecl, SourceLocation // Stop searching for "SAL_CALL" at the start of the function declaration's name (for // qualified names this will point after the qualifiers, but needlessly including those in // the search should be harmless): - endLoc = compat::getBeginLoc(functionDecl->getNameInfo()); + endLoc = functionDecl->getNameInfo().getBeginLoc(); while (endLoc.isMacroID() && SM.isAtStartOfImmediateMacroExpansion(endLoc, &endLoc)) { } @@ -447,8 +447,8 @@ bool SalCall::isSalCallFunction(FunctionDecl const* functionDecl, SourceLocation startLoc = functionDecl->getSourceRange().getBegin(); while (startLoc.isMacroID() && !(macroRange.isValid() - && compat::isPointWithin(SM, SM.getSpellingLoc(startLoc), macroRange.getBegin(), - macroRange.getEnd())) + && SM.isPointWithin(SM.getSpellingLoc(startLoc), macroRange.getBegin(), + macroRange.getEnd())) && SM.isAtStartOfImmediateMacroExpansion(startLoc, &startLoc)) { } @@ -459,7 +459,7 @@ bool SalCall::isSalCallFunction(FunctionDecl const* functionDecl, SourceLocation #if defined _WIN32 if (macroRange.isValid() - && !compat::isPointWithin(SM, startLoc, macroRange.getBegin(), macroRange.getEnd())) + && !SM.isPointWithin(startLoc, macroRange.getBegin(), macroRange.getEnd())) { // endLoc is within a macro body but startLoc is not; two source ranges, first is from // startLoc to the macro invocation, second is the leading part of the corresponding @@ -477,9 +477,11 @@ bool SalCall::isSalCallFunction(FunctionDecl const* functionDecl, SourceLocation if (noReturnType && !(functionDecl->isVirtualAsWritten() || (isa<CXXConstructorDecl>(functionDecl) - && compat::isExplicitSpecified(cast<CXXConstructorDecl>(functionDecl))) + && cast<CXXConstructorDecl>(functionDecl)->getExplicitSpecifier().isExplicit()) || (isa<CXXConversionDecl>(functionDecl) - && compat::isExplicitSpecified(cast<CXXConversionDecl>(functionDecl))))) + && cast<CXXConversionDecl>(functionDecl) + ->getExplicitSpecifier() + .isExplicit()))) { SourceLocation endLoc1; if (macroStartLoc.isMacroID() diff --git a/compilerplugins/clang/sallogareas.cxx b/compilerplugins/clang/sallogareas.cxx index bb256c6d7431..bd71128aa17c 100644 --- a/compilerplugins/clang/sallogareas.cxx +++ b/compilerplugins/clang/sallogareas.cxx @@ -109,7 +109,7 @@ bool SalLogAreas::VisitCallExpr( const CallExpr* call ) // from the same macro should be the same). if( kind == LogCallKind::Sal ) { - SourceLocation expansionLocation = compiler.getSourceManager().getExpansionLoc( compat::getBeginLoc(call)); + SourceLocation expansionLocation = compiler.getSourceManager().getExpansionLoc( call->getBeginLoc()); if( expansionLocation == lastSalDetailLogStreamMacro ) return true; lastSalDetailLogStreamMacro = expansionLocation; @@ -120,7 +120,7 @@ bool SalLogAreas::VisitCallExpr( const CallExpr* call ) checkArea( area->getBytes(), area->getExprLoc()); else report( DiagnosticsEngine::Warning, "unsupported string literal kind (plugin needs fixing?)", - compat::getBeginLoc(area)); + area->getBeginLoc()); return true; } if( loplugin::DeclCheck(inFunction).Function("log").Namespace("detail").Namespace("sal").GlobalNamespace() @@ -132,7 +132,7 @@ bool SalLogAreas::VisitCallExpr( const CallExpr* call ) Expr::NPC_ValueDependentIsNotNull ) != Expr::NPCK_NotNull ) { // If the area argument is a null pointer, that is allowed only for SAL_DEBUG. const SourceManager& source = compiler.getSourceManager(); - for( SourceLocation loc = compat::getBeginLoc(call); + for( SourceLocation loc = call->getBeginLoc(); loc.isMacroID(); loc = compat::getImmediateExpansionRange(source, loc ).first ) { @@ -141,11 +141,11 @@ bool SalLogAreas::VisitCallExpr( const CallExpr* call ) return true; // ok } report( DiagnosticsEngine::Warning, "missing log area", - compat::getBeginLoc(call->getArg( 1 )->IgnoreParenImpCasts())); + call->getArg( 1 )->IgnoreParenImpCasts()->getBeginLoc()); return true; } report( DiagnosticsEngine::Warning, "cannot analyse log area argument (plugin needs fixing?)", - compat::getBeginLoc(call)); + call->getBeginLoc()); return true; } diff --git a/compilerplugins/clang/salunicodeliteral.cxx b/compilerplugins/clang/salunicodeliteral.cxx index 4c2a00669ab0..aa0a3950c8fa 100644 --- a/compilerplugins/clang/salunicodeliteral.cxx +++ b/compilerplugins/clang/salunicodeliteral.cxx @@ -74,7 +74,7 @@ private: t = tt->desugar(); } auto const e1 = expr->getSubExprAsWritten(); - auto const loc = compat::getBeginLoc(e1); + auto const loc = e1->getBeginLoc(); if (loc.isMacroID() && compiler.getSourceManager().isAtStartOfImmediateMacroExpansion( loc)) diff --git a/compilerplugins/clang/sequentialassign.cxx b/compilerplugins/clang/sequentialassign.cxx index a89afea43438..01172df17eb1 100644 --- a/compilerplugins/clang/sequentialassign.cxx +++ b/compilerplugins/clang/sequentialassign.cxx @@ -15,6 +15,7 @@ #include "plugin.hxx" #include "check.hxx" +#include "config_clang.h" #include "clang/AST/CXXInheritance.h" #include "clang/AST/StmtVisitor.h" @@ -205,8 +206,7 @@ void SequentialAssign::checkForSecondAssign(Stmt const* stmt, VarDecl const* var if (declRefExprLHS->getDecl() == varDecl) { report(DiagnosticsEngine::Warning, - "simplify by merging with the preceding assignment", - compat::getBeginLoc(stmt)) + "simplify by merging with the preceding assignment", stmt->getBeginLoc()) << stmt->getSourceRange(); } } @@ -221,8 +221,7 @@ void SequentialAssign::checkForSecondAssign(Stmt const* stmt, VarDecl const* var if (declRefExpr->getDecl() == varDecl) { report(DiagnosticsEngine::Warning, - "simplify by merging with the preceding assignment", - compat::getBeginLoc(stmt)) + "simplify by merging with the preceding assignment", stmt->getBeginLoc()) << stmt->getSourceRange(); } } diff --git a/compilerplugins/clang/sfxpoolitem.cxx b/compilerplugins/clang/sfxpoolitem.cxx index 31d7dbc13c24..801689f0f3de 100644 --- a/compilerplugins/clang/sfxpoolitem.cxx +++ b/compilerplugins/clang/sfxpoolitem.cxx @@ -119,7 +119,7 @@ bool SfxPoolItem::VisitCXXRecordDecl(const CXXRecordDecl* decl) report( DiagnosticsEngine::Warning, "SfxPoolItem subclass %0 declares new fields, but does not override operator==", - compat::getBeginLoc(decl)) + decl->getBeginLoc()) << decl->getQualifiedNameAsString() << decl->getSourceRange(); return true; } diff --git a/compilerplugins/clang/sharedvisitor/analyzer.cxx b/compilerplugins/clang/sharedvisitor/analyzer.cxx index 381bd03759ed..a000bd249ffa 100644 --- a/compilerplugins/clang/sharedvisitor/analyzer.cxx +++ b/compilerplugins/clang/sharedvisitor/analyzer.cxx @@ -283,11 +283,7 @@ int main(int argc, char** argv) if( contents.empty()) continue; foundSomething = false; -#if CLANG_VERSION >= 100000 if( !tooling::runToolOnCodeWithArgs( std::unique_ptr<FindNamedClassAction>(new FindNamedClassAction), contents, args, argv[ i ] )) -#else - if( !tooling::runToolOnCodeWithArgs( new FindNamedClassAction, contents, args, argv[ i ] )) -#endif { std::cerr << "Failed to analyze: " << argv[ i ] << std::endl; return 2; diff --git a/compilerplugins/clang/shouldreturnbool.cxx b/compilerplugins/clang/shouldreturnbool.cxx index 1372d8103374..bc232b472e5e 100644 --- a/compilerplugins/clang/shouldreturnbool.cxx +++ b/compilerplugins/clang/shouldreturnbool.cxx @@ -11,7 +11,10 @@ #include <set> #include <iostream> +#include "config_clang.h" + #include "check.hxx" +#include "compat.hxx" #include "plugin.hxx" #include "functionaddress.hxx" @@ -111,12 +114,12 @@ public: continue; report(DiagnosticsEngine::Warning, "only returning one or zero is an indication you want to return bool", - compat::getBeginLoc(functionDecl)) + functionDecl->getBeginLoc()) << functionDecl->getSourceRange(); if (canonicalDecl->getLocation() != functionDecl->getLocation()) { report(DiagnosticsEngine::Note, "canonical function declaration here", - compat::getBeginLoc(canonicalDecl)) + canonicalDecl->getBeginLoc()) << canonicalDecl->getSourceRange(); } } diff --git a/compilerplugins/clang/simplifyconstruct.cxx b/compilerplugins/clang/simplifyconstruct.cxx index bd8aaaf03957..d9eff0b3af89 100644 --- a/compilerplugins/clang/simplifyconstruct.cxx +++ b/compilerplugins/clang/simplifyconstruct.cxx @@ -88,12 +88,12 @@ bool SimplifyConstruct::VisitVarDecl(VarDecl const* varDecl) return true; auto init = varDecl->getInit(); - auto const e1 = compat::IgnoreImplicit(init); + auto const e1 = init->IgnoreImplicit(); if (!isa<CXXFunctionalCastExpr>(e1) && !isa<CXXTemporaryObjectExpr>(e1)) return true; // e.g. the LANGUAGE_DONTKNOW defines - if (compiler.getSourceManager().isMacroBodyExpansion(compat::getBeginLoc(init))) + if (compiler.getSourceManager().isMacroBodyExpansion(init->getBeginLoc())) return true; report(DiagnosticsEngine::Warning, "simplify", varDecl->getLocation()) diff --git a/compilerplugins/clang/simplifydynamiccast.cxx b/compilerplugins/clang/simplifydynamiccast.cxx index b1f06179ee71..ffb81658d8c8 100644 --- a/compilerplugins/clang/simplifydynamiccast.cxx +++ b/compilerplugins/clang/simplifydynamiccast.cxx @@ -14,7 +14,6 @@ #include <set> #include <clang/AST/CXXInheritance.h> -#include "compat.hxx" #include "plugin.hxx" namespace @@ -102,12 +101,10 @@ bool SimplifyDynamicCast::VisitCXXStaticCastExpr(CXXStaticCastExpr const* static return true; if (dynamicCastSubExprVec[idx] != subExprDecl->getDecl()) return true; - report(DiagnosticsEngine::Warning, "simplify, use var in if", - compat::getBeginLoc(staticCastExpr)) + report(DiagnosticsEngine::Warning, "simplify, use var in if", staticCastExpr->getBeginLoc()) << staticCastExpr->getSourceRange(); auto ifStmt = ifVec[idx]; - report(DiagnosticsEngine::Note, "if here", compat::getBeginLoc(ifStmt)) - << ifStmt->getSourceRange(); + report(DiagnosticsEngine::Note, "if here", ifStmt->getBeginLoc()) << ifStmt->getSourceRange(); return true; } diff --git a/compilerplugins/clang/simplifypointertobool.cxx b/compilerplugins/clang/simplifypointertobool.cxx index 7afa2d01ec3e..097a78e16f67 100644 --- a/compilerplugins/clang/simplifypointertobool.cxx +++ b/compilerplugins/clang/simplifypointertobool.cxx @@ -17,11 +17,8 @@ #include <clang/AST/CXXInheritance.h> -#include "config_clang.h" - #include "plugin.hxx" #include "check.hxx" -#include "compat.hxx" /** Simplify boolean expressions involving smart pointers e.g. @@ -78,10 +75,6 @@ public: return res; } -#if CLANG_VERSION < 110000 - bool TraverseUnaryLNot(UnaryOperator* expr) { return TraverseUnaryOperator(expr); } -#endif - bool PreTraverseBinaryOperator(BinaryOperator* expr) { auto const op = expr->getOpcode(); @@ -114,11 +107,6 @@ public: return res; } -#if CLANG_VERSION < 110000 - bool TraverseBinLAnd(BinaryOperator* expr) { return TraverseBinaryOperator(expr); } - bool TraverseBinLOr(BinaryOperator* expr) { return TraverseBinaryOperator(expr); } -#endif - bool PreTraverseConditionalOperator(ConditionalOperator* expr) { contextuallyConvertedExprs_.push_back(expr->getCond()->IgnoreParenImpCasts()); @@ -291,8 +279,7 @@ private: } start = start1; } - return SourceRange(start, - compiler.getSourceManager().getSpellingLoc(compat::getEndLoc(expr))); + return SourceRange(start, compiler.getSourceManager().getSpellingLoc(expr->getEndLoc())); } //TODO: There are some more places where an expression is contextually converted to bool, but @@ -379,7 +366,7 @@ bool SimplifyPointerToBool::VisitImplicitCastExpr(ImplicitCastExpr const* castEx if (rewriter) { auto const loc - = compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(memberCallExpr)); + = compiler.getSourceManager().getSpellingLoc(memberCallExpr->getBeginLoc()); auto const range = getCallSourceRange(memberCallExpr); if (loc.isValid() && range.isValid() && insertText(loc, "bool") && removeText(range)) { @@ -401,7 +388,7 @@ bool SimplifyPointerToBool::VisitImplicitCastExpr(ImplicitCastExpr const* castEx if (rewriter) { auto const loc - = compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(memberCallExpr)); + = compiler.getSourceManager().getSpellingLoc(memberCallExpr->getBeginLoc()); auto const range = getCallSourceRange(memberCallExpr); if (loc.isValid() && range.isValid() && insertText(loc, "bool(") && replaceText(range, ")")) diff --git a/compilerplugins/clang/singlevalfields.cxx b/compilerplugins/clang/singlevalfields.cxx index 3f5b00a7c66b..81fa76da885e 100644 --- a/compilerplugins/clang/singlevalfields.cxx +++ b/compilerplugins/clang/singlevalfields.cxx @@ -18,9 +18,7 @@ #include "compat.hxx" #include "plugin.hxx" -#if CLANG_VERSION >= 110000 #include "clang/AST/ParentMapContext.h" -#endif /** Look for fields that are only ever assigned a single constant value. @@ -115,11 +113,11 @@ public: else { for (const MyFieldAssignmentInfo & s : assignedSet) - if (s.fieldDecl && compiler.getSourceManager().isInMainFile(compat::getBeginLoc(s.fieldDecl))) + if (s.fieldDecl && compiler.getSourceManager().isInMainFile(s.fieldDecl->getBeginLoc())) report( DiagnosticsEngine::Warning, "assign %0", - compat::getBeginLoc(s.fieldDecl)) + s.fieldDecl->getBeginLoc()) << s.value; } } @@ -445,7 +443,7 @@ void SingleValFields::walkPotentialAssign( const DeclaratorDecl* fieldOrVarDecl, report( DiagnosticsEngine::Warning, "oh dear, what can the matter be?", - compat::getBeginLoc(memberExpr)) + memberExpr->getBeginLoc()) << memberExpr->getSourceRange(); parent->dump(); } diff --git a/compilerplugins/clang/staticaccess.cxx b/compilerplugins/clang/staticaccess.cxx index 9c1abbc5cba4..46aa033f0bf2 100644 --- a/compilerplugins/clang/staticaccess.cxx +++ b/compilerplugins/clang/staticaccess.cxx @@ -86,7 +86,7 @@ bool StaticAccess::VisitMemberExpr(MemberExpr const * expr) { DiagnosticsEngine::Warning, ("accessing %select{static class member|member enumerator}0 through" " class member access syntax, use a qualified name like '%1' instead"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << me << decl->getQualifiedNameAsString() << expr->getSourceRange(); return true; } diff --git a/compilerplugins/clang/staticconstfield.cxx b/compilerplugins/clang/staticconstfield.cxx index 455ea9bac693..74aad462fa3c 100644 --- a/compilerplugins/clang/staticconstfield.cxx +++ b/compilerplugins/clang/staticconstfield.cxx @@ -98,7 +98,7 @@ bool StaticConstField::TraverseConstructorInitializer(CXXCtorInitializer* init) bool found = false; std::string value; - auto const initexpr = compat::IgnoreImplicit(init->getInit()); + auto const initexpr = init->getInit()->IgnoreImplicit(); if (tc.Const().Class("OUString").Namespace("rtl").GlobalNamespace() || tc.Const().Class("OString").Namespace("rtl").GlobalNamespace()) { diff --git a/compilerplugins/clang/staticdynamic.cxx b/compilerplugins/clang/staticdynamic.cxx index 7f3d2bd49aed..6dc351546590 100644 --- a/compilerplugins/clang/staticdynamic.cxx +++ b/compilerplugins/clang/staticdynamic.cxx @@ -15,7 +15,8 @@ #include <map> #include <vector> -#include "compat.hxx" +#include "config_clang.h" + #include "check.hxx" #include "plugin.hxx" @@ -107,7 +108,7 @@ bool StaticDynamic::VisitCXXStaticCastExpr(CXXStaticCastExpr const* staticCastEx if (it != blockState.dynamicCastVars.end()) { StringRef fn = getFilenameOfLocation( - compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(staticCastExpr))); + compiler.getSourceManager().getSpellingLoc(staticCastExpr->getBeginLoc())); // loop if (loplugin::isSamePathname(fn, SRCDIR "/basctl/source/basicide/basobj3.cxx")) return true; @@ -117,12 +118,12 @@ bool StaticDynamic::VisitCXXStaticCastExpr(CXXStaticCastExpr const* staticCastEx return true; report(DiagnosticsEngine::Warning, "static_cast after dynamic_cast", - compat::getBeginLoc(staticCastExpr)) + staticCastExpr->getBeginLoc()) << staticCastExpr->getSourceRange(); report(DiagnosticsEngine::Note, "dynamic_cast here", it->second); return true; } - blockState.staticCastVars.insert({ { varDecl, varType }, compat::getBeginLoc(staticCastExpr) }); + blockState.staticCastVars.insert({ { varDecl, varType }, staticCastExpr->getBeginLoc() }); return true; } @@ -142,12 +143,12 @@ bool StaticDynamic::VisitCXXDynamicCastExpr(CXXDynamicCastExpr const* dynamicCas if (it != blockState.staticCastVars.end()) { report(DiagnosticsEngine::Warning, "dynamic_cast after static_cast", - compat::getBeginLoc(dynamicCastExpr)) + dynamicCastExpr->getBeginLoc()) << dynamicCastExpr->getSourceRange(); report(DiagnosticsEngine::Note, "static_cast here", it->second); return true; } - auto loc = compat::getBeginLoc(dynamicCastExpr); + auto loc = dynamicCastExpr->getBeginLoc(); if (compiler.getSourceManager().isMacroArgExpansion(loc) && (Lexer::getImmediateMacroNameForDiagnostics(loc, compiler.getSourceManager(), compiler.getLangOpts()) @@ -155,8 +156,7 @@ bool StaticDynamic::VisitCXXDynamicCastExpr(CXXDynamicCastExpr const* dynamicCas { return true; } - blockState.dynamicCastVars.insert( - { { varDecl, varType }, compat::getBeginLoc(dynamicCastExpr) }); + blockState.dynamicCastVars.insert({ { varDecl, varType }, dynamicCastExpr->getBeginLoc() }); return true; } diff --git a/compilerplugins/clang/staticmethods.cxx b/compilerplugins/clang/staticmethods.cxx index 06afc3d92584..4651a4a3d060 100644 --- a/compilerplugins/clang/staticmethods.cxx +++ b/compilerplugins/clang/staticmethods.cxx @@ -9,6 +9,8 @@ #include "clang/AST/Attr.h" +#include "config_clang.h" + #include "check.hxx" #include "plugin.hxx" @@ -91,11 +93,11 @@ bool StaticMethods::TraverseCXXMethodDecl(const CXXMethodDecl * pCXXMethodDecl) return true; } // don't mess with the backwards compatibility stuff - if (loplugin::isSamePathname(getFilename(compat::getBeginLoc(pCXXMethodDecl)), SRCDIR "/cppuhelper/source/compat.cxx")) { + if (loplugin::isSamePathname(getFilename(pCXXMethodDecl->getBeginLoc()), SRCDIR "/cppuhelper/source/compat.cxx")) { return true; } // the DDE has a dummy implementation on Linux and a real one on Windows - auto aFilename = getFilename(compat::getBeginLoc(pCXXMethodDecl->getCanonicalDecl())); + auto aFilename = getFilename(pCXXMethodDecl->getCanonicalDecl()->getBeginLoc()); if (loplugin::isSamePathname(aFilename, SRCDIR "/include/svl/svdde.hxx")) { return true; } diff --git a/compilerplugins/clang/staticvar.cxx b/compilerplugins/clang/staticvar.cxx index 10f38f5f71ea..21cbd0f08172 100644 --- a/compilerplugins/clang/staticvar.cxx +++ b/compilerplugins/clang/staticvar.cxx @@ -15,6 +15,7 @@ #include "plugin.hxx" #include "check.hxx" +#include "config_clang.h" #include "clang/AST/CXXInheritance.h" #include "clang/AST/StmtVisitor.h" diff --git a/compilerplugins/clang/store/finalprotected.cxx b/compilerplugins/clang/store/finalprotected.cxx index 41b994c049d5..c7296232a25b 100644 --- a/compilerplugins/clang/store/finalprotected.cxx +++ b/compilerplugins/clang/store/finalprotected.cxx @@ -51,7 +51,7 @@ bool FinalProtected::VisitCXXMethodDecl(CXXMethodDecl const * cxxMethodDecl) cxxMethodDecl = cxxMethodDecl->getCanonicalDecl(); report(DiagnosticsEngine::Warning, "final class should not have protected members - convert them to private", - compat::getBeginLoc(cxxMethodDecl)) + cxxMethodDecl->getBeginLoc()) << cxxMethodDecl->getSourceRange(); return true; } @@ -70,7 +70,7 @@ bool FinalProtected::VisitFieldDecl(FieldDecl const * fieldDecl) fieldDecl = fieldDecl->getCanonicalDecl(); report(DiagnosticsEngine::Warning, "final class should not have protected members - convert them to private", - compat::getBeginLoc(fieldDecl)) + fieldDecl->getBeginLoc()) << fieldDecl->getSourceRange(); return true; } diff --git a/compilerplugins/clang/store/optmove.cxx b/compilerplugins/clang/store/optmove.cxx index a4831179ed14..51b5a4b84fa1 100644 --- a/compilerplugins/clang/store/optmove.cxx +++ b/compilerplugins/clang/store/optmove.cxx @@ -99,7 +99,7 @@ bool OptMove::VisitVarDecl(const VarDecl* varDecl) auto cons = dyn_cast<CXXConstructExpr>(varDecl->getInit()); if (!cons || !cons->getConstructor()->isCopyConstructor()) return true; - auto arg1 = dyn_cast<DeclRefExpr>(compat::IgnoreImplicit(cons->getArg(0))); + auto arg1 = dyn_cast<DeclRefExpr>(cons->getArg(0)->IgnoreImplicit()); if (!arg1) return true; auto varDecl1 = dyn_cast<VarDecl>(arg1->getDecl()); @@ -120,8 +120,8 @@ bool OptMove::VisitCXXOperatorCallExpr(CXXOperatorCallExpr const* cxxOperatorCal auto op = cxxOperatorCallExpr->getOperator(); if (op != OO_Equal) return true; - auto arg0 = dyn_cast<DeclRefExpr>(compat::IgnoreImplicit(cxxOperatorCallExpr->getArg(0))); - auto arg1 = dyn_cast<DeclRefExpr>(compat::IgnoreImplicit(cxxOperatorCallExpr->getArg(1))); + auto arg0 = dyn_cast<DeclRefExpr>(cxxOperatorCallExpr->getArg(0)->IgnoreImplicit()); + auto arg1 = dyn_cast<DeclRefExpr>(cxxOperatorCallExpr->getArg(1)->IgnoreImplicit()); if (!arg0 || !arg1) return true; auto varDecl0 = dyn_cast<VarDecl>(arg0->getDecl()); diff --git a/compilerplugins/clang/store/refassign.cxx b/compilerplugins/clang/store/refassign.cxx index 27471a6ae643..6d8e28605ea5 100644 --- a/compilerplugins/clang/store/refassign.cxx +++ b/compilerplugins/clang/store/refassign.cxx @@ -17,7 +17,6 @@ #include <clang/AST/CXXInheritance.h> #include "check.hxx" -#include "compat.hxx" #include "plugin.hxx" /** @@ -120,7 +119,7 @@ bool RefAssign::VisitBinaryOperator(BinaryOperator const* binaryOp) binaryOp->dump(); report(DiagnosticsEngine::Warning, "assigning a %0 to a var of type %1 probably does not do what you think", - compat::getBeginLoc(binaryOp)) + binaryOp->getBeginLoc()) << rhsType << lhsType << binaryOp->getSourceRange(); return true; } diff --git a/compilerplugins/clang/store/simplifybool.cxx b/compilerplugins/clang/store/simplifybool.cxx index d2e53d63aae9..973ab6a7a464 100644 --- a/compilerplugins/clang/store/simplifybool.cxx +++ b/compilerplugins/clang/store/simplifybool.cxx @@ -9,7 +9,6 @@ #include <cassert> -#include "compat.hxx" #include "plugin.hxx" #include "clang/AST/CXXInheritance.h" @@ -22,7 +21,7 @@ Expr const * ignoreAllImplicit(Expr const * expr) { expr = e->getSubExpr(); } if (auto const e = dyn_cast<MaterializeTemporaryExpr>(expr)) { - expr = compat::getSubExpr(e); + expr = e->getSubExpr(); } if (auto const e = dyn_cast<CXXBindTemporaryExpr>(expr)) { expr = e->getSubExpr(); @@ -231,7 +230,7 @@ bool SimplifyBool::VisitUnaryOperator(UnaryOperator const * expr) { // Ignore macros, otherwise // OSL_ENSURE(!b, ...); // triggers. - if (compat::getBeginLoc(e).isMacroID()) + if (e->getBeginLoc().isMacroID()) return true; // double logical not of an int is an idiom to convert to bool auto const sub = ignoreAllImplicit(e); @@ -241,7 +240,7 @@ bool SimplifyBool::VisitUnaryOperator(UnaryOperator const * expr) { DiagnosticsEngine::Warning, ("double logical negation expression of the form '!!A' (with A of type" " %0) can %select{logically|literally}1 be simplified as 'A'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << sub->getType() << sub->getType()->isBooleanType() << expr->getSourceRange(); @@ -249,7 +248,6 @@ bool SimplifyBool::VisitUnaryOperator(UnaryOperator const * expr) { } auto sub = expr->getSubExpr()->IgnoreParenImpCasts(); auto reversed = false; -#if CLANG_VERSION >= 100000 if (auto const rewritten = dyn_cast<CXXRewrittenBinaryOperator>(sub)) { if (rewritten->isReversed()) { if (rewritten->getOperator() == BO_EQ) { @@ -269,12 +267,11 @@ bool SimplifyBool::VisitUnaryOperator(UnaryOperator const * expr) { } } } -#endif if (auto binaryOp = dyn_cast<BinaryOperator>(sub)) { // Ignore macros, otherwise // OSL_ENSURE(!b, ...); // triggers. - if (compat::getBeginLoc(binaryOp).isMacroID()) + if (binaryOp->getBeginLoc().isMacroID()) return true; if (binaryOp->isComparisonOp()) { @@ -288,7 +285,7 @@ bool SimplifyBool::VisitUnaryOperator(UnaryOperator const * expr) { report( DiagnosticsEngine::Warning, ("logical negation of comparison operator, can be simplified by inverting operator"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getSourceRange(); } else if (binaryOp->isLogicalOp()) @@ -308,7 +305,7 @@ bool SimplifyBool::VisitUnaryOperator(UnaryOperator const * expr) { if (binaryOp->isComparisonOp()) return expr; if (auto cxxOpCall = dyn_cast<CXXOperatorCallExpr>(expr)) - if (compat::isComparisonOp(cxxOpCall)) + if (cxxOpCall->isComparisonOp()) return expr; return (Expr const*)nullptr; }; @@ -318,7 +315,7 @@ bool SimplifyBool::VisitUnaryOperator(UnaryOperator const * expr) { report( DiagnosticsEngine::Warning, ("logical negation of logical op containing negation, can be simplified"), - compat::getBeginLoc(binaryOp)) + binaryOp->getBeginLoc()) << binaryOp->getSourceRange(); } } @@ -326,7 +323,7 @@ bool SimplifyBool::VisitUnaryOperator(UnaryOperator const * expr) { // Ignore macros, otherwise // OSL_ENSURE(!b, ...); // triggers. - if (compat::getBeginLoc(binaryOp).isMacroID()) + if (binaryOp->getBeginLoc().isMacroID()) return true; auto op = binaryOp->getOperator(); // Negating things like > and >= would probably not be wise, there is no guarantee the negation holds for operator overloaded types. @@ -352,7 +349,7 @@ bool SimplifyBool::VisitUnaryOperator(UnaryOperator const * expr) { report( DiagnosticsEngine::Warning, ("logical negation of comparison operator, can be simplified by inverting operator"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getSourceRange(); if (negOp != ASSUME_OPERATOR_EXISTS) report( @@ -405,7 +402,7 @@ bool SimplifyBool::visitBinLT(BinaryOperator const * expr) { DiagnosticsEngine::Warning, ("less-than expression of the form 'A < false' (with A of type" " %0) can logically be simplified as 'false'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getLHS()->IgnoreImpCasts()->getType() << expr->getSourceRange(); break; @@ -418,7 +415,7 @@ bool SimplifyBool::visitBinLT(BinaryOperator const * expr) { ("less-than expression of the form 'A < true' (with A" " of type %0) can %select{logically|literally}1 be" " simplified as '!A'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getLHS()->IgnoreImpCasts()->getType() << (expr->getLHS()->IgnoreImpCasts()->getType() ->isBooleanType()) @@ -429,7 +426,7 @@ bool SimplifyBool::visitBinLT(BinaryOperator const * expr) { ("less-than expression of the form '!A < true' (with A" " of type %0) can %select{logically|literally}1 be" " simplified as 'A'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << e->IgnoreImpCasts()->getType() << e->IgnoreImpCasts()->getType()->isBooleanType() << expr->getSourceRange(); @@ -445,7 +442,7 @@ bool SimplifyBool::visitBinLT(BinaryOperator const * expr) { DiagnosticsEngine::Warning, ("less-than expression of the form 'false < A' (with A of type" " %0) can %select{logically|literally}1 be simplified as 'A'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getRHS()->IgnoreImpCasts()->getType() << expr->getRHS()->IgnoreImpCasts()->getType()->isBooleanType() << expr->getSourceRange(); @@ -455,7 +452,7 @@ bool SimplifyBool::visitBinLT(BinaryOperator const * expr) { DiagnosticsEngine::Warning, ("less-than expression of the form 'false < false' can" " literally be simplified as 'false'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getSourceRange(); break; case Value::True: @@ -463,7 +460,7 @@ bool SimplifyBool::visitBinLT(BinaryOperator const * expr) { DiagnosticsEngine::Warning, ("less-than expression of the form 'false < true' can" " literally be simplified as 'true'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getSourceRange(); break; } @@ -475,7 +472,7 @@ bool SimplifyBool::visitBinLT(BinaryOperator const * expr) { DiagnosticsEngine::Warning, ("less-than expression of the form 'true < A' (with A of type" " %0) can logically be simplified as 'false'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getRHS()->IgnoreImpCasts()->getType() << expr->getSourceRange(); break; @@ -484,7 +481,7 @@ bool SimplifyBool::visitBinLT(BinaryOperator const * expr) { DiagnosticsEngine::Warning, ("less-than expression of the form 'true < false' can" " literally be simplified as 'false'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getSourceRange(); break; case Value::True: @@ -492,7 +489,7 @@ bool SimplifyBool::visitBinLT(BinaryOperator const * expr) { DiagnosticsEngine::Warning, ("less-than expression of the form 'true < true' can" " literally be simplified as 'false'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getSourceRange(); break; } @@ -523,7 +520,7 @@ bool SimplifyBool::visitBinGT(BinaryOperator const * expr) { ("greater-than expression of the form 'A > false' (with A of" " type %0) can %select{logically|literally}1 be simplified as" " 'A'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getLHS()->IgnoreImpCasts()->getType() << expr->getLHS()->IgnoreImpCasts()->getType()->isBooleanType() << expr->getSourceRange(); @@ -533,7 +530,7 @@ bool SimplifyBool::visitBinGT(BinaryOperator const * expr) { DiagnosticsEngine::Warning, ("greater-than expression of the form 'A > true' (with A of" " type %0) can logically be simplified as 'false'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getLHS()->IgnoreImpCasts()->getType() << expr->getSourceRange(); break; @@ -546,7 +543,7 @@ bool SimplifyBool::visitBinGT(BinaryOperator const * expr) { DiagnosticsEngine::Warning, ("greater-than expression of the form 'false > A' (with A of" " type %0) can logically be simplified as 'false'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getRHS()->IgnoreImpCasts()->getType() << expr->getSourceRange(); break; @@ -555,7 +552,7 @@ bool SimplifyBool::visitBinGT(BinaryOperator const * expr) { DiagnosticsEngine::Warning, ("greater-than expression of the form 'false > false' can" " literally be simplified as 'false'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getSourceRange(); break; case Value::True: @@ -563,7 +560,7 @@ bool SimplifyBool::visitBinGT(BinaryOperator const * expr) { DiagnosticsEngine::Warning, ("greater-than expression of the form 'false > true' can" " literally be simplified as 'false'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getSourceRange(); break; } @@ -579,7 +576,7 @@ bool SimplifyBool::visitBinGT(BinaryOperator const * expr) { ("greater-than expression of the form 'true > A' (with" " A of type %0) can %select{logically|literally}1 be" " simplified as '!A'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getRHS()->IgnoreImpCasts()->getType() << (expr->getRHS()->IgnoreImpCasts()->getType() ->isBooleanType()) @@ -590,7 +587,7 @@ bool SimplifyBool::visitBinGT(BinaryOperator const * expr) { ("greater-than expression of the form 'true > !A' (with" " A of type %0) can %select{logically|literally}1 be" " simplified as 'A'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << e->IgnoreImpCasts()->getType() << e->IgnoreImpCasts()->getType()->isBooleanType() << expr->getSourceRange(); @@ -602,7 +599,7 @@ bool SimplifyBool::visitBinGT(BinaryOperator const * expr) { DiagnosticsEngine::Warning, ("greater-than expression of the form 'true > false' can" " literally be simplified as 'true'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getSourceRange(); break; case Value::True: @@ -610,7 +607,7 @@ bool SimplifyBool::visitBinGT(BinaryOperator const * expr) { DiagnosticsEngine::Warning, ("greater-than expression of the form 'true > true' can" " literally be simplified as 'false'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getSourceRange(); break; } @@ -645,7 +642,7 @@ bool SimplifyBool::visitBinLE(BinaryOperator const * expr) { " false' (with A of type %0) can" " %select{logically|literally}1 be simplified as" " '!A'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getLHS()->IgnoreImpCasts()->getType() << (expr->getLHS()->IgnoreImpCasts()->getType() ->isBooleanType()) @@ -656,7 +653,7 @@ bool SimplifyBool::visitBinLE(BinaryOperator const * expr) { ("less-than-or-equal-to expression of the form '!A <=" " false' (with A of type %0) can" " %select{logically|literally}1 be simplified as 'A'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << e->IgnoreImpCasts()->getType() << e->IgnoreImpCasts()->getType()->isBooleanType() << expr->getSourceRange(); @@ -668,7 +665,7 @@ bool SimplifyBool::visitBinLE(BinaryOperator const * expr) { DiagnosticsEngine::Warning, ("less-than-or-equal-to expression of the form 'A <= true'" " (with A of type %0) can logically be simplified as 'true'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getLHS()->IgnoreImpCasts()->getType() << expr->getSourceRange(); break; @@ -681,7 +678,7 @@ bool SimplifyBool::visitBinLE(BinaryOperator const * expr) { DiagnosticsEngine::Warning, ("less-than-or-equal-to expression of the form 'false <= A'" " (with A of type %0) can logically be simplified as 'true'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getRHS()->IgnoreImpCasts()->getType() << expr->getSourceRange(); break; @@ -690,7 +687,7 @@ bool SimplifyBool::visitBinLE(BinaryOperator const * expr) { DiagnosticsEngine::Warning, ("less-than-or-equal-to expression of the form 'false <= false'" " can literally be simplified as 'true'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getSourceRange(); break; case Value::True: @@ -698,7 +695,7 @@ bool SimplifyBool::visitBinLE(BinaryOperator const * expr) { DiagnosticsEngine::Warning, ("less-than-or-equal-to expression of the form 'false <= true'" " can literally be simplified as 'true'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getSourceRange(); break; } @@ -711,7 +708,7 @@ bool SimplifyBool::visitBinLE(BinaryOperator const * expr) { ("less-than-or-equal-to expression of the form 'true <= A'" " (with A of type %0) can %select{logically|literally}1 be" " simplified as 'A'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getRHS()->IgnoreImpCasts()->getType() << expr->getRHS()->IgnoreImpCasts()->getType()->isBooleanType() << expr->getSourceRange(); @@ -721,7 +718,7 @@ bool SimplifyBool::visitBinLE(BinaryOperator const * expr) { DiagnosticsEngine::Warning, ("less-than-or-equal-to expression of the form 'true <= false'" " can literally be simplified as 'false'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getSourceRange(); break; case Value::True: @@ -729,7 +726,7 @@ bool SimplifyBool::visitBinLE(BinaryOperator const * expr) { DiagnosticsEngine::Warning, ("less-than-or-equal-to expression of the form 'true <= true'" " can literally be simplified as 'true'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getSourceRange(); break; } @@ -759,7 +756,7 @@ bool SimplifyBool::visitBinGE(BinaryOperator const * expr) { DiagnosticsEngine::Warning, ("greater-than-or-equal-to expression of the form 'A >= false'" " (with A of type %0) can logically be simplified as 'true'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getLHS()->IgnoreImpCasts()->getType() << expr->getSourceRange(); break; @@ -769,7 +766,7 @@ bool SimplifyBool::visitBinGE(BinaryOperator const * expr) { ("greater-than-or-equal-to expression of the form 'A >= true'" " (with A of type %0) can %select{logically|literally}1 be" " simplified as 'A'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getLHS()->IgnoreImpCasts()->getType() << expr->getLHS()->IgnoreImpCasts()->getType()->isBooleanType() << expr->getSourceRange(); @@ -788,7 +785,7 @@ bool SimplifyBool::visitBinGE(BinaryOperator const * expr) { " 'false >= A' (with A of type %0) can" " %select{logically|literally}1 be simplified as" " '!A'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getRHS()->IgnoreImpCasts()->getType() << (expr->getRHS()->IgnoreImpCasts()->getType() ->isBooleanType()) @@ -799,7 +796,7 @@ bool SimplifyBool::visitBinGE(BinaryOperator const * expr) { ("greater-than-or-equal-to expression of the form" " 'false >= !A' (with A of type %0) can" " %select{logically|literally}1 be simplified as 'A'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << e->IgnoreImpCasts()->getType() << e->IgnoreImpCasts()->getType()->isBooleanType() << expr->getSourceRange(); @@ -811,7 +808,7 @@ bool SimplifyBool::visitBinGE(BinaryOperator const * expr) { DiagnosticsEngine::Warning, ("greater-than-or-equal-to expression of the form 'false >=" " false' can literally be simplified as 'true'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getSourceRange(); break; case Value::True: @@ -819,7 +816,7 @@ bool SimplifyBool::visitBinGE(BinaryOperator const * expr) { DiagnosticsEngine::Warning, ("greater-than-or-equal-to expression of the form 'false >=" " true' can literally be simplified as 'false'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getSourceRange(); break; } @@ -831,7 +828,7 @@ bool SimplifyBool::visitBinGE(BinaryOperator const * expr) { DiagnosticsEngine::Warning, ("greater-than-or-equal-to expression of the form 'true >= A'" " (with A of type %0) can logically be simplified as 'true'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getRHS()->IgnoreImpCasts()->getType() << expr->getSourceRange(); break; @@ -840,7 +837,7 @@ bool SimplifyBool::visitBinGE(BinaryOperator const * expr) { DiagnosticsEngine::Warning, ("greater-than-or-equal-to expression of the form 'true >=" " false' can literally be simplified as 'true'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getSourceRange(); break; case Value::True: @@ -848,7 +845,7 @@ bool SimplifyBool::visitBinGE(BinaryOperator const * expr) { DiagnosticsEngine::Warning, ("greater-than-or-equal-to expression of the form 'true >=" " true' can literally be simplified as 'true'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getSourceRange(); break; } @@ -882,7 +879,7 @@ bool SimplifyBool::visitBinEQ(BinaryOperator const * expr) { ("equal-to expression of the form 'A == false' (with A" " of type %0) can %select{logically|literally}1 be" " simplified as '!A'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getLHS()->IgnoreImpCasts()->getType() << (expr->getLHS()->IgnoreImpCasts()->getType() ->isBooleanType()) @@ -893,7 +890,7 @@ bool SimplifyBool::visitBinEQ(BinaryOperator const * expr) { ("equal-to expression of the form '!A == false' (with A" " of type %0) can %select{logically|literally}1 be" " simplified as 'A'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << e->IgnoreImpCasts()->getType() << e->IgnoreImpCasts()->getType()->isBooleanType() << expr->getSourceRange(); @@ -905,7 +902,7 @@ bool SimplifyBool::visitBinEQ(BinaryOperator const * expr) { DiagnosticsEngine::Warning, ("equal-to expression of the form 'A == true' (with A of type" " %0) can %select{logically|literally}1 be simplified as 'A'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getLHS()->IgnoreImpCasts()->getType() << expr->getLHS()->IgnoreImpCasts()->getType()->isBooleanType() << expr->getSourceRange(); @@ -923,7 +920,7 @@ bool SimplifyBool::visitBinEQ(BinaryOperator const * expr) { ("equal-to expression of the form 'false == A' (with A" " of type %0) can %select{logically|literally}1 be" " simplified as '!A'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getRHS()->IgnoreImpCasts()->getType() << (expr->getRHS()->IgnoreImpCasts()->getType() ->isBooleanType()) @@ -934,7 +931,7 @@ bool SimplifyBool::visitBinEQ(BinaryOperator const * expr) { ("equal-to expression of the form 'false == !A' (with A" " of type %0) can %select{logically|literally}1 be" " simplified as 'A'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << e->IgnoreImpCasts()->getType() << e->IgnoreImpCasts()->getType()->isBooleanType() << expr->getSourceRange(); @@ -946,7 +943,7 @@ bool SimplifyBool::visitBinEQ(BinaryOperator const * expr) { DiagnosticsEngine::Warning, ("equal-to expression of the form 'false == false' can" " literally be simplified as 'true'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getSourceRange(); break; case Value::True: @@ -954,7 +951,7 @@ bool SimplifyBool::visitBinEQ(BinaryOperator const * expr) { DiagnosticsEngine::Warning, ("equal-to expression of the form 'false == true' can" " literally be simplified as 'false'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getSourceRange(); break; } @@ -966,7 +963,7 @@ bool SimplifyBool::visitBinEQ(BinaryOperator const * expr) { DiagnosticsEngine::Warning, ("equal-to expression of the form 'true == A' (with A of type" " %0) can %select{logically|literally}1 be simplified as 'A'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getRHS()->IgnoreImpCasts()->getType() << expr->getRHS()->IgnoreImpCasts()->getType()->isBooleanType() << expr->getSourceRange(); @@ -976,7 +973,7 @@ bool SimplifyBool::visitBinEQ(BinaryOperator const * expr) { DiagnosticsEngine::Warning, ("equal-to expression of the form 'true == false' can" " literally be simplified as 'false'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getSourceRange(); break; case Value::True: @@ -984,7 +981,7 @@ bool SimplifyBool::visitBinEQ(BinaryOperator const * expr) { DiagnosticsEngine::Warning, ("equal-to expression of the form 'true == true' can" " literally be simplified as 'true'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getSourceRange(); break; } @@ -1015,7 +1012,7 @@ bool SimplifyBool::visitBinNE(BinaryOperator const * expr) { ("not-equal-to expression of the form 'A != false' (with A of" " type %0) can %select{logically|literally}1 be simplified as" " 'A'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getLHS()->IgnoreImpCasts()->getType() << expr->getLHS()->IgnoreImpCasts()->getType()->isBooleanType() << expr->getSourceRange(); @@ -1029,7 +1026,7 @@ bool SimplifyBool::visitBinNE(BinaryOperator const * expr) { ("not-equal-to expression of the form 'A != true' (with" " A of type %0) can %select{logically|literally}1 be" " simplified as '!A'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getLHS()->IgnoreImpCasts()->getType() << (expr->getLHS()->IgnoreImpCasts()->getType() ->isBooleanType()) @@ -1040,7 +1037,7 @@ bool SimplifyBool::visitBinNE(BinaryOperator const * expr) { ("not-equal-to expression of the form '!A != true'" " (with A of type %0) can" " %select{logically|literally}1 be simplified as 'A'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << e->IgnoreImpCasts()->getType() << e->IgnoreImpCasts()->getType()->isBooleanType() << expr->getSourceRange(); @@ -1057,7 +1054,7 @@ bool SimplifyBool::visitBinNE(BinaryOperator const * expr) { ("not-equal-to expression of the form 'false != A' (with A of" " type %0) can %select{logically|literally}1 be simplified as" " 'A'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getRHS()->IgnoreImpCasts()->getType() << expr->getRHS()->IgnoreImpCasts()->getType()->isBooleanType() << expr->getSourceRange(); @@ -1067,7 +1064,7 @@ bool SimplifyBool::visitBinNE(BinaryOperator const * expr) { DiagnosticsEngine::Warning, ("not-equal-to expression of the form 'false != false' can" " literally be simplified as 'false'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getSourceRange(); break; case Value::True: @@ -1075,7 +1072,7 @@ bool SimplifyBool::visitBinNE(BinaryOperator const * expr) { DiagnosticsEngine::Warning, ("not-equal-to expression of the form 'false != true' can" " literally be simplified as 'true'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getSourceRange(); break; } @@ -1091,7 +1088,7 @@ bool SimplifyBool::visitBinNE(BinaryOperator const * expr) { ("not-equal-to expression of the form 'true != A' (with" " A of type %0) can %select{logically|literally}1 be" " simplified as '!A'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getRHS()->IgnoreImpCasts()->getType() << (expr->getRHS()->IgnoreImpCasts()->getType() ->isBooleanType()) @@ -1102,7 +1099,7 @@ bool SimplifyBool::visitBinNE(BinaryOperator const * expr) { ("not-equal-to expression of the form 'true != !A'" " (with A of type %0) can" " %select{logically|literally}1 be simplified as 'A'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << e->IgnoreImpCasts()->getType() << e->IgnoreImpCasts()->getType()->isBooleanType() << expr->getSourceRange(); @@ -1114,7 +1111,7 @@ bool SimplifyBool::visitBinNE(BinaryOperator const * expr) { DiagnosticsEngine::Warning, ("not-equal-to expression of the form 'true != false' can" " literally be simplified as 'true'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getSourceRange(); break; case Value::True: @@ -1122,7 +1119,7 @@ bool SimplifyBool::visitBinNE(BinaryOperator const * expr) { DiagnosticsEngine::Warning, ("not-equal-to expression of the form 'true != true' can" " literally be simplified as 'false'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getSourceRange(); break; } @@ -1148,7 +1145,7 @@ bool SimplifyBool::VisitConditionalOperator(ConditionalOperator const * expr) { ("conditional expression of the form 'A ? B : false' (with A of" " type %0 and B of type %1) can %select{logically|literally}2" " be simplified as 'A && B'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getCond()->IgnoreImpCasts()->getType() << expr->getTrueExpr()->IgnoreImpCasts()->getType() << ((expr->getCond()->IgnoreImpCasts()->getType() @@ -1167,7 +1164,7 @@ bool SimplifyBool::VisitConditionalOperator(ConditionalOperator const * expr) { " (with A of type %0 and B of type %1) can" " %select{logically|literally}2 be simplified as '!A" " || B'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getCond()->IgnoreImpCasts()->getType() << expr->getTrueExpr()->IgnoreImpCasts()->getType() << ((expr->getCond()->IgnoreImpCasts()->getType() @@ -1182,7 +1179,7 @@ bool SimplifyBool::VisitConditionalOperator(ConditionalOperator const * expr) { " (with A of type %0 and B of type %1) can" " %select{logically|literally}2 be simplified as 'A ||" " B'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << e->IgnoreImpCasts()->getType() << expr->getTrueExpr()->IgnoreImpCasts()->getType() << (e->IgnoreImpCasts()->getType()->isBooleanType() @@ -1206,7 +1203,7 @@ bool SimplifyBool::VisitConditionalOperator(ConditionalOperator const * expr) { " (with A of type %0 and B of type %1) can" " %select{logically|literally}2 be simplified as '!A" " && B'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getCond()->IgnoreImpCasts()->getType() << expr->getFalseExpr()->IgnoreImpCasts()->getType() << ((expr->getCond()->IgnoreImpCasts()->getType() @@ -1221,7 +1218,7 @@ bool SimplifyBool::VisitConditionalOperator(ConditionalOperator const * expr) { " (with A of type %0 and B of type %1) can" " %select{logically|literally}2 be simplified as 'A &&" " B'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << e->IgnoreImpCasts()->getType() << expr->getFalseExpr()->IgnoreImpCasts()->getType() << (e->IgnoreImpCasts()->getType()->isBooleanType() @@ -1236,7 +1233,7 @@ bool SimplifyBool::VisitConditionalOperator(ConditionalOperator const * expr) { DiagnosticsEngine::Warning, ("conditional expression of the form 'A ? false : false' (with" " A of type %0) can logically be simplified as 'false'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getCond()->IgnoreImpCasts()->getType() << expr->getSourceRange(); break; @@ -1250,7 +1247,7 @@ bool SimplifyBool::VisitConditionalOperator(ConditionalOperator const * expr) { " (with A of type %0) can" " %select{logically|literally}1 be simplified as" " '!A'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getCond()->IgnoreImpCasts()->getType() << (expr->getCond()->IgnoreImpCasts()->getType() ->isBooleanType()) @@ -1261,7 +1258,7 @@ bool SimplifyBool::VisitConditionalOperator(ConditionalOperator const * expr) { ("conditional expression of the form '!A ? false :" " true' (with A of type %0) can" " %select{logically|literally}1 be simplified as 'A'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << e->IgnoreImpCasts()->getType() << e->IgnoreImpCasts()->getType()->isBooleanType() << expr->getSourceRange(); @@ -1278,7 +1275,7 @@ bool SimplifyBool::VisitConditionalOperator(ConditionalOperator const * expr) { ("conditional expression of the form 'A ? true : B' (with A of" " type %0 and B of type %1) can %select{logically|literally}2" " be simplified as 'A || B'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getCond()->IgnoreImpCasts()->getType() << expr->getFalseExpr()->IgnoreImpCasts()->getType() << ((expr->getCond()->IgnoreImpCasts()->getType() @@ -1293,7 +1290,7 @@ bool SimplifyBool::VisitConditionalOperator(ConditionalOperator const * expr) { ("conditional expression of the form 'A ? true : false' (with A" " of type %0) can %select{logically|literally}1 be simplified" " as 'A'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getCond()->IgnoreImpCasts()->getType() << expr->getCond()->IgnoreImpCasts()->getType()->isBooleanType() << expr->getSourceRange(); @@ -1303,7 +1300,7 @@ bool SimplifyBool::VisitConditionalOperator(ConditionalOperator const * expr) { DiagnosticsEngine::Warning, ("conditional expression of the form 'A ? true : true' (with A" " of type %0) can logically be simplified as 'true'"), - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getCond()->IgnoreImpCasts()->getType() << expr->getSourceRange(); break; diff --git a/compilerplugins/clang/store/stringbuffer.cxx b/compilerplugins/clang/store/stringbuffer.cxx index 61df3069a51c..899c9b6ac2d8 100644 --- a/compilerplugins/clang/store/stringbuffer.cxx +++ b/compilerplugins/clang/store/stringbuffer.cxx @@ -9,7 +9,6 @@ #ifndef LO_CLANG_SHARED_PLUGINS #include "check.hxx" -#include "compat.hxx" #include "plugin.hxx" #include <vector> @@ -58,11 +57,11 @@ bool StringBuffer::VisitCXXMemberCallExpr(CXXMemberCallExpr const* memberCallExp auto matTemp = dyn_cast<MaterializeTemporaryExpr>(memberCallExpr->getArg(0)); if (!matTemp) return true; - if (!isa<CXXOperatorCallExpr>(compat::getSubExpr(matTemp))) + if (!isa<CXXOperatorCallExpr>(matTemp->getSubExpr())) return true; report(DiagnosticsEngine::Warning, "appending added result of OUString to OUStringBuffer, rather do .append(x).append(y)", - compat::getBeginLoc(memberCallExpr)) + memberCallExpr->getBeginLoc()) << memberCallExpr->getSourceRange(); return true; } diff --git a/compilerplugins/clang/stringadd.cxx b/compilerplugins/clang/stringadd.cxx index f10072497767..339192a78687 100644 --- a/compilerplugins/clang/stringadd.cxx +++ b/compilerplugins/clang/stringadd.cxx @@ -16,6 +16,7 @@ #include "plugin.hxx" #include "check.hxx" +#include "config_clang.h" #include "clang/AST/CXXInheritance.h" #include "clang/AST/StmtVisitor.h" @@ -216,7 +217,7 @@ bool StringAdd::checkForCompoundAssign(Stmt const* stmt1, Stmt const* stmt2, return true; } report(DiagnosticsEngine::Warning, "simplify by merging with the preceding assignment", - compat::getBeginLoc(stmt2)) + stmt2->getBeginLoc()) << stmt2->getSourceRange(); return true; } @@ -253,7 +254,7 @@ bool StringAdd::VisitCXXOperatorCallExpr(CXXOperatorCallExpr const* operatorCall ("rather use O[U]String::Concat than constructing %0 from %1 on %select{L|R}2HS of " "+ (where %select{R|L}2HS is of" " type %3)"), - compat::getBeginLoc(e)) + e->getBeginLoc()) << e->getType().getLocalUnqualifiedType() << e->getSubExprAsWritten()->getType() << arg << operatorCall->getArg(1 - arg)->IgnoreImpCasts()->getType() << e->getSourceRange(); }; @@ -306,7 +307,7 @@ bool StringAdd::VisitCXXMemberCallExpr(CXXMemberCallExpr const* methodCall) return true; report(DiagnosticsEngine::Warning, "chained append, rather use single append call and + operator", - compat::getBeginLoc(methodCall2)) + methodCall2->getBeginLoc()) << methodCall2->getSourceRange(); return true; @@ -314,7 +315,7 @@ bool StringAdd::VisitCXXMemberCallExpr(CXXMemberCallExpr const* methodCall) Expr const* StringAdd::ignore(Expr const* expr) { - return compat::IgnoreImplicit(compat::IgnoreImplicit(expr)->IgnoreParens()); + return expr->IgnoreImplicit()->IgnoreParens()->IgnoreImplicit(); } bool StringAdd::isSideEffectFree(Expr const* expr) @@ -451,7 +452,7 @@ bool StringAdd::isSideEffectFree(Expr const* expr) bool StringAdd::isCompileTimeConstant(Expr const* expr) { - expr = compat::IgnoreImplicit(expr); + expr = expr->IgnoreImplicit(); if (auto cxxConstructExpr = dyn_cast<CXXConstructExpr>(expr)) if (cxxConstructExpr->getNumArgs() > 0) expr = cxxConstructExpr->getArg(0); diff --git a/compilerplugins/clang/stringconcatauto.cxx b/compilerplugins/clang/stringconcatauto.cxx index c7460cfcc8cd..561aedec8070 100644 --- a/compilerplugins/clang/stringconcatauto.cxx +++ b/compilerplugins/clang/stringconcatauto.cxx @@ -20,6 +20,8 @@ and so their lifecycle should not extend the lifecycle of those temporaries. #ifndef LO_CLANG_SHARED_PLUGINS +#include "config_clang.h" + #include "plugin.hxx" #include "check.hxx" @@ -71,7 +73,7 @@ bool StringConcatAuto::checkDecl( const DeclaratorDecl* decl, QualType type, con if( isa< ParmVarDecl >( decl )) // parameters should be fine, temporaries should exist during the call return true; std::string fileName = getFilenameOfLocation( - compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(decl))).str(); + compiler.getSourceManager().getSpellingLoc(decl->getBeginLoc())).str(); loplugin::normalizeDotDotInFilePath(fileName); if (loplugin::isSamePathname(fileName, SRCDIR "/include/rtl/string.hxx") || loplugin::isSamePathname(fileName, SRCDIR "/include/rtl/ustring.hxx") diff --git a/compilerplugins/clang/stringconcatliterals.cxx b/compilerplugins/clang/stringconcatliterals.cxx index f82114199de8..2e89ddca66a9 100644 --- a/compilerplugins/clang/stringconcatliterals.cxx +++ b/compilerplugins/clang/stringconcatliterals.cxx @@ -9,6 +9,8 @@ #ifndef LO_CLANG_SHARED_PLUGINS +#include "config_clang.h" + #include "plugin.hxx" #include "check.hxx" @@ -83,7 +85,7 @@ bool StringConcatLiterals::VisitCallExpr(CallExpr const * expr) { SourceLocation leftLoc; auto const leftExpr = expr->getArg(0)->IgnoreParenImpCasts(); if (isStringLiteral(leftExpr)) { - leftLoc = compat::getBeginLoc(leftExpr); + leftLoc = leftExpr->getBeginLoc(); } else { CallExpr const * left = dyn_cast<CallExpr>(leftExpr); if (left == nullptr) { @@ -101,7 +103,7 @@ bool StringConcatLiterals::VisitCallExpr(CallExpr const * expr) { { return true; } - leftLoc = compat::getBeginLoc(left->getArg(1)); + leftLoc = left->getArg(1)->getBeginLoc(); } // We add an extra " " in the TOOLS_WARN_EXCEPTION macro, which triggers this plugin @@ -111,13 +113,13 @@ bool StringConcatLiterals::VisitCallExpr(CallExpr const * expr) { compiler.getSourceManager().getImmediateMacroCallerLoc( compiler.getSourceManager().getImmediateMacroCallerLoc( compiler.getSourceManager().getImmediateMacroCallerLoc( - compat::getBeginLoc(expr)))))), + expr->getBeginLoc()))))), SRCDIR "/include/tools/diagnose_ex.h")) return true; StringRef name { getFilenameOfLocation( - compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(expr))) }; + compiler.getSourceManager().getSpellingLoc(expr->getBeginLoc())) }; if (loplugin::isSamePathname( name, SRCDIR "/sal/qa/rtl/oustringbuffer/test_oustringbuffer_assign.cxx") || loplugin::isSamePathname( @@ -133,7 +135,7 @@ bool StringConcatLiterals::VisitCallExpr(CallExpr const * expr) { "replace '%0' between string literals with juxtaposition", op == nullptr ? expr->getExprLoc() : op->getOperatorLoc()) << (oo == OverloadedOperatorKind::OO_Plus ? "+" : "<<") - << SourceRange(leftLoc, compat::getEndLoc(expr->getArg(1))); + << SourceRange(leftLoc, expr->getArg(1)->getEndLoc()); return true; } diff --git a/compilerplugins/clang/stringconstant.cxx b/compilerplugins/clang/stringconstant.cxx index 5c237afa1924..80b0b13882b6 100644 --- a/compilerplugins/clang/stringconstant.cxx +++ b/compilerplugins/clang/stringconstant.cxx @@ -86,7 +86,7 @@ bool hasOverloads(FunctionDecl const * decl, unsigned arguments) { CXXConstructExpr const * lookForCXXConstructExpr(Expr const * expr) { if (auto e = dyn_cast<MaterializeTemporaryExpr>(expr)) { - expr = compat::getSubExpr(e); + expr = e->getSubExpr(); } if (auto e = dyn_cast<CXXFunctionalCastExpr>(expr)) { expr = e->getSubExpr(); @@ -118,56 +118,56 @@ public: void run() override; bool TraverseFunctionDecl(FunctionDecl * decl) { - returnTypes_.push(compat::getDeclaredReturnType(decl)); + returnTypes_.push(decl->getDeclaredReturnType()); auto const ret = RecursiveASTVisitor::TraverseFunctionDecl(decl); assert(!returnTypes_.empty()); - assert(returnTypes_.top() == compat::getDeclaredReturnType(decl)); + assert(returnTypes_.top() == decl->getDeclaredReturnType()); returnTypes_.pop(); return ret; } bool TraverseCXXDeductionGuideDecl(CXXDeductionGuideDecl * decl) { - returnTypes_.push(compat::getDeclaredReturnType(decl)); + returnTypes_.push(decl->getDeclaredReturnType()); auto const ret = RecursiveASTVisitor::TraverseCXXDeductionGuideDecl( decl); assert(!returnTypes_.empty()); - assert(returnTypes_.top() == compat::getDeclaredReturnType(decl)); + assert(returnTypes_.top() == decl->getDeclaredReturnType()); returnTypes_.pop(); return ret; } bool TraverseCXXMethodDecl(CXXMethodDecl * decl) { - returnTypes_.push(compat::getDeclaredReturnType(decl)); + returnTypes_.push(decl->getDeclaredReturnType()); auto const ret = RecursiveASTVisitor::TraverseCXXMethodDecl(decl); assert(!returnTypes_.empty()); - assert(returnTypes_.top() == compat::getDeclaredReturnType(decl)); + assert(returnTypes_.top() == decl->getDeclaredReturnType()); returnTypes_.pop(); return ret; } bool TraverseCXXConstructorDecl(CXXConstructorDecl * decl) { - returnTypes_.push(compat::getDeclaredReturnType(decl)); + returnTypes_.push(decl->getDeclaredReturnType()); auto const ret = RecursiveASTVisitor::TraverseCXXConstructorDecl(decl); assert(!returnTypes_.empty()); - assert(returnTypes_.top() == compat::getDeclaredReturnType(decl)); + assert(returnTypes_.top() == decl->getDeclaredReturnType()); returnTypes_.pop(); return ret; } bool TraverseCXXDestructorDecl(CXXDestructorDecl * decl) { - returnTypes_.push(compat::getDeclaredReturnType(decl)); + returnTypes_.push(decl->getDeclaredReturnType()); auto const ret = RecursiveASTVisitor::TraverseCXXDestructorDecl(decl); assert(!returnTypes_.empty()); - assert(returnTypes_.top() == compat::getDeclaredReturnType(decl)); + assert(returnTypes_.top() == decl->getDeclaredReturnType()); returnTypes_.pop(); return ret; } bool TraverseCXXConversionDecl(CXXConversionDecl * decl) { - returnTypes_.push(compat::getDeclaredReturnType(decl)); + returnTypes_.push(decl->getDeclaredReturnType()); auto const ret = RecursiveASTVisitor::TraverseCXXConversionDecl(decl); assert(!returnTypes_.empty()); - assert(returnTypes_.top() == compat::getDeclaredReturnType(decl)); + assert(returnTypes_.top() == decl->getDeclaredReturnType()); returnTypes_.pop(); return ret; } @@ -424,7 +424,7 @@ bool StringConstant::VisitCallExpr(CallExpr const * expr) { // u.equalsIngoreAsciiCase("foo"): auto file = getFilenameOfLocation( - compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(expr))); + compiler.getSourceManager().getSpellingLoc(expr->getBeginLoc())); if (loplugin::isSamePathname( file, SRCDIR "/sal/qa/rtl/strings/test_oustring_compare.cxx")) { @@ -442,7 +442,7 @@ bool StringConstant::VisitCallExpr(CallExpr const * expr) { // u.equalsIgnoreAsciiCaseAsciiL("foo", 3) -> // u.equalsIngoreAsciiCase("foo"): auto file = getFilenameOfLocation( - compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(expr))); + compiler.getSourceManager().getSpellingLoc(expr->getBeginLoc())); if (loplugin::isSamePathname( file, SRCDIR "/sal/qa/rtl/strings/test_oustring_compare.cxx")) { @@ -816,7 +816,7 @@ bool StringConstant::VisitCallExpr(CallExpr const * expr) { // b.append("foo", 3) -> b.append("foo"): auto file = getFilenameOfLocation( compiler.getSourceManager().getSpellingLoc( - compat::getBeginLoc(expr))); + expr->getBeginLoc())); if (loplugin::isSamePathname( file, SRCDIR "/sal/qa/OStringBuffer/rtl_OStringBuffer.cxx")) @@ -1067,7 +1067,7 @@ bool StringConstant::VisitCXXConstructExpr(CXXConstructExpr const * expr) { for (auto i(argsBeg); i != argsEnd; ++i) { Expr const * e = (*i)->IgnoreParenImpCasts(); if (isa<MaterializeTemporaryExpr>(e)) { - e = compat::getSubExpr(cast<MaterializeTemporaryExpr>(e)) + e = cast<MaterializeTemporaryExpr>(e)->getSubExpr() ->IgnoreParenImpCasts(); } if (isa<CXXFunctionalCastExpr>(e)) { @@ -1173,7 +1173,7 @@ bool StringConstant::VisitCXXConstructExpr(CXXConstructExpr const * expr) { auto file = getFilenameOfLocation( compiler.getSourceManager() .getSpellingLoc( - compat::getBeginLoc(expr))); + expr->getBeginLoc())); if (loplugin::isSamePathname( file, (SRCDIR @@ -1186,7 +1186,7 @@ bool StringConstant::VisitCXXConstructExpr(CXXConstructExpr const * expr) { return true; } } - auto loc = compat::getBeginLoc(expr->getArg(0)); + auto loc = expr->getArg(0)->getBeginLoc(); while (compiler.getSourceManager() .isMacroArgExpansion(loc)) { @@ -1314,7 +1314,7 @@ bool StringConstant::VisitReturnStmt(ReturnStmt const * stmt) { { return true; } - report(DiagnosticsEngine::Warning, "elide constructor call", compat::getBeginLoc(e1)) + report(DiagnosticsEngine::Warning, "elide constructor call", e1->getBeginLoc()) << e1->getSourceRange(); return true; } @@ -2034,7 +2034,7 @@ void StringConstant::handleStringCtor( } //TODO: cont, emb, trm if (rewriter != nullptr) { - auto loc1 = compat::getBeginLoc(e3); + auto loc1 = e3->getBeginLoc(); auto range = e3->getParenOrBraceRange(); if (loc1.isFileID() && range.getBegin().isFileID() && range.getEnd().isFileID()) diff --git a/compilerplugins/clang/stringliteraldefine.cxx b/compilerplugins/clang/stringliteraldefine.cxx index 3eef01533ef3..8d7e778051e1 100644 --- a/compilerplugins/clang/stringliteraldefine.cxx +++ b/compilerplugins/clang/stringliteraldefine.cxx @@ -16,6 +16,8 @@ #include <cassert> +#include "config_clang.h" + #include "check.hxx" #include "plugin.hxx" @@ -54,7 +56,7 @@ public: auto const e1 = dyn_cast<clang::StringLiteral>(arg0); if (!e1) return true; - auto argLoc = compat::getBeginLoc(arg0); + auto argLoc = arg0->getBeginLoc(); // check if the arg is a macro auto macroLoc = compiler.getSourceManager().getSpellingLoc(argLoc); if (argLoc == macroLoc) @@ -62,16 +64,14 @@ public: // check if it is the right kind of macro (not particularly reliable checks) if (!macroLoc.isValid() || !compiler.getSourceManager().isInMainFile(macroLoc) || compiler.getSourceManager().isInSystemHeader(macroLoc) -#if CLANG_VERSION >= 90000 || compiler.getSourceManager().isWrittenInBuiltinFile(macroLoc) || compiler.getSourceManager().isWrittenInScratchSpace(macroLoc) || compiler.getSourceManager().isWrittenInCommandLineFile(macroLoc) -#endif || isInUnoIncludeFile(macroLoc)) return true; StringRef fileName = getFilenameOfLocation(macroLoc); StringRef name{ Lexer::getImmediateMacroName( - compat::getBeginLoc(arg0), compiler.getSourceManager(), compiler.getLangOpts()) }; + arg0->getBeginLoc(), compiler.getSourceManager(), compiler.getLangOpts()) }; if (loplugin::hasPathnamePrefix(fileName, SRCDIR "/config_host/")) return true; // used in both OUString and OString context @@ -145,7 +145,7 @@ public: "%select{OStringLiteral|OUStringLiteral}1'", macroLoc) << name << (tc.Class("OString").Namespace("rtl").GlobalNamespace() ? 0 : 1); - report(DiagnosticsEngine::Note, "macro used here", compat::getBeginLoc(arg0)) + report(DiagnosticsEngine::Note, "macro used here", arg0->getBeginLoc()) << arg0->getSourceRange(); return true; } diff --git a/compilerplugins/clang/stringliteralvar.cxx b/compilerplugins/clang/stringliteralvar.cxx index f8dfe916cc5b..5ace384f1e16 100644 --- a/compilerplugins/clang/stringliteralvar.cxx +++ b/compilerplugins/clang/stringliteralvar.cxx @@ -198,7 +198,7 @@ public: d->getLocation()) << d << d->getType() << (tc.Class("OString").Namespace("rtl").GlobalNamespace() ? 0 : 1) << isAutomaticVariable(cast<VarDecl>(d)) << d->getSourceRange(); - report(DiagnosticsEngine::Note, "first assigned here", compat::getBeginLoc(expr)) + report(DiagnosticsEngine::Note, "first assigned here", expr->getBeginLoc()) << expr->getSourceRange(); return true; } diff --git a/compilerplugins/clang/stringloop.cxx b/compilerplugins/clang/stringloop.cxx index cb3ad327738f..3bae1a225b1e 100644 --- a/compilerplugins/clang/stringloop.cxx +++ b/compilerplugins/clang/stringloop.cxx @@ -9,6 +9,7 @@ #include "check.hxx" #include "plugin.hxx" +#include "config_clang.h" #include <vector> /** Look for OUString/OString being appended to inside a loop, where OUStringBuffer/OStringBuffer would be a better idea @@ -256,9 +257,9 @@ bool StringLoop::VisitCallExpr(CallExpr const* callExpr) return true; report(DiagnosticsEngine::Warning, "appending to OUString in loop, rather use OUStringBuffer", - compat::getBeginLoc(operatorCallExpr)) + operatorCallExpr->getBeginLoc()) << operatorCallExpr->getSourceRange(); - report(DiagnosticsEngine::Note, "field here", compat::getBeginLoc(fieldDecl)) + report(DiagnosticsEngine::Note, "field here", fieldDecl->getBeginLoc()) << fieldDecl->getSourceRange(); } else if (auto declRefExpr = dyn_cast<DeclRefExpr>(callExpr->getArg(0))) @@ -275,9 +276,9 @@ bool StringLoop::VisitCallExpr(CallExpr const* callExpr) return true; report(DiagnosticsEngine::Warning, "appending to OUString in loop, rather use OUStringBuffer", - compat::getBeginLoc(operatorCallExpr)) + operatorCallExpr->getBeginLoc()) << operatorCallExpr->getSourceRange(); - report(DiagnosticsEngine::Note, "var here", compat::getBeginLoc(varDecl)) + report(DiagnosticsEngine::Note, "var here", varDecl->getBeginLoc()) << varDecl->getSourceRange(); } } diff --git a/compilerplugins/clang/stringstatic.cxx b/compilerplugins/clang/stringstatic.cxx index a6b5b7d2e8fe..a0b83c465235 100644 --- a/compilerplugins/clang/stringstatic.cxx +++ b/compilerplugins/clang/stringstatic.cxx @@ -10,9 +10,10 @@ #ifndef LO_CLANG_SHARED_PLUGINS #include "check.hxx" -#include "compat.hxx" #include "plugin.hxx" +#include "config_clang.h" + #include <unordered_set> /** Look for static O*String and O*String[], they can be more efficiently declared as: @@ -109,7 +110,7 @@ bool StringStatic::VisitVarDecl(VarDecl const* varDecl) expr = castExpr->getSubExpr(); } else if (MaterializeTemporaryExpr const * materializeExpr = dyn_cast<MaterializeTemporaryExpr>(expr)) { - expr = compat::getSubExpr(materializeExpr); + expr = materializeExpr->getSubExpr(); } else if (CXXBindTemporaryExpr const * bindExpr = dyn_cast<CXXBindTemporaryExpr>(expr)) { expr = bindExpr->getSubExpr(); @@ -161,7 +162,7 @@ bool StringStatic::VisitDeclRefExpr(DeclRefExpr const * declRef) return true; // ignore globals that are used in CPPUNIT_ASSERT expressions, otherwise we can end up // trying to compare an OUStringLiteral and an OUString, and CPPUNIT can't handle that - auto loc = compat::getBeginLoc(declRef); + auto loc = declRef->getBeginLoc(); if (compiler.getSourceManager().isMacroArgExpansion(loc)) { StringRef name { Lexer::getImmediateMacroName(loc, compiler.getSourceManager(), compiler.getLangOpts()) }; diff --git a/compilerplugins/clang/stringview.cxx b/compilerplugins/clang/stringview.cxx index c81b04ebace5..1f7783a3f3b3 100644 --- a/compilerplugins/clang/stringview.cxx +++ b/compilerplugins/clang/stringview.cxx @@ -16,6 +16,7 @@ #include "plugin.hxx" #include "check.hxx" +#include "config_clang.h" #include "clang/AST/CXXInheritance.h" #include "clang/AST/StmtVisitor.h" @@ -78,7 +79,7 @@ bool StringView::VisitCXXOperatorCallExpr(CXXOperatorCallExpr const* cxxOperator handleSubExprThatCouldBeView(cxxOperatorCallExpr->getArg(0)); handleSubExprThatCouldBeView(cxxOperatorCallExpr->getArg(1)); } - if (compat::isComparisonOp(cxxOperatorCallExpr)) + if (cxxOperatorCallExpr->isComparisonOp()) { handleSubExprThatCouldBeView(cxxOperatorCallExpr->getArg(0)); handleSubExprThatCouldBeView(cxxOperatorCallExpr->getArg(1)); @@ -130,7 +131,7 @@ bool StringView::VisitImplicitCastExpr(ImplicitCastExpr const* expr) void StringView::handleSubExprThatCouldBeView(Expr const* subExpr) { - auto const e0 = compat::IgnoreImplicit(subExpr); + auto const e0 = subExpr->IgnoreImplicit(); auto const e = e0->IgnoreParens(); auto const tc = loplugin::TypeCheck(e->getType()); if (!(tc.Class("OString").Namespace("rtl").GlobalNamespace() @@ -227,8 +228,7 @@ void StringView::handleCXXConstructExpr(CXXConstructExpr const* expr) auto const arg = expr->getArg(1); if (!arg->isValueDependent()) { - if (auto const val - = compat::getIntegerConstantExpr(arg, compiler.getASTContext())) + if (auto const val = arg->getIntegerConstantExpr(compiler.getASTContext())) { if (val->getExtValue() == 1) { @@ -345,7 +345,7 @@ bool StringView::VisitCXXConstructExpr(CXXConstructExpr const* expr) { return true; } - if (!compat::CPlusPlus17(compiler.getLangOpts()) && expr->isElidable()) // external C++03 code + if (!compiler.getLangOpts().CPlusPlus17 && expr->isElidable()) // external C++03 code { return true; } diff --git a/compilerplugins/clang/stringviewparam.cxx b/compilerplugins/clang/stringviewparam.cxx index a500adf65d7c..ac33ea7c558c 100644 --- a/compilerplugins/clang/stringviewparam.cxx +++ b/compilerplugins/clang/stringviewparam.cxx @@ -11,8 +11,9 @@ #include <set> #include <vector> +#include "config_clang.h" + #include "check.hxx" -#include "compat.hxx" #include "functionaddress.hxx" #include "plugin.hxx" @@ -122,7 +123,7 @@ DeclRefExpr const* relevantImplicitCastExpr(ImplicitCastExpr const* expr) DeclRefExpr const* relevantCXXMemberCallExpr(CXXMemberCallExpr const* expr) { - StringType t = relevantStringType(compat::getObjectType(expr)); + StringType t = relevantStringType(expr->getObjectType()); if (t == StringType::None) { return nullptr; @@ -182,7 +183,7 @@ SmallVector<DeclRefExpr const*, 2> relevantCXXOperatorCallExpr(CXXOperatorCallEx } return wrap(relevantDeclRefExpr(e)); } - if (compat::isComparisonOp(expr) || (op == OO_Plus && expr->getNumArgs() == 2)) + if (expr->isComparisonOp() || (op == OO_Plus && expr->getNumArgs() == 2)) { SmallVector<DeclRefExpr const*, 2> v; if (auto const e = relevantDeclRefExpr(expr->getArg(0))) diff --git a/compilerplugins/clang/test/indentation.cxx b/compilerplugins/clang/test/indentation.cxx index 71b8c6f61e5a..1c57c6ceea98 100644 --- a/compilerplugins/clang/test/indentation.cxx +++ b/compilerplugins/clang/test/indentation.cxx @@ -7,8 +7,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "config_clang.h" - int foo(); int foo2(int); @@ -94,12 +92,10 @@ void attr() { foo(); } -#if CLANG_VERSION >= 100000 void attr_bad() { [[maybe_unused]] int i = foo(); // expected-note {{measured against this one [loplugin:indentation]}} foo(); // expected-error {{statement mis-aligned compared to neighbours [loplugin:indentation]}} } -#endif void xxx(); void test5(bool x) diff --git a/compilerplugins/clang/test/noexceptmove.cxx b/compilerplugins/clang/test/noexceptmove.cxx index fda58deae403..c0742c8284b7 100644 --- a/compilerplugins/clang/test/noexceptmove.cxx +++ b/compilerplugins/clang/test/noexceptmove.cxx @@ -6,10 +6,6 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "config_clang.h" - -// clang before V9 does not have API to report exception spec type -#if CLANG_VERSION >= 90000 namespace test1 { @@ -96,7 +92,4 @@ class Bar }; }; -#else -// expected-no-diagnostics -#endif // CLANG_VERSION /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/compilerplugins/clang/test/referencecasting.cxx b/compilerplugins/clang/test/referencecasting.cxx index 1b1e75f90cea..1f3480dbee5b 100644 --- a/compilerplugins/clang/test/referencecasting.cxx +++ b/compilerplugins/clang/test/referencecasting.cxx @@ -8,7 +8,6 @@ */ #include "sal/config.h" -#include "config_clang.h" #include "com/sun/star/uno/Sequence.hxx" #include "com/sun/star/uno/XInterface.hpp" @@ -105,16 +104,12 @@ void test(rtl::Reference<FooStream> l) css::uno::Reference<css::io::XStreamListener> a2 = l; (void)a2; } -// not should about the exact version I should use here, -// clang 7.0.1 visits the CXXConstructorExpr inside the initializer, while clang 11 does not -#if CLANG_VERSION >= 80000 css::uno::Sequence<css::uno::Reference<css::io::XStreamListener>> getContinuations() { rtl::Reference<FooStream> noel1; // expected-error@+1 {{unnecessary get() call [loplugin:referencecasting]}} return { noel1.get() }; } -#endif } namespace test8 diff --git a/compilerplugins/clang/test/unusedfields.cxx b/compilerplugins/clang/test/unusedfields.cxx index 6ff9189eab27..b545f4b1a89f 100644 --- a/compilerplugins/clang/test/unusedfields.cxx +++ b/compilerplugins/clang/test/unusedfields.cxx @@ -6,11 +6,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "config_clang.h" -// CLANG_VERSION = older versions of clang need something different in getParentFunctionDecl -// WIN32 = TODO, see corresponding TODO in compilerplugins/clang/unusedfields.cxx -#if CLANG_VERSION < 110000 || defined _WIN32 +#if defined _WIN32 // TODO, see corresponding TODO in compilerplugins/clang/unusedfields.cxx // expected-no-diagnostics #else diff --git a/compilerplugins/clang/test/unusedvarsglobal.cxx b/compilerplugins/clang/test/unusedvarsglobal.cxx index 58c18d0de84c..e7a0316d497d 100644 --- a/compilerplugins/clang/test/unusedvarsglobal.cxx +++ b/compilerplugins/clang/test/unusedvarsglobal.cxx @@ -6,11 +6,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "config_clang.h" -// CLANG_VERSION = older versions of clang need something different in getParentFunctionDecl -// WIN32 = TODO, see corresponding TODO in compilerplugins/clang/unusedfields.cxx -#if CLANG_VERSION < 110000 || defined _WIN32 +#if defined _WIN32 // TODO, see corresponding TODO in compilerplugins/clang/unusedfields.cxx // expected-no-diagnostics #else diff --git a/compilerplugins/clang/toolslong.cxx b/compilerplugins/clang/toolslong.cxx index 38beb8ed19b0..35a7223bd8f4 100644 --- a/compilerplugins/clang/toolslong.cxx +++ b/compilerplugins/clang/toolslong.cxx @@ -20,7 +20,6 @@ #include "config_clang.h" #include "check.hxx" -#include "compat.hxx" #include "plugin.hxx" namespace @@ -34,21 +33,6 @@ bool isLong(QualType type) // some parts of the STL have ::difference_type => long if (type->getAs<AutoType>() || type->getAs<DecltypeType>()) return false; -#if CLANG_VERSION < 80000 - // Prior to <https://github.com/llvm/llvm-project/commit/ - // c50240dac133451b3eae5b89cecca4c1c4af9fd4> "[AST] Get aliased type info from an aliased - // TemplateSpecialization" in Clang 8, if type is a TemplateSpecializationType on top of a - // TypedefType, the above getAs<TypedefType> returned null (as it unconditionally desugared the - // TemplateSpecializationType to the underlying canonic type, not to any aliased type), so re- - // check with the TemplateSpecializationType's aliased type: - if (auto const t = type->getAs<TemplateSpecializationType>()) - { - if (t->isTypeAlias()) - { - return isLong(t->getAliasedType()); - } - } -#endif if (type->isSpecificBuiltinType(BuiltinType::Kind::Long)) return true; auto arrayType = type->getAsArrayTypeUnsafe(); @@ -119,10 +103,9 @@ private: std::vector<std::pair<T, bool>> vec(map.begin(), map.end()); std::sort(vec.begin(), vec.end(), [&](std::pair<T, bool> const& lhs, std::pair<T, bool> const& rhs) { - return compiler.getSourceManager().getCharacterData( - compat::getBeginLoc(lhs.first)) + return compiler.getSourceManager().getCharacterData(lhs.first->getBeginLoc()) > compiler.getSourceManager().getCharacterData( - compat::getBeginLoc(rhs.first)); + rhs.first->getBeginLoc()); }); return vec; } @@ -178,7 +161,7 @@ void ToolsLong::run() for (auto const& dcl : reverseSourceOrder(varDecls_)) { auto const decl = dcl.first; - SourceLocation loc{ compat::getBeginLoc(decl) }; + SourceLocation loc{ decl->getBeginLoc() }; TypeSourceInfo* tsi = decl->getTypeSourceInfo(); if (tsi != nullptr) { @@ -216,7 +199,7 @@ void ToolsLong::run() for (auto const& dcl : reverseSourceOrder(fieldDecls_)) { auto const decl = dcl.first; - SourceLocation loc{ compat::getBeginLoc(decl) }; + SourceLocation loc{ decl->getBeginLoc() }; TypeSourceInfo* tsi = decl->getTypeSourceInfo(); if (tsi != nullptr) { @@ -254,7 +237,7 @@ void ToolsLong::run() for (auto const& dcl : reverseSourceOrder(parmVarDecls_)) { auto const decl = dcl.first; - SourceLocation loc{ compat::getBeginLoc(decl) }; + SourceLocation loc{ decl->getBeginLoc() }; TypeSourceInfo* tsi = decl->getTypeSourceInfo(); if (tsi != nullptr) { @@ -304,7 +287,7 @@ void ToolsLong::run() for (auto const& dcl : functionDecls_) { auto const decl = dcl.first; - SourceLocation loc{ compat::getBeginLoc(decl) }; + SourceLocation loc{ decl->getBeginLoc() }; SourceLocation l{ compiler.getSourceManager().getExpansionLoc(loc) }; SourceLocation end{ compiler.getSourceManager().getExpansionLoc( decl->getNameInfo().getLoc()) }; @@ -340,7 +323,7 @@ void ToolsLong::run() for (auto const& dcl : staticCasts_) { auto const expr = dcl.first; - SourceLocation loc{ compat::getBeginLoc(expr) }; + SourceLocation loc{ expr->getBeginLoc() }; TypeSourceInfo* tsi = expr->getTypeInfoAsWritten(); if (tsi != nullptr) { @@ -372,7 +355,7 @@ void ToolsLong::run() if (!rewrite(loc)) { report(DiagnosticsEngine::Warning, "CXXStaticCastExpr, suspicious cast from %0 to %1", - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getSubExpr()->IgnoreParenImpCasts()->getType() << expr->getType() << expr->getSourceRange(); } @@ -381,7 +364,7 @@ void ToolsLong::run() for (auto const& dcl : functionalCasts_) { auto const expr = dcl.first; - SourceLocation loc{ compat::getBeginLoc(expr) }; + SourceLocation loc{ expr->getBeginLoc() }; TypeSourceInfo* tsi = expr->getTypeInfoAsWritten(); if (tsi != nullptr) { @@ -413,8 +396,7 @@ void ToolsLong::run() if (!rewrite(loc)) { report(DiagnosticsEngine::Warning, - "CXXFunctionalCastExpr, suspicious cast from %0 to %1", - compat::getBeginLoc(expr)) + "CXXFunctionalCastExpr, suspicious cast from %0 to %1", expr->getBeginLoc()) << expr->getSubExpr()->IgnoreParenImpCasts()->getType() << expr->getType() << expr->getSourceRange(); } @@ -425,12 +407,12 @@ bool ToolsLong::VisitCStyleCastExpr(CStyleCastExpr* expr) { if (ignoreLocation(expr)) return true; - if (isExcludedFile(compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(expr)))) + if (isExcludedFile(compiler.getSourceManager().getSpellingLoc(expr->getBeginLoc()))) return true; auto const k = isLong(expr->getType()); if (!k) return true; - SourceLocation loc{ compat::getBeginLoc(expr) }; + SourceLocation loc{ expr->getBeginLoc() }; while (compiler.getSourceManager().isMacroArgExpansion(loc)) loc = compiler.getSourceManager().getImmediateMacroCallerLoc(loc); if (compiler.getSourceManager().isMacroBodyExpansion(loc) @@ -440,7 +422,7 @@ bool ToolsLong::VisitCStyleCastExpr(CStyleCastExpr* expr) return true; } report(DiagnosticsEngine::Warning, "CStyleCastExpr, suspicious cast from %0 to %1", - compat::getBeginLoc(expr)) + expr->getBeginLoc()) << expr->getSubExpr()->IgnoreParenImpCasts()->getType() << expr->getType() << expr->getSourceRange(); return true; @@ -450,7 +432,7 @@ bool ToolsLong::VisitCXXStaticCastExpr(CXXStaticCastExpr* expr) { if (ignoreLocation(expr)) return true; - if (isExcludedFile(compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(expr)))) + if (isExcludedFile(compiler.getSourceManager().getSpellingLoc(expr->getBeginLoc()))) return true; auto const k = isLong(expr->getType()); if (!k) @@ -463,7 +445,7 @@ bool ToolsLong::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr* expr) { if (ignoreLocation(expr)) return true; - if (isExcludedFile(compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(expr)))) + if (isExcludedFile(compiler.getSourceManager().getSpellingLoc(expr->getBeginLoc()))) return true; auto const k = isLong(expr->getType()); if (!k) diff --git a/compilerplugins/clang/typedefparam.cxx b/compilerplugins/clang/typedefparam.cxx index 7ea4df79d2af..b7e57b2a1b74 100644 --- a/compilerplugins/clang/typedefparam.cxx +++ b/compilerplugins/clang/typedefparam.cxx @@ -15,6 +15,8 @@ #include <fstream> #include <set> +#include "config_clang.h" + #include "check.hxx" #include "plugin.hxx" @@ -85,10 +87,10 @@ bool TypedefParam::VisitFunctionDecl(FunctionDecl const* functionDecl) report(DiagnosticsEngine::Warning, "function return type at definition site does not match function param at " "declaration site, %0 vs %1", - compat::getBeginLoc(functionDecl)) + functionDecl->getBeginLoc()) << functionDecl->getReturnType() << canonicalDecl->getReturnType() << functionDecl->getSourceRange(); - report(DiagnosticsEngine::Note, "declaration site here", compat::getBeginLoc(canonicalDecl)) + report(DiagnosticsEngine::Note, "declaration site here", canonicalDecl->getBeginLoc()) << canonicalDecl->getSourceRange(); } return true; @@ -105,7 +107,7 @@ bool TypedefParam::VisitCXXMethodDecl(CXXMethodDecl const* methodDecl) return true; StringRef aFileName = getFilenameOfLocation( - compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(methodDecl))); + compiler.getSourceManager().getSpellingLoc(methodDecl->getBeginLoc())); // seems to be using typedefs as a form of documentation for method params if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/sw/source/filter/ww8/ww8scan.hxx")) return true; @@ -145,11 +147,11 @@ bool TypedefParam::VisitCXXMethodDecl(CXXMethodDecl const* methodDecl) report(DiagnosticsEngine::Warning, "method return type does not match overridden method " "%0 vs %1", - compat::getBeginLoc(methodDecl)) + methodDecl->getBeginLoc()) << methodDecl->getReturnType() << superMethodDecl->getReturnType() << methodDecl->getSourceRange(); report(DiagnosticsEngine::Note, "super-class method here", - compat::getBeginLoc(superMethodDecl)) + superMethodDecl->getBeginLoc()) << superMethodDecl->getSourceRange(); } } diff --git a/compilerplugins/clang/unicodetochar.cxx b/compilerplugins/clang/unicodetochar.cxx index 3599d3081a9f..e404211ffed1 100644 --- a/compilerplugins/clang/unicodetochar.cxx +++ b/compilerplugins/clang/unicodetochar.cxx @@ -12,6 +12,7 @@ #include <stack> #include "check.hxx" +#include "compat.hxx" #include "plugin.hxx" // In C++, find implicit conversions from char16_t (aka sal_Unicode) to char. diff --git a/compilerplugins/clang/unnecessarycatchthrow.cxx b/compilerplugins/clang/unnecessarycatchthrow.cxx index 903e903823ab..0a8265b170d6 100644 --- a/compilerplugins/clang/unnecessarycatchthrow.cxx +++ b/compilerplugins/clang/unnecessarycatchthrow.cxx @@ -16,7 +16,6 @@ #include <set> #include <clang/AST/CXXInheritance.h> -#include "compat.hxx" #include "plugin.hxx" /** @@ -77,7 +76,7 @@ bool UnnecessaryCatchThrow::VisitCXXTryStmt(CXXTryStmt const * tryStmt) } report( DiagnosticsEngine::Warning, "unnecessary catch and throw", - compat::getBeginLoc(catchStmt)) + catchStmt->getBeginLoc()) << catchStmt->getSourceRange(); return true; } diff --git a/compilerplugins/clang/unnecessaryoverride.cxx b/compilerplugins/clang/unnecessaryoverride.cxx index 7e7d39a0a5d8..d3c67b492a19 100644 --- a/compilerplugins/clang/unnecessaryoverride.cxx +++ b/compilerplugins/clang/unnecessaryoverride.cxx @@ -16,6 +16,7 @@ #include <set> #include <clang/AST/CXXInheritance.h> +#include "config_clang.h" #include "plugin.hxx" #include "check.hxx" @@ -124,7 +125,7 @@ bool UnnecessaryOverride::VisitCXXMethodDecl(const CXXMethodDecl* methodDecl) } StringRef aFileName = getFilenameOfLocation( - compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(methodDecl))); + compiler.getSourceManager().getSpellingLoc(methodDecl->getBeginLoc())); if (isa<CXXDestructorDecl>(methodDecl) && !isInUnoIncludeFile(methodDecl)) @@ -371,7 +372,7 @@ bool UnnecessaryOverride::VisitCXXMethodDecl(const CXXMethodDecl* methodDecl) if (pOther) { StringRef aFileName = getFilenameOfLocation( - compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(pOther))); + compiler.getSourceManager().getSpellingLoc(pOther->getBeginLoc())); // SFX_DECL_CHILDWINDOW_WITHID macro if (loplugin::isSamePathname(aFileName, SRCDIR "/include/sfx2/childwin.hxx")) return true; diff --git a/compilerplugins/clang/unnecessaryparen.cxx b/compilerplugins/clang/unnecessaryparen.cxx index eb53c449cd77..29a790702c66 100644 --- a/compilerplugins/clang/unnecessaryparen.cxx +++ b/compilerplugins/clang/unnecessaryparen.cxx @@ -20,7 +20,6 @@ #include "config_clang.h" -#include "compat.hxx" #include "plugin.hxx" /** @@ -44,7 +43,7 @@ Expr const * ignoreAllImplicit(Expr const * expr) { } } else if (auto const e = dyn_cast<MaterializeTemporaryExpr>(expr)) { - expr = compat::getSubExpr(e); + expr = e->getSubExpr(); } else if (auto const e = dyn_cast<CXXBindTemporaryExpr>(expr)) { expr = e->getSubExpr(); @@ -57,11 +56,9 @@ Expr const * ignoreAllImplicit(Expr const * expr) { expr = ce->getImplicitObjectArgument(); } } -#if CLANG_VERSION >= 80000 else if (auto const e = dyn_cast<ConstantExpr>(expr)) { expr = e->getSubExpr(); } -#endif if (expr == oldExpr) return expr; } @@ -70,7 +67,7 @@ Expr const * ignoreAllImplicit(Expr const * expr) { bool isParenWorthyOpcode(BinaryOperatorKind op) { return !(BinaryOperator::isMultiplicativeOp(op) || BinaryOperator::isAdditiveOp(op) - || compat::isPtrMemOp(op)); + || BinaryOperator::isPtrMemOp(op)); } class UnnecessaryParen: @@ -175,7 +172,7 @@ bool UnnecessaryParen::VisitParenExpr(const ParenExpr* parenExpr) { if (ignoreLocation(parenExpr)) return true; - if (compat::getBeginLoc(parenExpr).isMacroID()) + if (parenExpr->getBeginLoc().isMacroID()) return true; if (handled_.find(parenExpr) != handled_.end()) return true; @@ -184,11 +181,11 @@ bool UnnecessaryParen::VisitParenExpr(const ParenExpr* parenExpr) if (auto subParenExpr = dyn_cast<ParenExpr>(subExpr)) { - if (compat::getBeginLoc(subParenExpr).isMacroID()) + if (subParenExpr->getBeginLoc().isMacroID()) return true; report( DiagnosticsEngine::Warning, "parentheses around parentheses", - compat::getBeginLoc(parenExpr)) + parenExpr->getBeginLoc()) << parenExpr->getSourceRange(); handled_.insert(subParenExpr); } @@ -201,7 +198,7 @@ bool UnnecessaryParen::VisitParenExpr(const ParenExpr* parenExpr) if (!isPrecededBy_BAD_CAST(parenExpr)) { report( DiagnosticsEngine::Warning, "unnecessary parentheses around identifier", - compat::getBeginLoc(parenExpr)) + parenExpr->getBeginLoc()) << parenExpr->getSourceRange(); handled_.insert(parenExpr); } @@ -210,7 +207,7 @@ bool UnnecessaryParen::VisitParenExpr(const ParenExpr* parenExpr) || isa<CXXBoolLiteralExpr>(subExpr) || isa<CXXNullPtrLiteralExpr>(subExpr) || isa<ObjCBoolLiteralExpr>(subExpr)) { - auto const loc = compat::getBeginLoc(subExpr); + auto const loc = subExpr->getBeginLoc(); if (loc.isMacroID() && compiler.getSourceManager().isAtStartOfImmediateMacroExpansion(loc)) { // just in case the macro could also expand to something that /would/ require @@ -219,7 +216,7 @@ bool UnnecessaryParen::VisitParenExpr(const ParenExpr* parenExpr) } report( DiagnosticsEngine::Warning, "unnecessary parentheses around literal", - compat::getBeginLoc(parenExpr)) + parenExpr->getBeginLoc()) << parenExpr->getSourceRange(); handled_.insert(parenExpr); } else if (auto const e = dyn_cast<clang::StringLiteral>(subExpr)) { @@ -227,7 +224,7 @@ bool UnnecessaryParen::VisitParenExpr(const ParenExpr* parenExpr) report( DiagnosticsEngine::Warning, "unnecessary parentheses around single-token string literal", - compat::getBeginLoc(parenExpr)) + parenExpr->getBeginLoc()) << parenExpr->getSourceRange(); handled_.insert(parenExpr); } @@ -239,7 +236,7 @@ bool UnnecessaryParen::VisitParenExpr(const ParenExpr* parenExpr) report( DiagnosticsEngine::Warning, "unnecessary parentheses around signed numeric literal", - compat::getBeginLoc(parenExpr)) + parenExpr->getBeginLoc()) << parenExpr->getSourceRange(); handled_.insert(parenExpr); } @@ -248,7 +245,7 @@ bool UnnecessaryParen::VisitParenExpr(const ParenExpr* parenExpr) if (!removeParens(parenExpr)) { report( DiagnosticsEngine::Warning, "unnecessary parentheses around cast", - compat::getBeginLoc(parenExpr)) + parenExpr->getBeginLoc()) << parenExpr->getSourceRange(); } handled_.insert(parenExpr); @@ -256,7 +253,7 @@ bool UnnecessaryParen::VisitParenExpr(const ParenExpr* parenExpr) if (isa<CXXThisExpr>(ignoreAllImplicit(memberExpr->getBase()))) { report( DiagnosticsEngine::Warning, "unnecessary parentheses around member expr", - compat::getBeginLoc(parenExpr)) + parenExpr->getBeginLoc()) << parenExpr->getSourceRange(); handled_.insert(parenExpr); } @@ -314,7 +311,7 @@ bool UnnecessaryParen::VisitReturnStmt(const ReturnStmt* returnStmt) auto parenExpr = dyn_cast<ParenExpr>(ignoreAllImplicit(returnStmt->getRetValue())); if (!parenExpr) return true; - if (compat::getBeginLoc(parenExpr).isMacroID()) + if (parenExpr->getBeginLoc().isMacroID()) return true; // assignments need extra parentheses or they generate a compiler warning auto binaryOp = dyn_cast<BinaryOperator>(parenExpr->getSubExpr()); @@ -327,7 +324,7 @@ bool UnnecessaryParen::VisitReturnStmt(const ReturnStmt* returnStmt) { report( DiagnosticsEngine::Warning, "parentheses immediately inside return statement", - compat::getBeginLoc(parenExpr)) + parenExpr->getBeginLoc()) << parenExpr->getSourceRange(); handled_.insert(parenExpr); } @@ -344,7 +341,7 @@ void UnnecessaryParen::VisitSomeStmt(const Stmt * stmt, const Expr* cond, String if (handled_.find(parenExpr) != handled_.end()) { return; } - if (compat::getBeginLoc(parenExpr).isMacroID()) + if (parenExpr->getBeginLoc().isMacroID()) return; // assignments need extra parentheses or they generate a compiler warning auto binaryOp = dyn_cast<BinaryOperator>(parenExpr->getSubExpr()); @@ -357,7 +354,7 @@ void UnnecessaryParen::VisitSomeStmt(const Stmt * stmt, const Expr* cond, String } report( DiagnosticsEngine::Warning, "parentheses immediately inside %0 statement", - compat::getBeginLoc(parenExpr)) + parenExpr->getBeginLoc()) << stmtName << parenExpr->getSourceRange(); handled_.insert(parenExpr); @@ -381,7 +378,7 @@ bool UnnecessaryParen::VisitCallExpr(const CallExpr* callExpr) auto parenExpr = dyn_cast<ParenExpr>(ignoreAllImplicit(callExpr->getArg(0))); if (!parenExpr) return true; - if (compat::getBeginLoc(parenExpr).isMacroID()) + if (parenExpr->getBeginLoc().isMacroID()) return true; // assignments need extra parentheses or they generate a compiler warning auto binaryOp = dyn_cast<BinaryOperator>(parenExpr->getSubExpr()); @@ -389,7 +386,7 @@ bool UnnecessaryParen::VisitCallExpr(const CallExpr* callExpr) return true; report( DiagnosticsEngine::Warning, "parentheses immediately inside single-arg call", - compat::getBeginLoc(parenExpr)) + parenExpr->getBeginLoc()) << parenExpr->getSourceRange(); handled_.insert(parenExpr); return true; @@ -403,7 +400,7 @@ bool UnnecessaryParen::VisitCXXDeleteExpr(const CXXDeleteExpr* deleteExpr) auto parenExpr = dyn_cast<ParenExpr>(ignoreAllImplicit(deleteExpr->getArgument())); if (!parenExpr) return true; - if (compat::getBeginLoc(parenExpr).isMacroID()) + if (parenExpr->getBeginLoc().isMacroID()) return true; // assignments need extra parentheses or they generate a compiler warning auto binaryOp = dyn_cast<BinaryOperator>(parenExpr->getSubExpr()); @@ -411,7 +408,7 @@ bool UnnecessaryParen::VisitCXXDeleteExpr(const CXXDeleteExpr* deleteExpr) return true; report( DiagnosticsEngine::Warning, "parentheses immediately inside delete expr", - compat::getBeginLoc(parenExpr)) + parenExpr->getBeginLoc()) << parenExpr->getSourceRange(); handled_.insert(parenExpr); return true; @@ -437,18 +434,16 @@ bool UnnecessaryParen::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr* callE auto parenExpr = dyn_cast<ParenExpr>(ignoreAllImplicit(callExpr->getArg(1))); if (!parenExpr) return true; - if (compat::getBeginLoc(parenExpr).isMacroID()) + if (parenExpr->getBeginLoc().isMacroID()) return true; // Sometimes parentheses make the RHS of an assignment easier to read by // visually disambiguating the = from a call to == auto sub = parenExpr->getSubExpr(); -#if CLANG_VERSION >= 100000 if (auto const e = dyn_cast<CXXRewrittenBinaryOperator>(sub)) { if (isParenWorthyOpcode(e->getDecomposedForm().Opcode)) { return true; } } -#endif if (auto subBinOp = dyn_cast<BinaryOperator>(sub)) { if (isParenWorthyOpcode(subBinOp->getOpcode())) @@ -465,7 +460,7 @@ bool UnnecessaryParen::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr* callE report( DiagnosticsEngine::Warning, "parentheses immediately inside assignment", - compat::getBeginLoc(parenExpr)) + parenExpr->getBeginLoc()) << parenExpr->getSourceRange(); handled_.insert(parenExpr); return true; @@ -481,17 +476,15 @@ bool UnnecessaryParen::VisitVarDecl(const VarDecl* varDecl) auto parenExpr = dyn_cast<ParenExpr>(ignoreAllImplicit(varDecl->getInit())); if (!parenExpr) return true; - if (compat::getBeginLoc(parenExpr).isMacroID()) + if (parenExpr->getBeginLoc().isMacroID()) return true; // Sometimes parentheses make the RHS of an assignment easier to read by // visually disambiguating the = from a call to == auto sub = parenExpr->getSubExpr(); -#if CLANG_VERSION >= 100000 if (auto const e = dyn_cast<CXXRewrittenBinaryOperator>(sub)) { sub = e->getDecomposedForm().InnerBinOp; } -#endif if (auto subBinOp = dyn_cast<BinaryOperator>(sub)) { if (!(subBinOp->isMultiplicativeOp() || subBinOp->isAdditiveOp() || subBinOp->isPtrMemOp())) @@ -514,7 +507,7 @@ bool UnnecessaryParen::VisitVarDecl(const VarDecl* varDecl) report( DiagnosticsEngine::Warning, "parentheses immediately inside vardecl statement", - compat::getBeginLoc(parenExpr)) + parenExpr->getBeginLoc()) << parenExpr->getSourceRange(); handled_.insert(parenExpr); return true; @@ -530,7 +523,7 @@ bool UnnecessaryParen::VisitMemberExpr(const MemberExpr* memberExpr) return true; if (handled_.find(parenExpr) != handled_.end()) return true; - if (compat::getBeginLoc(parenExpr).isMacroID()) + if (parenExpr->getBeginLoc().isMacroID()) return true; auto sub = parenExpr->getSubExpr(); @@ -548,7 +541,7 @@ bool UnnecessaryParen::VisitMemberExpr(const MemberExpr* memberExpr) report( DiagnosticsEngine::Warning, "unnecessary parentheses around member expr", - compat::getBeginLoc(parenExpr)) + parenExpr->getBeginLoc()) << parenExpr->getSourceRange(); handled_.insert(parenExpr); return true; @@ -583,12 +576,12 @@ void UnnecessaryParen::handleUnreachableCodeConditionParens(Expr const * expr) { } bool UnnecessaryParen::isPrecededBy_BAD_CAST(Expr const * expr) { - if (compat::getBeginLoc(expr).isMacroID()) { + if (expr->getBeginLoc().isMacroID()) { return false; } SourceManager& SM = compiler.getSourceManager(); - const char *p1 = SM.getCharacterData( compat::getBeginLoc(expr).getLocWithOffset(-10) ); - const char *p2 = SM.getCharacterData( compat::getBeginLoc(expr) ); + const char *p1 = SM.getCharacterData( expr->getBeginLoc().getLocWithOffset(-10) ); + const char *p2 = SM.getCharacterData( expr->getBeginLoc() ); return std::string(p1, p2 - p1).find("BAD_CAST") != std::string::npos; } @@ -617,8 +610,8 @@ bool UnnecessaryParen::removeParens(ParenExpr const * expr) { if (rewriter == nullptr) { return false; } - auto const firstBegin = compat::getBeginLoc(expr); - auto secondBegin = compat::getEndLoc(expr); + auto const firstBegin = expr->getBeginLoc(); + auto secondBegin = expr->getEndLoc(); if (firstBegin.isMacroID() || secondBegin.isMacroID()) { return false; } diff --git a/compilerplugins/clang/unnecessaryvirtual.cxx b/compilerplugins/clang/unnecessaryvirtual.cxx index 9f3a3eecf444..eb3df3b1524f 100644 --- a/compilerplugins/clang/unnecessaryvirtual.cxx +++ b/compilerplugins/clang/unnecessaryvirtual.cxx @@ -12,6 +12,7 @@ #include <iostream> #include <set> #include <unordered_set> +#include "config_clang.h" #include "plugin.hxx" #include <fstream> diff --git a/compilerplugins/clang/unoany.cxx b/compilerplugins/clang/unoany.cxx index d44fce1d434c..0ab5657c1d03 100644 --- a/compilerplugins/clang/unoany.cxx +++ b/compilerplugins/clang/unoany.cxx @@ -9,8 +9,9 @@ #ifndef LO_CLANG_SHARED_PLUGINS +#include "config_clang.h" + #include "check.hxx" -#include "compat.hxx" #include "plugin.hxx" namespace { @@ -40,7 +41,7 @@ bool UnoAny::VisitCXXOperatorCallExpr(CXXOperatorCallExpr const * expr) return true; } StringRef aFileName = getFilenameOfLocation( - compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(expr))); + compiler.getSourceManager().getSpellingLoc(expr->getBeginLoc())); if (loplugin::isSamePathname(aFileName, SRCDIR "/include/com/sun/star/uno/Any.hxx")) { return true; } @@ -53,7 +54,7 @@ bool UnoAny::VisitCXXOperatorCallExpr(CXXOperatorCallExpr const * expr) return true; } if (auto expr2 = dyn_cast<MaterializeTemporaryExpr>(expr->getArg(1))) { - if (auto expr3 = dyn_cast<CXXBindTemporaryExpr>(compat::getSubExpr(expr2))) { + if (auto expr3 = dyn_cast<CXXBindTemporaryExpr>(expr2->getSubExpr())) { if (auto expr4 = dyn_cast<CallExpr>(expr3->getSubExpr())) { if (loplugin::DeclCheck(expr4->getDirectCallee()).Function("makeAny"). Namespace("uno").Namespace("star").Namespace("sun").Namespace("com").GlobalNamespace()) { @@ -67,7 +68,7 @@ bool UnoAny::VisitCXXOperatorCallExpr(CXXOperatorCallExpr const * expr) } } } - if (isa<CXXFunctionalCastExpr>(compat::getSubExpr(expr2))) { + if (isa<CXXFunctionalCastExpr>(expr2->getSubExpr())) { //expr->getArg(1)->dump(); report( DiagnosticsEngine::Warning, diff --git a/compilerplugins/clang/unoquery.cxx b/compilerplugins/clang/unoquery.cxx index fd7715fe1df3..1fe2d4b5bab4 100644 --- a/compilerplugins/clang/unoquery.cxx +++ b/compilerplugins/clang/unoquery.cxx @@ -10,7 +10,6 @@ #ifndef LO_CLANG_SHARED_PLUGINS #include "check.hxx" -#include "compat.hxx" #include "plugin.hxx" // TODO it would be better if we were running some kind of nullability analysis here, where we marked @@ -64,7 +63,7 @@ bool UnoQuery::VisitCXXMemberCallExpr(CXXMemberCallExpr const* memberCallExpr) Expr const* expr = operatorCallExpr->getArg(0)->IgnoreImplicit(); // depending on the version of clang, the IgnoreImplicit may or may not look through these nodes if (auto matTemp = dyn_cast<MaterializeTemporaryExpr>(expr)) - expr = compat::getSubExpr(matTemp); + expr = matTemp->getSubExpr(); if (auto bindTemp = dyn_cast<CXXBindTemporaryExpr>(expr)) expr = bindTemp->getSubExpr(); diff --git a/compilerplugins/clang/unsignedcompare.cxx b/compilerplugins/clang/unsignedcompare.cxx index f231db0858f4..5b55edea2843 100644 --- a/compilerplugins/clang/unsignedcompare.cxx +++ b/compilerplugins/clang/unsignedcompare.cxx @@ -15,9 +15,6 @@ #include <cassert> -#include "config_clang.h" - -#include "compat.hxx" #include "plugin.hxx" namespace @@ -128,9 +125,7 @@ public: // be, so lets keep it here at least for now): switch (expr->getOpcode()) { -#if CLANG_VERSION >= 60000 case BO_Cmp: -#endif case BO_LT: case BO_GT: case BO_LE: @@ -203,7 +198,7 @@ private: // Filter out e.g. `size_t(-1)`: if (!e2->isValueDependent()) { - if (auto const val = compat::getIntegerConstantExpr(e2, compiler.getASTContext())) + if (auto const val = e2->getIntegerConstantExpr(compiler.getASTContext())) { if (val->isNegative()) { @@ -211,7 +206,7 @@ private: } } } - auto loc = compat::getBeginLoc(e); + auto loc = e->getBeginLoc(); while (compiler.getSourceManager().isMacroArgExpansion(loc)) { loc = compiler.getSourceManager().getImmediateMacroCallerLoc(loc); diff --git a/compilerplugins/clang/unusedenumconstants.cxx b/compilerplugins/clang/unusedenumconstants.cxx index 0c56314af888..a04117343860 100644 --- a/compilerplugins/clang/unusedenumconstants.cxx +++ b/compilerplugins/clang/unusedenumconstants.cxx @@ -12,8 +12,8 @@ #include <iostream> #include <fstream> #include <set> +#include "config_clang.h" #include "plugin.hxx" -#include "compat.hxx" /** This looks for unused enum constants @@ -246,9 +246,7 @@ walk_up: || isa<ParenExpr>(parent) || isa<MaterializeTemporaryExpr>(parent) || isa<ExprWithCleanups>(parent) -#if CLANG_VERSION >= 80000 || isa<ConstantExpr>(parent) -#endif || isa<CXXBindTemporaryExpr>(parent)) { goto walk_up; @@ -284,7 +282,7 @@ walk_up: declRefExpr->dump(); report( DiagnosticsEngine::Warning, "unhandled clang AST node type", - compat::getBeginLoc(parent)); + parent->getBeginLoc()); } if (bWrite) { diff --git a/compilerplugins/clang/unusedfields.cxx b/compilerplugins/clang/unusedfields.cxx index ac260d7e82d1..24045483ffe1 100644 --- a/compilerplugins/clang/unusedfields.cxx +++ b/compilerplugins/clang/unusedfields.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: @@ -216,25 +214,25 @@ void UnusedFields::run() report( DiagnosticsEngine::Warning, "read %0", - compat::getBeginLoc(s.parentRecord)) + s.parentRecord->getBeginLoc()) << s.fieldName; for (const MyFieldInfo & s : writeToSet) report( DiagnosticsEngine::Warning, "write %0", - compat::getBeginLoc(s.parentRecord)) + s.parentRecord->getBeginLoc()) << s.fieldName; for (const MyFieldInfo & s : touchedFromOutsideConstructorSet) report( DiagnosticsEngine::Warning, "outside-constructor %0", - compat::getBeginLoc(s.parentRecord)) + s.parentRecord->getBeginLoc()) << s.fieldName; for (const MyFieldInfo & s : touchedFromOutsideSet) report( DiagnosticsEngine::Warning, "outside %0", - compat::getBeginLoc(s.parentRecord)) + s.parentRecord->getBeginLoc()) << s.fieldName; } } @@ -322,7 +320,7 @@ bool UnusedFields::checkIgnoreLocation(SourceLocation loc) bool UnusedFields::VisitFieldDecl( const FieldDecl* fieldDecl ) { fieldDecl = fieldDecl->getCanonicalDecl(); - if (ignoreLocation( compat::getBeginLoc(fieldDecl) )) { + if (ignoreLocation( fieldDecl->getBeginLoc() )) { return true; } // ignore stuff that forms part of the stable URE interface @@ -387,8 +385,8 @@ bool UnusedFields::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) { @@ -424,7 +422,7 @@ bool startswith(const std::string& rStr, const char* pSubStr) bool UnusedFields::TraverseCXXConstructorDecl(CXXConstructorDecl* cxxConstructorDecl) { auto copy = insideMoveOrCopyOrCloneDeclParent; - if (!ignoreLocation(compat::getBeginLoc(cxxConstructorDecl)) && cxxConstructorDecl->isThisDeclarationADefinition()) + if (!ignoreLocation(cxxConstructorDecl->getBeginLoc()) && cxxConstructorDecl->isThisDeclarationADefinition()) { if (cxxConstructorDecl->isCopyOrMoveConstructor()) insideMoveOrCopyOrCloneDeclParent = cxxConstructorDecl->getParent(); @@ -438,7 +436,7 @@ bool UnusedFields::TraverseCXXMethodDecl(CXXMethodDecl* cxxMethodDecl) { auto copy1 = insideMoveOrCopyOrCloneDeclParent; auto copy2 = insideFunctionDecl; - if (!ignoreLocation(compat::getBeginLoc(cxxMethodDecl)) && cxxMethodDecl->isThisDeclarationADefinition()) + if (!ignoreLocation(cxxMethodDecl->getBeginLoc()) && cxxMethodDecl->isThisDeclarationADefinition()) { if (cxxMethodDecl->isCopyAssignmentOperator() || cxxMethodDecl->isMoveAssignmentOperator() @@ -465,7 +463,7 @@ bool UnusedFields::TraverseFunctionDecl(FunctionDecl* functionDecl) auto copy1 = insideStreamOutputOperator; auto copy2 = insideFunctionDecl; auto copy3 = insideMoveOrCopyOrCloneDeclParent; - if (functionDecl->getLocation().isValid() && !ignoreLocation(compat::getBeginLoc(functionDecl)) && functionDecl->isThisDeclarationADefinition()) + if (functionDecl->getLocation().isValid() && !ignoreLocation(functionDecl->getBeginLoc()) && functionDecl->isThisDeclarationADefinition()) { auto op = functionDecl->getOverloadedOperator(); if (op == OO_LessLess @@ -532,7 +530,7 @@ bool UnusedFields::VisitMemberExpr( const MemberExpr* memberExpr ) return true; } fieldDecl = fieldDecl->getCanonicalDecl(); - if (ignoreLocation(compat::getBeginLoc(fieldDecl))) { + if (ignoreLocation(fieldDecl->getBeginLoc())) { return true; } // ignore stuff that forms part of the stable URE interface @@ -774,12 +772,12 @@ void UnusedFields::checkIfReadFrom(const FieldDecl* fieldDecl, const Expr* membe 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)) + parent->getBeginLoc()) << parent->getSourceRange(); parent->dump(); memberExpr->dump(); @@ -990,7 +988,7 @@ void UnusedFields::checkIfWrittenTo(const FieldDecl* fieldDecl, const Expr* memb report( DiagnosticsEngine::Warning, "oh dear, what can the matter be? writtenTo=%0", - compat::getBeginLoc(memberExpr)) + memberExpr->getBeginLoc()) << bPotentiallyWrittenTo << memberExpr->getSourceRange(); if (parent) @@ -998,7 +996,7 @@ void UnusedFields::checkIfWrittenTo(const FieldDecl* fieldDecl, const Expr* memb report( DiagnosticsEngine::Note, "parent over here", - compat::getBeginLoc(parent)) + parent->getBeginLoc()) << parent->getSourceRange(); parent->dump(); } @@ -1106,7 +1104,7 @@ bool UnusedFields::IsPassedByNonConst(const FieldDecl* fieldDecl, const Stmt * c // have to do it here bool UnusedFields::VisitCXXConstructorDecl( const CXXConstructorDecl* cxxConstructorDecl ) { - if (ignoreLocation( compat::getBeginLoc(cxxConstructorDecl) )) { + if (ignoreLocation( cxxConstructorDecl->getBeginLoc() )) { return true; } // ignore stuff that forms part of the stable URE interface @@ -1139,7 +1137,7 @@ bool UnusedFields::VisitCXXConstructorDecl( const CXXConstructorDecl* cxxConstru // have to do it here. bool UnusedFields::VisitInitListExpr( const InitListExpr* initListExpr) { - if (ignoreLocation( compat::getBeginLoc(initListExpr) )) + if (ignoreLocation( initListExpr->getBeginLoc() )) return true; QualType varType = initListExpr->getType().getDesugaredType(compiler.getASTContext()); @@ -1165,7 +1163,7 @@ bool UnusedFields::VisitDeclRefExpr( const DeclRefExpr* declRefExpr ) return true; } fieldDecl = fieldDecl->getCanonicalDecl(); - if (ignoreLocation(compat::getBeginLoc(fieldDecl))) { + if (ignoreLocation(fieldDecl->getBeginLoc())) { return true; } // ignore stuff that forms part of the stable URE interface diff --git a/compilerplugins/clang/unusedfieldsremove.cxx b/compilerplugins/clang/unusedfieldsremove.cxx index b8c339edcbcd..61df036f2c62 100644 --- a/compilerplugins/clang/unusedfieldsremove.cxx +++ b/compilerplugins/clang/unusedfieldsremove.cxx @@ -12,6 +12,7 @@ #include <cassert> #include <string> #include <iostream> +#include "config_clang.h" #include "plugin.hxx" #include <sys/mman.h> #include <sys/types.h> @@ -120,7 +121,7 @@ bool UnusedFieldsRemove::VisitFieldDecl( const FieldDecl* fieldDecl ) report( DiagnosticsEngine::Warning, "Could not remove unused field (" + niceName(fieldDecl) + ")", - compat::getBeginLoc(fieldDecl)) + fieldDecl->getBeginLoc()) << fieldDecl->getSourceRange(); } return true; diff --git a/compilerplugins/clang/unusedindex.cxx b/compilerplugins/clang/unusedindex.cxx index a47d55b0fd0a..63b9d4dcaeaf 100644 --- a/compilerplugins/clang/unusedindex.cxx +++ b/compilerplugins/clang/unusedindex.cxx @@ -63,8 +63,7 @@ bool UnusedIndex::TraverseForStmt(ForStmt* stmt) auto ret = RecursiveASTVisitor::TraverseStmt(stmt->getBody()); if (loopVarDecl && mFoundSet.erase(loopVarDecl) == 0) - report(DiagnosticsEngine::Warning, "loop variable not used", - compat::getBeginLoc(loopVarDecl)) + report(DiagnosticsEngine::Warning, "loop variable not used", loopVarDecl->getBeginLoc()) << loopVarDecl->getSourceRange(); if (loopVarDecl) diff --git a/compilerplugins/clang/unusedmember.cxx b/compilerplugins/clang/unusedmember.cxx index 8239b5ae1d8d..7ee433ca2387 100644 --- a/compilerplugins/clang/unusedmember.cxx +++ b/compilerplugins/clang/unusedmember.cxx @@ -18,8 +18,6 @@ #include <cassert> #include <set> -#include "config_clang.h" - #include "check.hxx" #include "compat.hxx" #include "plugin.hxx" @@ -60,40 +58,6 @@ public: { } -#if CLANG_VERSION < 60000 - - bool TraverseAlignedAttr(AlignedAttr* attr) - { - bool ret = FilteringPlugin::TraverseAlignedAttr(attr); - PostTraverseAlignedAttr(attr, ret); - return ret; - } - - bool PostTraverseAlignedAttr(AlignedAttr* attr, bool run) - { - if (!run) - { - return false; - } - if (attr->isAlignmentExpr()) - { - if (!TraverseStmt(attr->getAlignmentExpr())) - { - return false; - } - } - else if (auto const tsi = attr->getAlignmentType()) - { - if (!TraverseTypeLoc(tsi->getTypeLoc())) - { - return false; - } - } - return true; - } - -#endif - bool VisitDeclaratorDecl(DeclaratorDecl const* decl) { // For declarations like @@ -279,9 +243,7 @@ public: { case UETT_SizeOf: case UETT_AlignOf: -#if CLANG_VERSION >= 80000 case UETT_PreferredAlignOf: -#endif break; default: return true; diff --git a/compilerplugins/clang/unusedmethods.cxx b/compilerplugins/clang/unusedmethods.cxx index ccad7e3375d7..41b1317d4047 100644 --- a/compilerplugins/clang/unusedmethods.cxx +++ b/compilerplugins/clang/unusedmethods.cxx @@ -17,6 +17,8 @@ #include "clang/AST/Attr.h" +#include "config_clang.h" + #include "plugin.hxx" /** @@ -144,10 +146,6 @@ MyFuncInfo UnusedMethods::niceName(const FunctionDecl* functionDecl) { if (functionDecl->getInstantiatedFromMemberFunction()) functionDecl = functionDecl->getInstantiatedFromMemberFunction(); -#if CLANG_VERSION < 90000 - else if (functionDecl->getClassScopeSpecializationPattern()) - functionDecl = functionDecl->getClassScopeSpecializationPattern(); -#endif else if (functionDecl->getTemplateInstantiationPattern()) functionDecl = functionDecl->getTemplateInstantiationPattern(); else @@ -262,7 +260,7 @@ void UnusedMethods::logCallToRootMethods(const FunctionDecl* functionDecl, std:: { while (functionDecl->getTemplateInstantiationPattern()) functionDecl = functionDecl->getTemplateInstantiationPattern(); - if (functionDecl->getLocation().isValid() && !ignoreLocation( compat::getBeginLoc(functionDecl) ) + if (functionDecl->getLocation().isValid() && !ignoreLocation( functionDecl->getBeginLoc() ) && !functionDecl->isExternC()) funcSet.insert(niceName(functionDecl)); } @@ -307,7 +305,7 @@ gotfunc: { const FunctionDecl* parentFunctionOfCallSite = getParentFunctionDecl(expr); if (parentFunctionOfCallSite != calleeFunctionDecl) { - if (!parentFunctionOfCallSite || !ignoreLocation(compat::getBeginLoc(parentFunctionOfCallSite))) { + if (!parentFunctionOfCallSite || !ignoreLocation(parentFunctionOfCallSite->getBeginLoc())) { calledFromOutsideSet.insert(niceName(calleeFunctionDecl)); } } @@ -347,7 +345,7 @@ bool UnusedMethods::VisitCXXConstructExpr( const CXXConstructExpr* constructExpr const CXXConstructorDecl* constructorDecl = constructExpr->getConstructor(); constructorDecl = constructorDecl->getCanonicalDecl(); - if (!constructorDecl->getLocation().isValid() || ignoreLocation(compat::getBeginLoc(constructorDecl))) { + if (!constructorDecl->getLocation().isValid() || ignoreLocation(constructorDecl->getBeginLoc())) { return true; } @@ -378,7 +376,7 @@ bool UnusedMethods::VisitFunctionDecl( const FunctionDecl* functionDecl ) { return true; } - if (!canonicalFunctionDecl->getLocation().isValid() || ignoreLocation(compat::getBeginLoc(canonicalFunctionDecl))) { + if (!canonicalFunctionDecl->getLocation().isValid() || ignoreLocation(canonicalFunctionDecl->getBeginLoc())) { return true; } // ignore method overrides, since the call will show up as being directed to the root method @@ -408,7 +406,7 @@ bool UnusedMethods::VisitDeclRefExpr( const DeclRefExpr* declRefExpr ) { const FunctionDecl* parentFunctionOfCallSite = getParentFunctionDecl(declRefExpr); if (parentFunctionOfCallSite != functionDecl) { - if (!parentFunctionOfCallSite || !ignoreLocation(compat::getBeginLoc(parentFunctionOfCallSite))) { + if (!parentFunctionOfCallSite || !ignoreLocation(parentFunctionOfCallSite->getBeginLoc())) { calledFromOutsideSet.insert(niceName(functionDecl)); } } diff --git a/compilerplugins/clang/unusedmethodsremove.cxx b/compilerplugins/clang/unusedmethodsremove.cxx index 417c3778edf0..ff87c6b7771a 100644 --- a/compilerplugins/clang/unusedmethodsremove.cxx +++ b/compilerplugins/clang/unusedmethodsremove.cxx @@ -12,8 +12,8 @@ #include <cassert> #include <string> #include <iostream> +#include "config_clang.h" #include "plugin.hxx" -#include "compat.hxx" #include <sys/mman.h> #include <sys/types.h> #include <fcntl.h> @@ -137,7 +137,7 @@ bool UnusedMethodsRemove::VisitCXXMethodDecl( const CXXMethodDecl* functionDecl report( DiagnosticsEngine::Warning, "Could not remove unused method (" + niceName(functionDecl) + ")", - compat::getBeginLoc(functionDecl)) + functionDecl->getBeginLoc()) << functionDecl->getSourceRange(); } return true; diff --git a/compilerplugins/clang/unusedvariablemore.cxx b/compilerplugins/clang/unusedvariablemore.cxx index f165a6d6b50c..908edf33a465 100644 --- a/compilerplugins/clang/unusedvariablemore.cxx +++ b/compilerplugins/clang/unusedvariablemore.cxx @@ -17,9 +17,7 @@ #include <unordered_set> #include <unordered_map> -#if CLANG_VERSION >= 110000 #include "clang/AST/ParentMapContext.h" -#endif namespace loplugin { diff --git a/compilerplugins/clang/unusedvariableplus.cxx b/compilerplugins/clang/unusedvariableplus.cxx index 845a4eedb2a7..af33ad9d2223 100644 --- a/compilerplugins/clang/unusedvariableplus.cxx +++ b/compilerplugins/clang/unusedvariableplus.cxx @@ -12,6 +12,7 @@ #ifndef LO_CLANG_SHARED_PLUGINS #include "plugin.hxx" +#include "config_clang.h" #include <unordered_set> /* diff --git a/compilerplugins/clang/unusedvarsglobal.cxx b/compilerplugins/clang/unusedvarsglobal.cxx index 9362a0117ac6..50ac67d4059e 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: @@ -199,9 +197,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 +332,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) @@ -604,10 +602,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; @@ -623,9 +618,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(); @@ -813,10 +808,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 @@ -834,11 +826,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(); } diff --git a/compilerplugins/clang/useuniqueptr.cxx b/compilerplugins/clang/useuniqueptr.cxx index c26e3db11365..ae95cbdfe99e 100644 --- a/compilerplugins/clang/useuniqueptr.cxx +++ b/compilerplugins/clang/useuniqueptr.cxx @@ -13,6 +13,7 @@ #include <iostream> #include <fstream> #include <set> +#include "config_clang.h" #include "plugin.hxx" #include "check.hxx" @@ -589,12 +590,12 @@ void UseUniquePtr::CheckDeleteLocalVar(const FunctionDecl* functionDecl, const C report( DiagnosticsEngine::Warning, "call to delete on a var, should be using std::unique_ptr", - compat::getBeginLoc(deleteExpr)) + deleteExpr->getBeginLoc()) << deleteExpr->getSourceRange(); report( DiagnosticsEngine::Note, "var is here", - compat::getBeginLoc(varDecl)) + varDecl->getBeginLoc()) << varDecl->getSourceRange(); } @@ -662,16 +663,16 @@ void UseUniquePtr::CheckLoopDelete(const FunctionDecl* functionDecl, const CXXDe auto init = iterVarDecl->getInit(); if (init) { - init = compat::IgnoreImplicit(init); - if (!compat::CPlusPlus17(compiler.getLangOpts())) + init = init->IgnoreImplicit(); + if (!compiler.getLangOpts().CPlusPlus17) if (auto x = dyn_cast<CXXConstructExpr>(init)) if (x->isElidable()) - init = compat::IgnoreImplicit(x->getArg(0)); + init = x->getArg(0)->IgnoreImplicit(); if (auto x = dyn_cast<CXXConstructExpr>(init)) if (x->getNumArgs() == 1 || (x->getNumArgs() >= 2 && isa<CXXDefaultArgExpr>(x->getArg(1)))) { - init = compat::IgnoreImplicit(x->getArg(0)); + init = x->getArg(0)->IgnoreImplicit(); } if (auto x = dyn_cast<CXXMemberCallExpr>(init)) init = x->getImplicitObjectArgument()->IgnoreParenImpCasts(); @@ -820,12 +821,12 @@ void UseUniquePtr::CheckLoopDelete(const FunctionDecl* functionDecl, const CXXDe report( DiagnosticsEngine::Warning, "loopdelete: rather manage this var with std::some_container<std::unique_ptr<T>>", - compat::getBeginLoc(deleteExpr)) + deleteExpr->getBeginLoc()) << deleteExpr->getSourceRange(); report( DiagnosticsEngine::Note, "var is here", - compat::getBeginLoc(varDecl)) + varDecl->getBeginLoc()) << varDecl->getSourceRange(); } } @@ -908,12 +909,12 @@ void UseUniquePtr::CheckCXXForRangeStmt(const FunctionDecl* functionDecl, const report( DiagnosticsEngine::Warning, "rather manage this var with std::some_container<std::unique_ptr<T>>", - compat::getBeginLoc(deleteExpr)) + deleteExpr->getBeginLoc()) << deleteExpr->getSourceRange(); report( DiagnosticsEngine::Note, "var is here", - compat::getBeginLoc(varDecl)) + varDecl->getBeginLoc()) << varDecl->getSourceRange(); } } @@ -992,12 +993,12 @@ void UseUniquePtr::CheckMemberDeleteExpr(const FunctionDecl* functionDecl, const report( DiagnosticsEngine::Warning, message, - compat::getBeginLoc(deleteExpr)) + deleteExpr->getBeginLoc()) << deleteExpr->getSourceRange(); report( DiagnosticsEngine::Note, "member is here", - compat::getBeginLoc(fieldDecl)) + fieldDecl->getBeginLoc()) << fieldDecl->getSourceRange(); } @@ -1117,7 +1118,7 @@ bool UseUniquePtr::VisitCXXDeleteExpr(const CXXDeleteExpr* deleteExpr) return true; if (ignoreLocation(mpCurrentFunctionDecl)) return true; - if (isInUnoIncludeFile(compat::getBeginLoc(mpCurrentFunctionDecl->getCanonicalDecl()))) + if (isInUnoIncludeFile(mpCurrentFunctionDecl->getCanonicalDecl()->getBeginLoc())) return true; auto declRefExpr = dyn_cast<DeclRefExpr>(deleteExpr->getArgument()->IgnoreParenImpCasts()->IgnoreImplicit()); if (!declRefExpr) @@ -1298,7 +1299,7 @@ void UseUniquePtr::CheckDeleteParmVar(const CXXDeleteExpr* deleteExpr, const Par report( DiagnosticsEngine::Warning, "calling delete on a pointer param, should be either allowlisted or simplified", - compat::getBeginLoc(deleteExpr)) + deleteExpr->getBeginLoc()) << deleteExpr->getSourceRange(); } diff --git a/compilerplugins/clang/vclwidgets.cxx b/compilerplugins/clang/vclwidgets.cxx index 804b4cc26489..2f5d6c57ab59 100644 --- a/compilerplugins/clang/vclwidgets.cxx +++ b/compilerplugins/clang/vclwidgets.cxx @@ -13,6 +13,7 @@ #include "plugin.hxx" #include "check.hxx" +#include "config_clang.h" #include "clang/AST/CXXInheritance.h" // Final goal: Checker for VCL widget references. Makes sure that VCL Window subclasses are properly referenced counted and dispose()'ed. @@ -189,7 +190,7 @@ bool VCLWidgets::VisitCXXDestructorDecl(const CXXDestructorDecl* pCXXDestructorD report( DiagnosticsEngine::Warning, BASE_REF_COUNTED_CLASS " subclass with VclPtr field must call disposeOnce() from its destructor", - compat::getBeginLoc(pCXXDestructorDecl)) + pCXXDestructorDecl->getBeginLoc()) << pCXXDestructorDecl->getSourceRange(); return true; } @@ -207,7 +208,7 @@ bool VCLWidgets::VisitCXXDestructorDecl(const CXXDestructorDecl* pCXXDestructorD // assert(true), ...; // auto skip = false; - for (auto loc = compat::getBeginLoc(*i); + for (auto loc = (*i)->getBeginLoc(); compiler.getSourceManager().isMacroBodyExpansion(loc); loc = compiler.getSourceManager().getImmediateMacroCallerLoc( loc)) @@ -238,7 +239,7 @@ bool VCLWidgets::VisitCXXDestructorDecl(const CXXDestructorDecl* pCXXDestructorD } if (!bOk) { SourceLocation spellingLocation = compiler.getSourceManager().getSpellingLoc( - compat::getBeginLoc(pCXXDestructorDecl)); + pCXXDestructorDecl->getBeginLoc()); StringRef filename = getFilenameOfLocation(spellingLocation); if ( !(loplugin::isSamePathname(filename, SRCDIR "/vcl/source/window/window.cxx")) && !(loplugin::isSamePathname(filename, SRCDIR "/vcl/source/gdi/virdev.cxx")) @@ -248,7 +249,7 @@ bool VCLWidgets::VisitCXXDestructorDecl(const CXXDestructorDecl* pCXXDestructorD report( DiagnosticsEngine::Warning, BASE_REF_COUNTED_CLASS " subclass should have nothing in its destructor but a call to disposeOnce()", - compat::getBeginLoc(pCXXDestructorDecl)) + pCXXDestructorDecl->getBeginLoc()) << pCXXDestructorDecl->getSourceRange(); } } @@ -264,7 +265,7 @@ bool VCLWidgets::VisitBinaryOperator(const BinaryOperator * binaryOperator) return true; } SourceLocation spellingLocation = compiler.getSourceManager().getSpellingLoc( - compat::getBeginLoc(binaryOperator)); + binaryOperator->getBeginLoc()); checkAssignmentForVclPtrToRawConversion(spellingLocation, binaryOperator->getLHS()->getType().getTypePtr(), binaryOperator->getRHS()); return true; } @@ -357,7 +358,7 @@ bool VCLWidgets::VisitVarDecl(const VarDecl * pVarDecl) { return true; } SourceLocation spellingLocation = compiler.getSourceManager().getSpellingLoc( - compat::getBeginLoc(pVarDecl)); + pVarDecl->getBeginLoc()); if (pVarDecl->getInit()) { checkAssignmentForVclPtrToRawConversion(spellingLocation, pVarDecl->getType().getTypePtr(), pVarDecl->getInit()); } @@ -414,7 +415,7 @@ bool VCLWidgets::VisitFieldDecl(const FieldDecl * fieldDecl) { return true; } StringRef aFileName = getFilenameOfLocation( - compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(fieldDecl))); + compiler.getSourceManager().getSpellingLoc(fieldDecl->getBeginLoc())); if (loplugin::isSamePathname(aFileName, SRCDIR "/include/vcl/vclptr.hxx")) return true; if (loplugin::isSamePathname(aFileName, SRCDIR "/include/rtl/ref.hxx")) @@ -601,7 +602,7 @@ bool VCLWidgets::VisitFunctionDecl( const FunctionDecl* functionDecl ) report( DiagnosticsEngine::Warning, BASE_REF_COUNTED_CLASS " subclass dispose() function MUST call dispose() of its superclass as the last thing it does", - compat::getBeginLoc(functionDecl)) + functionDecl->getBeginLoc()) << functionDecl->getSourceRange(); } } @@ -655,7 +656,7 @@ bool VCLWidgets::VisitFunctionDecl( const FunctionDecl* functionDecl ) report( DiagnosticsEngine::Warning, aMessage, - compat::getBeginLoc(functionDecl)) + functionDecl->getBeginLoc()) << functionDecl->getSourceRange(); } } @@ -672,14 +673,14 @@ bool VCLWidgets::VisitCXXDeleteExpr(const CXXDeleteExpr *pCXXDeleteExpr) const CXXRecordDecl *pPointee = pCXXDeleteExpr->getArgument()->getType()->getPointeeCXXRecordDecl(); if (pPointee && isDerivedFromVclReferenceBase(pPointee)) { SourceLocation spellingLocation = compiler.getSourceManager().getSpellingLoc( - compat::getBeginLoc(pCXXDeleteExpr)); + pCXXDeleteExpr->getBeginLoc()); StringRef filename = getFilenameOfLocation(spellingLocation); if ( !(loplugin::isSamePathname(filename, SRCDIR "/include/vcl/vclreferencebase.hxx"))) { report( DiagnosticsEngine::Warning, "calling delete on instance of " BASE_REF_COUNTED_CLASS " subclass, must rather call disposeAndClear()", - compat::getBeginLoc(pCXXDeleteExpr)) + pCXXDeleteExpr->getBeginLoc()) << pCXXDeleteExpr->getSourceRange(); } } @@ -698,7 +699,7 @@ bool VCLWidgets::VisitCXXDeleteExpr(const CXXDeleteExpr *pCXXDeleteExpr) report( DiagnosticsEngine::Warning, "calling delete on instance of VclPtr, must rather call disposeAndClear()", - compat::getBeginLoc(pCXXDeleteExpr)) + pCXXDeleteExpr->getBeginLoc()) << pCXXDeleteExpr->getSourceRange(); return true; } @@ -855,7 +856,7 @@ bool VCLWidgets::VisitCXXConstructExpr( const CXXConstructExpr* constructExpr ) const CXXRecordDecl* recordDecl = pConstructorDecl->getParent(); if (isDerivedFromVclReferenceBase(recordDecl)) { StringRef aFileName = getFilenameOfLocation( - compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(constructExpr))); + compiler.getSourceManager().getSpellingLoc(constructExpr->getBeginLoc())); if (!loplugin::isSamePathname(aFileName, SRCDIR "/include/vcl/vclptr.hxx")) { report( DiagnosticsEngine::Warning, diff --git a/compilerplugins/clang/virtualdead.cxx b/compilerplugins/clang/virtualdead.cxx index 0d575ec8aef2..ca117d7f60ef 100644 --- a/compilerplugins/clang/virtualdead.cxx +++ b/compilerplugins/clang/virtualdead.cxx @@ -242,8 +242,8 @@ std::string VirtualDead::getCallValue(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) diff --git a/compilerplugins/clang/virtualdown.cxx b/compilerplugins/clang/virtualdown.cxx index 96984b19dcfd..946d8bc953bc 100644 --- a/compilerplugins/clang/virtualdown.cxx +++ b/compilerplugins/clang/virtualdown.cxx @@ -11,6 +11,7 @@ #include <string> #include <iostream> #include <set> +#include "config_clang.h" #include "plugin.hxx" #include <fstream> diff --git a/compilerplugins/clang/weakbase.cxx b/compilerplugins/clang/weakbase.cxx index ffc0b931956c..666444ff7ffb 100644 --- a/compilerplugins/clang/weakbase.cxx +++ b/compilerplugins/clang/weakbase.cxx @@ -50,7 +50,7 @@ bool WeakBase::VisitCXXRecordDecl(CXXRecordDecl const* recordDecl) return true; } // StringRef aFileName = getFilenameOfLocation( - // compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(fieldDecl))); + // compiler.getSourceManager().getSpellingLoc(fieldDecl->getBeginLoc())); // if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/chart2/source/")) // return true; @@ -108,7 +108,7 @@ bool WeakBase::VisitCXXRecordDecl(CXXRecordDecl const* recordDecl) { report(DiagnosticsEngine::Warning, "multiple copies of WeakBase, through inheritance paths %0", - compat::getBeginLoc(recordDecl)) + recordDecl->getBeginLoc()) << basePaths << recordDecl->getSourceRange(); } return true; diff --git a/compilerplugins/clang/weakobject.cxx b/compilerplugins/clang/weakobject.cxx index 4801953cc44a..d021dd419d89 100644 --- a/compilerplugins/clang/weakobject.cxx +++ b/compilerplugins/clang/weakobject.cxx @@ -70,7 +70,7 @@ bool WeakObject::VisitCXXRecordDecl(const CXXRecordDecl* decl) return true; report(DiagnosticsEngine::Warning, "more than one copy of cppu::OWeakObject inherited", - compat::getBeginLoc(decl)) + decl->getBeginLoc()) << decl->getSourceRange(); return true; } diff --git a/compilerplugins/clang/writeonlyvars.cxx b/compilerplugins/clang/writeonlyvars.cxx index 51a967dac8a0..f5051c99e128 100644 --- a/compilerplugins/clang/writeonlyvars.cxx +++ b/compilerplugins/clang/writeonlyvars.cxx @@ -22,12 +22,9 @@ #include "config_clang.h" #include "plugin.hxx" -#include "compat.hxx" #include "check.hxx" -#if CLANG_VERSION >= 110000 #include "clang/AST/ParentMapContext.h" -#endif /** Finds variables that are effectively write-only. @@ -484,18 +481,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 +545,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 +758,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 +774,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 +967,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 +984,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(); } diff --git a/compilerplugins/clang/xmlimport.cxx b/compilerplugins/clang/xmlimport.cxx index a15c3c63f057..1f9f44090b8a 100644 --- a/compilerplugins/clang/xmlimport.cxx +++ b/compilerplugins/clang/xmlimport.cxx @@ -10,9 +10,9 @@ */ #ifndef LO_CLANG_SHARED_PLUGINS -#include "compat.hxx" #include "plugin.hxx" #include "check.hxx" +#include "config_clang.h" #include <iostream> #include <unordered_map> #include "clang/AST/CXXInheritance.h" @@ -93,7 +93,7 @@ private: bool XmlImport::VisitCXXMethodDecl(const CXXMethodDecl* methodDecl) { - auto beginLoc = compat::getBeginLoc(methodDecl); + auto beginLoc = methodDecl->getBeginLoc(); if (!beginLoc.isValid() || ignoreLocation(beginLoc)) return true; @@ -140,11 +140,11 @@ bool XmlImport::VisitCXXMethodDecl(const CXXMethodDecl* methodDecl) { auto methodDecl1 = it1->second; report(DiagnosticsEngine::Warning, "cannot override both endFastElement and EndElement", - compat::getBeginLoc(methodDecl1)) + methodDecl1->getBeginLoc()) << methodDecl1->getSourceRange(); auto methodDecl2 = it2->second; report(DiagnosticsEngine::Warning, "cannot override both endFastElement and EndElement", - compat::getBeginLoc(methodDecl2)) + methodDecl2->getBeginLoc()) << methodDecl2->getSourceRange(); } } @@ -157,12 +157,12 @@ bool XmlImport::VisitCXXMethodDecl(const CXXMethodDecl* methodDecl) auto methodDecl1 = it1->second; report(DiagnosticsEngine::Warning, "cannot override both startFastElement and StartElement", - compat::getBeginLoc(methodDecl1)) + methodDecl1->getBeginLoc()) << methodDecl1->getSourceRange(); auto methodDecl2 = it2->second; report(DiagnosticsEngine::Warning, "cannot override both startFastElement and StartElement", - compat::getBeginLoc(methodDecl2)) + methodDecl2->getBeginLoc()) << methodDecl2->getSourceRange(); } } @@ -173,11 +173,11 @@ bool XmlImport::VisitCXXMethodDecl(const CXXMethodDecl* methodDecl) { auto methodDecl1 = it1->second; report(DiagnosticsEngine::Warning, "cannot override both characters and Characters", - compat::getBeginLoc(methodDecl1)) + methodDecl1->getBeginLoc()) << methodDecl1->getSourceRange(); auto methodDecl2 = it2->second; report(DiagnosticsEngine::Warning, "cannot override both characters and Characters", - compat::getBeginLoc(methodDecl2)) + methodDecl2->getBeginLoc()) << methodDecl2->getSourceRange(); } } @@ -188,12 +188,11 @@ bool XmlImport::VisitCXXMethodDecl(const CXXMethodDecl* methodDecl) auto compoundStmt = dyn_cast_or_null<CompoundStmt>(methodDecl->getBody()); if (compoundStmt == nullptr || compoundStmt->size() > 0) return; - report(DiagnosticsEngine::Warning, "empty, should be removed", - compat::getBeginLoc(methodDecl)) + report(DiagnosticsEngine::Warning, "empty, should be removed", methodDecl->getBeginLoc()) << methodDecl->getSourceRange(); auto canonicalDecl = methodDecl->getCanonicalDecl(); if (canonicalDecl != methodDecl) - report(DiagnosticsEngine::Note, "definition here", compat::getBeginLoc(canonicalDecl)) + report(DiagnosticsEngine::Note, "definition here", canonicalDecl->getBeginLoc()) << canonicalDecl->getSourceRange(); }; auto checkOnlyReturn = [&]() { @@ -213,12 +212,11 @@ bool XmlImport::VisitCXXMethodDecl(const CXXMethodDecl* methodDecl) return; if (!isa<CXXNullPtrLiteralExpr>(cxxConstructExpr->getArg(0)->IgnoreImplicit())) return; - report(DiagnosticsEngine::Warning, "empty, should be removed", - compat::getBeginLoc(methodDecl)) + report(DiagnosticsEngine::Warning, "empty, should be removed", methodDecl->getBeginLoc()) << methodDecl->getSourceRange(); auto canonicalDecl = methodDecl->getCanonicalDecl(); if (canonicalDecl != methodDecl) - report(DiagnosticsEngine::Note, "definition here", compat::getBeginLoc(canonicalDecl)) + report(DiagnosticsEngine::Note, "definition here", canonicalDecl->getBeginLoc()) << canonicalDecl->getSourceRange(); }; @@ -238,7 +236,7 @@ bool XmlImport::VisitCXXMethodDecl(const CXXMethodDecl* methodDecl) bool XmlImport::VisitCXXMemberCallExpr(const CXXMemberCallExpr* callExpr) { - auto beginLoc = compat::getBeginLoc(callExpr); + auto beginLoc = callExpr->getBeginLoc(); if (!beginLoc.isValid() || ignoreLocation(callExpr)) return true; @@ -263,7 +261,7 @@ bool XmlImport::VisitCXXMemberCallExpr(const CXXMemberCallExpr* callExpr) * Calling this superclass method from a subclass method will mess with the fallback logic in the superclass. */ report(DiagnosticsEngine::Warning, "don't call this superclass method", - compat::getBeginLoc(callExpr)) + callExpr->getBeginLoc()) << callExpr->getSourceRange(); } return true; @@ -271,7 +269,7 @@ bool XmlImport::VisitCXXMemberCallExpr(const CXXMemberCallExpr* callExpr) bool XmlImport::VisitBinaryOperator(const BinaryOperator* binaryOp) { - auto beginLoc = compat::getBeginLoc(binaryOp); + auto beginLoc = binaryOp->getBeginLoc(); if (!beginLoc.isValid() || ignoreLocation(binaryOp)) return true; auto op = binaryOp->getOpcode(); @@ -281,7 +279,7 @@ bool XmlImport::VisitBinaryOperator(const BinaryOperator* binaryOp) if (!isUInt16(expr)) report(DiagnosticsEngine::Warning, "comparing XML_TOK enum to 'sal_uInt32', expected sal_uInt16", - compat::getBeginLoc(binaryOp)) + binaryOp->getBeginLoc()) << binaryOp->getSourceRange(); }; if (isXmlTokEnum(binaryOp->getLHS())) @@ -293,13 +291,14 @@ bool XmlImport::VisitBinaryOperator(const BinaryOperator* binaryOp) bool XmlImport::VisitSwitchStmt(const SwitchStmt* switchStmt) { - auto beginLoc = compat::getBeginLoc(switchStmt); + auto beginLoc = switchStmt->getBeginLoc(); if (!beginLoc.isValid() || ignoreLocation(switchStmt)) return true; if (isUInt16(switchStmt->getCond())) return true; // if the condition is an enum type, ignore this switch - auto condEnumType = compat::IgnoreImplicit(switchStmt->getCond()) + auto condEnumType = switchStmt->getCond() + ->IgnoreImplicit() ->getType() ->getUnqualifiedDesugaredType() ->getAs<EnumType>(); @@ -315,7 +314,7 @@ bool XmlImport::VisitSwitchStmt(const SwitchStmt* switchStmt) continue; report(DiagnosticsEngine::Warning, "comparing XML_TOK enum to 'sal_uInt32', expected sal_uInt16", - compat::getBeginLoc(caseStmt)) + caseStmt->getBeginLoc()) << caseStmt->getSourceRange(); } return true; @@ -323,7 +322,7 @@ bool XmlImport::VisitSwitchStmt(const SwitchStmt* switchStmt) bool XmlImport::VisitCallExpr(const CallExpr* callExpr) { - auto beginLoc = compat::getBeginLoc(callExpr); + auto beginLoc = callExpr->getBeginLoc(); if (!beginLoc.isValid() || ignoreLocation(callExpr)) return true; @@ -336,7 +335,7 @@ bool XmlImport::VisitCallExpr(const CallExpr* callExpr) return true; for (unsigned i = 0; i != callExpr->getNumArgs(); ++i) { - auto argExpr = compat::IgnoreImplicit(callExpr->getArg(i)); + auto argExpr = callExpr->getArg(i)->IgnoreImplicit(); if (!isXmlTokEnum(argExpr)) continue; // if the condition is an enum type, ignore this switch @@ -350,7 +349,7 @@ bool XmlImport::VisitCallExpr(const CallExpr* callExpr) return true; report(DiagnosticsEngine::Warning, "passing XML_TOK enum to 'sal_Int32', wrong param or XML token type", - compat::getBeginLoc(callExpr)) + callExpr->getBeginLoc()) << callExpr->getSourceRange(); } @@ -359,7 +358,7 @@ bool XmlImport::VisitCallExpr(const CallExpr* callExpr) bool XmlImport::isXmlTokEnum(const Expr* expr) { - expr = compat::IgnoreImplicit(expr); + expr = expr->IgnoreImplicit(); // check that we have an unscoped enum type auto condEnumType = expr->getType()->getUnqualifiedDesugaredType()->getAs<EnumType>(); if (!condEnumType || condEnumType->getDecl()->isScoped()) @@ -375,7 +374,7 @@ bool XmlImport::isXmlTokEnum(const Expr* expr) bool XmlImport::isUInt16(const Expr* expr) { - expr = compat::IgnoreImplicit(expr); + expr = expr->IgnoreImplicit(); return isUInt16(expr->getType()); } |