From 7cd19a8f10881028bfaf4217e586955f1d435c31 Mon Sep 17 00:00:00 2001 From: Luboš Luňák Date: Tue, 9 Oct 2012 16:39:49 +0200 Subject: do not analyse system headers in the compiler plugin Change-Id: Ica1e233b45cc778bfdc86cfd608ada7fc261c6c2 --- compilerplugins/clang/bodynotinblock.cxx | 3 +-- compilerplugins/clang/compileplugin.cxx | 5 +++++ compilerplugins/clang/compileplugin.hxx | 15 +++++++++++++++ compilerplugins/clang/unusedvariablecheck.cxx | 3 +-- 4 files changed, 22 insertions(+), 4 deletions(-) (limited to 'compilerplugins/clang') diff --git a/compilerplugins/clang/bodynotinblock.cxx b/compilerplugins/clang/bodynotinblock.cxx index ce19a5f6477a..9e59896f892f 100644 --- a/compilerplugins/clang/bodynotinblock.cxx +++ b/compilerplugins/clang/bodynotinblock.cxx @@ -32,8 +32,7 @@ void BodyNotInBlock::run() bool BodyNotInBlock::VisitFunctionDecl( FunctionDecl* declaration ) { - // TODO also LO header files? or a subdir? - if( !context.getSourceManager().isFromMainFile( declaration->getLocStart())) + if( ignoreLocation( declaration )) return true; if( !declaration->doesThisDeclarationHaveABody()) return true; diff --git a/compilerplugins/clang/compileplugin.cxx b/compilerplugins/clang/compileplugin.cxx index e5d34a32ccd5..a61a3bab66a4 100644 --- a/compilerplugins/clang/compileplugin.cxx +++ b/compilerplugins/clang/compileplugin.cxx @@ -43,6 +43,11 @@ DiagnosticBuilder Plugin::report( DiagnosticsEngine::Level level, StringRef mess return diag.Report( loc, diag.getCustomDiagID( level, message )); } +bool Plugin::ignoreLocation( SourceLocation loc ) + { + return context.getSourceManager().isInSystemHeader( context.getSourceManager().getExpansionLoc( loc )); + } + /** Class that manages all LO modules. */ diff --git a/compilerplugins/clang/compileplugin.hxx b/compilerplugins/clang/compileplugin.hxx index edf3a5ea11a8..a02b36005e4b 100644 --- a/compilerplugins/clang/compileplugin.hxx +++ b/compilerplugins/clang/compileplugin.hxx @@ -24,9 +24,24 @@ class Plugin explicit Plugin( ASTContext& context ); protected: DiagnosticBuilder report( DiagnosticsEngine::Level level, StringRef message, SourceLocation loc ); + bool ignoreLocation( SourceLocation loc ); + bool ignoreLocation( const Decl* decl ); + bool ignoreLocation( const Stmt* stmt ); ASTContext& context; }; +inline +bool Plugin::ignoreLocation( const Decl* decl ) + { + return ignoreLocation( decl->getLocStart()); + } + +inline +bool Plugin::ignoreLocation( const Stmt* stmt ) + { + return ignoreLocation( stmt->getLocStart()); + } + } // namespace #endif // COMPILEPLUGIN_H diff --git a/compilerplugins/clang/unusedvariablecheck.cxx b/compilerplugins/clang/unusedvariablecheck.cxx index a9e47b2eb316..f2916320718d 100644 --- a/compilerplugins/clang/unusedvariablecheck.cxx +++ b/compilerplugins/clang/unusedvariablecheck.cxx @@ -40,8 +40,7 @@ void UnusedVariableCheck::run() bool UnusedVariableCheck::VisitNamedDecl( NamedDecl* declaration ) { - // TODO also LO header files? or a subdir? - if( !context.getSourceManager().isFromMainFile( declaration->getLocStart())) + if( ignoreLocation( declaration )) return true; if( !isa< VarDecl >( declaration )) return true; -- cgit