summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2017-10-19 21:33:08 +0200
committerStephan Bergmann <sbergman@redhat.com>2017-10-20 08:31:30 +0200
commit15dce20e8b97dbd0179f01910ca4d0027e80ff4e (patch)
treebc0a374f688bfed557c6428310d2cf04239225d1 /compilerplugins
parent2161abff3510dd591db30d94911241436c90c4d4 (diff)
Fully ignore inappropriately named loplugins in unit-test mode
...even if they implement PPCallbacks, so filtering them out in HandleTranslationUnit was ineffective. Change-Id: I9df8103a50739f3176e6d63accfd0334da7faa9a Reviewed-on: https://gerrit.libreoffice.org/43575 Reviewed-by: Stephan Bergmann <sbergman@redhat.com> Tested-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/pluginhandler.cxx11
-rw-r--r--compilerplugins/clang/pluginhandler.hxx1
2 files changed, 7 insertions, 5 deletions
diff --git a/compilerplugins/clang/pluginhandler.cxx b/compilerplugins/clang/pluginhandler.cxx
index 5712f02dcc3a..d82a369cb119 100644
--- a/compilerplugins/clang/pluginhandler.cxx
+++ b/compilerplugins/clang/pluginhandler.cxx
@@ -55,6 +55,7 @@ static bool unitTestMode = false;
PluginHandler::PluginHandler( CompilerInstance& compiler, const std::vector< std::string >& args )
: compiler( compiler )
+ , mainFileName(compiler.getASTContext().getSourceManager().getFileEntryForID(compiler.getASTContext().getSourceManager().getMainFileID())->getName())
, rewriter( compiler.getSourceManager(), compiler.getLangOpts())
, scope( "mainfile" )
, warningsAsErrors( false )
@@ -120,6 +121,10 @@ void PluginHandler::createPlugins( std::set< std::string > rewriters )
for( int i = 0; i < pluginCount; ++i )
{
const char* name = plugins[i].optionName;
+ // When in unit-test mode, ignore plugins whose names don't match the filename of the test,
+ // so that we only generate warnings for the plugin that we want to test.
+ if (unitTestMode && mainFileName.find(plugins[ i ].optionName) == StringRef::npos)
+ continue;
if( rewriters.erase( name ) != 0 )
plugins[ i ].object = plugins[ i ].create( Plugin::InstantiationData { name, *this, compiler, &rewriter } );
else if( plugins[ i ].byDefault )
@@ -179,7 +184,6 @@ void PluginHandler::HandleTranslationUnit( ASTContext& context )
{
if( context.getDiagnostics().hasErrorOccurred())
return;
- StringRef const mainFileName = context.getSourceManager().getFileEntryForID(context.getSourceManager().getMainFileID())->getName();
if (mainFileName.endswith(".ii"))
{
report(DiagnosticsEngine::Fatal,
@@ -191,10 +195,7 @@ void PluginHandler::HandleTranslationUnit( ASTContext& context )
{
if( plugins[ i ].object != NULL )
{
- // When in unit-test mode, ignore plugins whose names don't match the filename of the test,
- // so that we only generate warnings for the plugin that we want to test.
- if (!unitTestMode || mainFileName.find(plugins[ i ].optionName) != StringRef::npos)
- plugins[ i ].object->run();
+ plugins[ i ].object->run();
}
}
#if defined _WIN32
diff --git a/compilerplugins/clang/pluginhandler.hxx b/compilerplugins/clang/pluginhandler.hxx
index 9c3d0a49c839..63210fa11df4 100644
--- a/compilerplugins/clang/pluginhandler.hxx
+++ b/compilerplugins/clang/pluginhandler.hxx
@@ -43,6 +43,7 @@ private:
void createPlugins( std::set< std::string > rewriters );
DiagnosticBuilder report( DiagnosticsEngine::Level level, StringRef message, SourceLocation loc = SourceLocation());
CompilerInstance& compiler;
+ StringRef const mainFileName;
Rewriter rewriter;
std::set< SourceLocation > removals;
std::string scope;