From 75f41baab6ce75786a91fe461835ee16a23ec18e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Lu=C5=88=C3=A1k?= Date: Tue, 20 Aug 2013 19:42:16 +0200 Subject: [PATCH] warn when rewriter should modify something involving a macro Apparently Clang rewriter API doesn't properly bail out if the range given is not inside one file, so check explicitly. Change-Id: I27be6d396a131d385231e9c0dfa8c84d9fa15ccc --- compilerplugins/clang/plugin.cxx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/compilerplugins/clang/plugin.cxx b/compilerplugins/clang/plugin.cxx index 65333025e576..064bfa5b91a7 100644 --- a/compilerplugins/clang/plugin.cxx +++ b/compilerplugins/clang/plugin.cxx @@ -199,6 +199,8 @@ bool RewritePlugin::removeText( SourceRange range, RewriteOptions opts ) bool RewritePlugin::removeText( CharSourceRange range, RewriteOptions opts ) { + if( rewriter.getRangeSize( range, opts ) == -1 ) + return reportEditFailure( range.getBegin()); if( removals.find( range.getBegin()) != removals.end()) report( DiagnosticsEngine::Warning, "double code removal, possible plugin error", range.getBegin()); removals.insert( range.getBegin()); @@ -264,6 +266,8 @@ bool RewritePlugin::replaceText( SourceLocation Start, unsigned OrigLength, Stri bool RewritePlugin::replaceText( SourceRange range, StringRef NewStr ) { + if( rewriter.getRangeSize( range ) == -1 ) + return reportEditFailure( range.getBegin()); if( removals.find( range.getBegin()) != removals.end()) report( DiagnosticsEngine::Warning, "double code replacement, possible plugin error", range.getBegin()); removals.insert( range.getBegin()); @@ -274,6 +278,8 @@ bool RewritePlugin::replaceText( SourceRange range, StringRef NewStr ) bool RewritePlugin::replaceText( SourceRange range, SourceRange replacementRange ) { + if( rewriter.getRangeSize( range ) == -1 ) + return reportEditFailure( range.getBegin()); if( removals.find( range.getBegin()) != removals.end()) report( DiagnosticsEngine::Warning, "double code replacement, possible plugin error", range.getBegin()); removals.insert( range.getBegin());