summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@suse.cz>2013-05-03 16:40:51 +0200
committerLuboš Luňák <l.lunak@suse.cz>2013-05-06 16:49:36 +0200
commita0da672521f806d11f9922601328de3ab0542187 (patch)
tree33d765973014ef4955aae252551a52fd5cab341f /compilerplugins
parent6f16cfb5a661c0a4b13ed18c9246d8830ca118b5 (diff)
ignore already seen locations in compiler plugins
Change-Id: Icba8dfa61aee7237af569b2414b1cf4ce93ca476
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/plugin.cxx21
-rw-r--r--compilerplugins/clang/plugin.hxx1
2 files changed, 16 insertions, 6 deletions
diff --git a/compilerplugins/clang/plugin.cxx b/compilerplugins/clang/plugin.cxx
index 85bd69625b09..bfcec730003d 100644
--- a/compilerplugins/clang/plugin.cxx
+++ b/compilerplugins/clang/plugin.cxx
@@ -56,12 +56,21 @@ bool Plugin::ignoreLocation( SourceLocation loc )
const char* bufferName = compiler.getSourceManager().getPresumedLoc( expansionLoc ).getFilename();
if( bufferName == NULL )
return true;
- if( strncmp( bufferName, OUTDIR, strlen( OUTDIR )) == 0
- || strncmp( bufferName, WORKDIR, strlen( WORKDIR )) == 0
- || strncmp( bufferName, BUILDDIR, strlen( BUILDDIR )) == 0
- || strncmp( bufferName, SRCDIR, strlen( SRCDIR )) == 0 )
- return false; // ok
- return true;
+ if( strncmp( bufferName, OUTDIR, strlen( OUTDIR )) != 0
+ && strncmp( bufferName, WORKDIR, strlen( WORKDIR )) != 0
+ && strncmp( bufferName, BUILDDIR, strlen( BUILDDIR )) != 0
+ && strncmp( bufferName, SRCDIR, strlen( SRCDIR )) != 0 )
+ return true; // not in LO sources
+ // Sometimes a VisitXXX function may be called more than once for one source location.
+ // This can happen e.g. with a default argument for a function, if it involves constructing
+ // a temporary, then this temporary will be constructed whenever the function is called
+ // and the default argument is needed. As this would mean processing the same piece of code
+ // more than once, and thus possibly modifying the source code more than once, just
+ // ignore an already seen location.
+ if( alreadySeen.find( loc ) != alreadySeen.end())
+ return true;
+ alreadySeen.insert( loc );
+ return false;
}
void Plugin::registerPlugin( Plugin* (*create)( CompilerInstance&, Rewriter& ), const char* optionName, bool isRewriter )
diff --git a/compilerplugins/clang/plugin.hxx b/compilerplugins/clang/plugin.hxx
index da336818cccb..52f6273e16e2 100644
--- a/compilerplugins/clang/plugin.hxx
+++ b/compilerplugins/clang/plugin.hxx
@@ -53,6 +53,7 @@ class Plugin
bool ignoreLocation( const Decl* decl );
bool ignoreLocation( const Stmt* stmt );
CompilerInstance& compiler;
+ set< SourceLocation > alreadySeen;
private:
static void registerPlugin( Plugin* (*create)( CompilerInstance&, Rewriter& ), const char* optionName, bool isRewriter );
template< typename T > static Plugin* createHelper( CompilerInstance& compiler, Rewriter& rewriter );