diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2018-05-03 21:13:35 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2018-05-04 13:56:51 +0200 |
commit | b72a31b37f9bdcfd3f59b3256b465bf0fb5a50ca (patch) | |
tree | 80d44735a1106b93463ae36150a3302689ffde85 /compilerplugins | |
parent | fe18111ac42101e6653402c214f7fc1df03acd43 (diff) |
Adapt to Clang trunk SourceManager::getImmediateExpansionRange changes
...of <http://llvm.org/viewvc/llvm-project?view=revision&revision=331155>
"PR37189 Fix incorrect end source location and spelling for a split '>>' token",
changing (among others) the return type of getImmediateExpansionRange from a
std::pair of token locations to CharSourceRange (which will typically also
represent token locations, but might also represent char locations).
For now, map the return value of getImmediateExpansionRange back to a std::pair
(as expected by our compilerplugins code in its current form), and mark the
char location case with a TODO (which will need to be addressed if any of our
plugins starts to produce wrong results due to not handling that char location
case). In the long run, we should instead adapt our code to use the new return
type of getImmediateExpansionRange directly.
Change-Id: Idc2f5dc43830af4798b55bf605976c4ab146c522
Reviewed-on: https://gerrit.libreoffice.org/53817
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/compat.hxx | 12 | ||||
-rw-r--r-- | compilerplugins/clang/constparams.cxx | 2 | ||||
-rw-r--r-- | compilerplugins/clang/cppunitassertequals.cxx | 3 | ||||
-rw-r--r-- | compilerplugins/clang/cstylecast.cxx | 24 | ||||
-rw-r--r-- | compilerplugins/clang/literaltoboolconversion.cxx | 4 | ||||
-rw-r--r-- | compilerplugins/clang/nullptr.cxx | 11 | ||||
-rw-r--r-- | compilerplugins/clang/salcall.cxx | 2 | ||||
-rw-r--r-- | compilerplugins/clang/sallogareas.cxx | 3 |
8 files changed, 39 insertions, 22 deletions
diff --git a/compilerplugins/clang/compat.hxx b/compilerplugins/clang/compat.hxx index 5a540b8ef695..e77846ab1166 100644 --- a/compilerplugins/clang/compat.hxx +++ b/compilerplugins/clang/compat.hxx @@ -11,6 +11,7 @@ #define INCLUDED_COMPILERPLUGINS_CLANG_COMPAT_HXX #include <cstddef> +#include <utility> #include "clang/AST/Decl.h" #include "clang/AST/Expr.h" @@ -49,6 +50,17 @@ inline clang::FunctionDecl::param_const_range parameters( } #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, diff --git a/compilerplugins/clang/constparams.cxx b/compilerplugins/clang/constparams.cxx index 89be6f684033..471da7367dc0 100644 --- a/compilerplugins/clang/constparams.cxx +++ b/compilerplugins/clang/constparams.cxx @@ -179,7 +179,7 @@ bool ConstParams::CheckTraverseFunctionDecl(FunctionDecl * functionDecl) canonicalDecl->getLocStart(), compiler.getSourceManager(), compiler.getLangOpts()) }; if (name.startswith("DECL_LINK") || name.startswith("DECL_STATIC_LINK")) return false; - auto loc2 = compiler.getSourceManager().getImmediateExpansionRange(canonicalDecl->getLocStart()).first; + auto loc2 = compat::getImmediateExpansionRange(compiler.getSourceManager(), canonicalDecl->getLocStart()).first; if (compiler.getSourceManager().isMacroBodyExpansion(loc2)) { StringRef name2 { Lexer::getImmediateMacroName( diff --git a/compilerplugins/clang/cppunitassertequals.cxx b/compilerplugins/clang/cppunitassertequals.cxx index 5b0f8f5278c4..cff8908c7a46 100644 --- a/compilerplugins/clang/cppunitassertequals.cxx +++ b/compilerplugins/clang/cppunitassertequals.cxx @@ -9,6 +9,7 @@ #include "plugin.hxx" #include "check.hxx" +#include "compat.hxx" /** Check for calls to CPPUNIT_ASSERT when it should be using CPPUNIT_ASSERT_EQUALS @@ -95,7 +96,7 @@ bool CppunitAssertEquals::VisitCallExpr(const CallExpr* callExpr) << callExpr->getSourceRange(); return true; } - auto range = compiler.getSourceManager().getImmediateExpansionRange(loc); + auto range = compat::getImmediateExpansionRange(compiler.getSourceManager(), loc); checkExpr( SourceRange(range.first, range.second), name, e2->IgnoreParenImpCasts(), false); diff --git a/compilerplugins/clang/cstylecast.cxx b/compilerplugins/clang/cstylecast.cxx index 228e3878e5eb..4bf3aaf6460f 100644 --- a/compilerplugins/clang/cstylecast.cxx +++ b/compilerplugins/clang/cstylecast.cxx @@ -12,6 +12,8 @@ #include <limits> #include <set> #include <string> + +#include "compat.hxx" #include "plugin.hxx" // @@ -351,7 +353,7 @@ bool CStyleCast::isLastTokenOfImmediateMacroBodyExpansion( assert(MI != nullptr); if (spell == MI->getDefinitionEndLoc()) { if (macroEnd != nullptr) { - *macroEnd = compiler.getSourceManager().getImmediateExpansionRange(loc).second; + *macroEnd = compat::getImmediateExpansionRange(compiler.getSourceManager(), loc).second; } return true; } @@ -391,8 +393,8 @@ bool CStyleCast::rewriteArithmeticCast(CStyleCastExpr const * expr, char const * auto secondBegin = expr->getRParenLoc(); while (compiler.getSourceManager().isMacroArgExpansion(firstBegin) && compiler.getSourceManager().isMacroArgExpansion(secondBegin) - && (compiler.getSourceManager().getImmediateExpansionRange(firstBegin) - == compiler.getSourceManager().getImmediateExpansionRange(secondBegin))) + && (compat::getImmediateExpansionRange(compiler.getSourceManager(), firstBegin) + == compat::getImmediateExpansionRange(compiler.getSourceManager(), secondBegin))) { firstBegin = compiler.getSourceManager().getImmediateSpellingLoc(firstBegin); secondBegin = compiler.getSourceManager().getImmediateSpellingLoc(secondBegin); @@ -424,14 +426,14 @@ bool CStyleCast::rewriteArithmeticCast(CStyleCastExpr const * expr, char const * // FOO((y)) while (compiler.getSourceManager().isMacroArgExpansion(third) && compiler.getSourceManager().isMacroArgExpansion(fourth) - && (compiler.getSourceManager().getImmediateExpansionRange(third) - == compiler.getSourceManager().getImmediateExpansionRange(fourth)) + && (compat::getImmediateExpansionRange(compiler.getSourceManager(), third) + == compat::getImmediateExpansionRange(compiler.getSourceManager(), fourth)) && compiler.getSourceManager().isAtStartOfImmediateMacroExpansion(third)) //TODO: check fourth is at end of immediate macro expansion, but // SourceManager::isAtEndOfImmediateMacroExpansion requires a location pointing at the // character end of the last token { - auto const range = compiler.getSourceManager().getImmediateExpansionRange(third); + auto const range = compat::getImmediateExpansionRange(compiler.getSourceManager(), third); third = range.first; fourth = range.second; macro = true; @@ -439,8 +441,8 @@ bool CStyleCast::rewriteArithmeticCast(CStyleCastExpr const * expr, char const * } while (compiler.getSourceManager().isMacroArgExpansion(third) && compiler.getSourceManager().isMacroArgExpansion(fourth) - && (compiler.getSourceManager().getImmediateExpansionRange(third) - == compiler.getSourceManager().getImmediateExpansionRange(fourth))) + && (compat::getImmediateExpansionRange(compiler.getSourceManager(), third) + == compat::getImmediateExpansionRange(compiler.getSourceManager(), fourth))) { third = compiler.getSourceManager().getImmediateSpellingLoc(third); fourth = compiler.getSourceManager().getImmediateSpellingLoc(fourth); @@ -474,7 +476,8 @@ bool CStyleCast::rewriteArithmeticCast(CStyleCastExpr const * expr, char const * } break; } - auto const range = compiler.getSourceManager().getImmediateExpansionRange(third); + auto const range = compat::getImmediateExpansionRange( + compiler.getSourceManager(), third); third = range.first; fourth = range.second; assert(third.isValid()); @@ -511,7 +514,8 @@ bool CStyleCast::rewriteArithmeticCast(CStyleCastExpr const * expr, char const * { break; } - auto const range = compiler.getSourceManager().getImmediateExpansionRange(third); + auto const range = compat::getImmediateExpansionRange( + compiler.getSourceManager(), third); third = range.first; fourth = range.second; } diff --git a/compilerplugins/clang/literaltoboolconversion.cxx b/compilerplugins/clang/literaltoboolconversion.cxx index 17fa9da77d73..19c18a4ca765 100644 --- a/compilerplugins/clang/literaltoboolconversion.cxx +++ b/compilerplugins/clang/literaltoboolconversion.cxx @@ -12,6 +12,7 @@ #include "clang/Lex/Lexer.h" +#include "compat.hxx" #include "plugin.hxx" namespace { @@ -125,8 +126,7 @@ void LiteralToBoolConversion::handleImplicitCastSubExpr( StringRef name { Lexer::getImmediateMacroName( loc, compiler.getSourceManager(), compiler.getLangOpts()) }; if (name == "sal_False" || name == "sal_True") { - loc = compiler.getSourceManager().getImmediateExpansionRange( - loc).first; + loc = compat::getImmediateExpansionRange(compiler.getSourceManager(), loc).first; } if (isSharedCAndCppCode(loc)) { return; diff --git a/compilerplugins/clang/nullptr.cxx b/compilerplugins/clang/nullptr.cxx index 2e4de5d37a1c..bc1f7b505243 100644 --- a/compilerplugins/clang/nullptr.cxx +++ b/compilerplugins/clang/nullptr.cxx @@ -13,6 +13,7 @@ #include <set> #include "check.hxx" +#include "compat.hxx" #include "plugin.hxx" namespace { @@ -317,8 +318,7 @@ void Nullptr::handleNull( // ellipsis, cast to void* return; } - loc = compiler.getSourceManager() - .getImmediateExpansionRange(loc).first; + loc = compat::getImmediateExpansionRange(compiler.getSourceManager(), loc).first; if (ignoreLocation( compiler.getSourceManager().getSpellingLoc(loc))) { @@ -381,8 +381,8 @@ void Nullptr::rewriteOrWarn( compiler.getLangOpts()) == "NULL")) { - locStart = compiler.getSourceManager().getImmediateExpansionRange( - locStart).first; + locStart = compat::getImmediateExpansionRange(compiler.getSourceManager(), locStart) + .first; } SourceLocation locEnd(expr->getLocEnd()); while (compiler.getSourceManager().isMacroArgExpansion(locEnd)) { @@ -396,8 +396,7 @@ void Nullptr::rewriteOrWarn( compiler.getLangOpts()) == "NULL")) { - locEnd = compiler.getSourceManager().getImmediateExpansionRange( - locEnd).first; + locEnd = compat::getImmediateExpansionRange(compiler.getSourceManager(), locEnd).first; } if (replaceText(SourceRange(compiler.getSourceManager().getSpellingLoc(locStart), compiler.getSourceManager().getSpellingLoc(locEnd)), replacement)) { return; diff --git a/compilerplugins/clang/salcall.cxx b/compilerplugins/clang/salcall.cxx index 2f289033851d..a84cbd9825d5 100644 --- a/compilerplugins/clang/salcall.cxx +++ b/compilerplugins/clang/salcall.cxx @@ -428,7 +428,7 @@ bool SalCall::isSalCallFunction(FunctionDecl const* functionDecl, SourceLocation //TODO: If the macro is a function-like macro with a parameter named "SAL_CALL", uses of // that parameter in the remainder of the replacement text will be false positives. assert(SM.isMacroBodyExpansion(startLoc)); - auto const startLoc2 = SM.getImmediateExpansionRange(startLoc).second; + auto const startLoc2 = compat::getImmediateExpansionRange(SM, startLoc).second; auto name = Lexer::getImmediateMacroName(startLoc, SM, compiler.getLangOpts()); while (name.startswith("\\\n")) { diff --git a/compilerplugins/clang/sallogareas.cxx b/compilerplugins/clang/sallogareas.cxx index e31754493523..e18f100043e5 100644 --- a/compilerplugins/clang/sallogareas.cxx +++ b/compilerplugins/clang/sallogareas.cxx @@ -11,6 +11,7 @@ #include "sallogareas.hxx" #include "check.hxx" +#include "compat.hxx" #include <clang/Lex/Lexer.h> @@ -102,7 +103,7 @@ bool SalLogAreas::VisitCallExpr( const CallExpr* call ) const SourceManager& source = compiler.getSourceManager(); for( SourceLocation loc = call->getLocStart(); loc.isMacroID(); - loc = source.getImmediateExpansionRange( loc ).first ) + loc = compat::getImmediateExpansionRange(source, loc ).first ) { StringRef inMacro = Lexer::getImmediateMacroName( loc, source, compiler.getLangOpts()); if( inMacro == "SAL_DEBUG" || inMacro == "SAL_DEBUG_BACKTRACE" ) |