summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/plugin.cxx7
-rw-r--r--compilerplugins/clang/plugin.hxx2
-rw-r--r--compilerplugins/clang/pointertobool.cxx2
3 files changed, 9 insertions, 2 deletions
diff --git a/compilerplugins/clang/plugin.cxx b/compilerplugins/clang/plugin.cxx
index 50ec0a9ced1b..65333025e576 100644
--- a/compilerplugins/clang/plugin.cxx
+++ b/compilerplugins/clang/plugin.cxx
@@ -145,6 +145,11 @@ void Plugin::buildParents( CompilerInstance& compiler )
builder.TraverseDecl( compiler.getASTContext().getTranslationUnitDecl());
}
+SourceLocation Plugin::locationAfterToken( SourceLocation location )
+ {
+ return Lexer::getLocForEndOfToken( location, 0, compiler.getSourceManager(), compiler.getLangOpts());
+ }
+
/////
RewritePlugin::RewritePlugin( CompilerInstance& compiler, Rewriter& rewriter )
@@ -222,7 +227,7 @@ bool RewritePlugin::adjustRangeForOptions( CharSourceRange* range, RewriteOption
return false;
SourceLocation locationEnd = range->getEnd();
if( range->isTokenRange())
- locationEnd = Lexer::getLocForEndOfToken( locationEnd, 0, compiler.getSourceManager(), compiler.getLangOpts());
+ locationEnd = locationAfterToken( locationEnd );
const char* endBuf = SM.getCharacterData( locationEnd, &invalid );
if( invalid )
return false;
diff --git a/compilerplugins/clang/plugin.hxx b/compilerplugins/clang/plugin.hxx
index 4fd766d8d2a0..24a6c3b7a2f3 100644
--- a/compilerplugins/clang/plugin.hxx
+++ b/compilerplugins/clang/plugin.hxx
@@ -51,6 +51,8 @@ class Plugin
DiagnosticBuilder report( DiagnosticsEngine::Level level, StringRef message, SourceLocation loc = SourceLocation());
static DiagnosticBuilder report( DiagnosticsEngine::Level level, StringRef message,
CompilerInstance& compiler, SourceLocation loc = SourceLocation());
+ // Returns location right after the end of the token that starts at the given location.
+ SourceLocation locationAfterToken( SourceLocation location );
protected:
bool ignoreLocation( SourceLocation loc );
bool ignoreLocation( const Decl* decl );
diff --git a/compilerplugins/clang/pointertobool.cxx b/compilerplugins/clang/pointertobool.cxx
index 238e0180b7e8..e0c69ff98099 100644
--- a/compilerplugins/clang/pointertobool.cxx
+++ b/compilerplugins/clang/pointertobool.cxx
@@ -73,7 +73,7 @@ bool PointerToBool::VisitImplicitCastExpr( const ImplicitCastExpr* expr )
report( DiagnosticsEngine::Warning,
"pointer %0 implicitly converted to bool", expr->getLocStart())
<< expr->getSubExpr()->getType() << expr->getSourceRange();
- SourceLocation endOfExpression = Lexer::getLocForEndOfToken( expr->getLocEnd(), 0, compiler.getSourceManager(), compiler.getLangOpts());
+ SourceLocation endOfExpression = locationAfterToken( expr->getLocEnd());
report( DiagnosticsEngine::Note,
"explicitly compare to null pointer to silence this warning", endOfExpression )
<< FixItHint::CreateInsertion( endOfExpression, " != NULL" );