From ef91bd38cd94e34b4b0a30e225e507f5c10087d3 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Mon, 30 Apr 2018 05:25:48 +0000 Subject: PR37189 Fix incorrect end source location and spelling for a split '>>' token. When a '>>' token is split into two '>' tokens (in C++11 onwards), or (as an extension) when we do the same for other tokens starting with a '>', we can't just use a location pointing to the first '>' as the location of the split token, because that would result in our miscomputing the length and spelling for the token. As a consequence, for example, a refactoring replacing 'A' with something else would sometimes replace one character too many, and similarly diagnostics highlighting a template-id source range would highlight one character too many. Fix this by creating an expansion range covering the first character of the '>>' token, whose spelling is '>'. For this to work, we generalize the expansion range of a macro FileID to be either a token range (the common case) or a character range (used in this new case). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@331155 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Edit/EditedSource.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'lib/Edit') diff --git a/lib/Edit/EditedSource.cpp b/lib/Edit/EditedSource.cpp index 0ff2447f77..89a3eb40d0 100644 --- a/lib/Edit/EditedSource.cpp +++ b/lib/Edit/EditedSource.cpp @@ -36,12 +36,14 @@ void EditedSource::deconstructMacroArgLoc(SourceLocation Loc, SourceLocation &ExpansionLoc, MacroArgUse &ArgUse) { assert(SourceMgr.isMacroArgExpansion(Loc)); - SourceLocation DefArgLoc = SourceMgr.getImmediateExpansionRange(Loc).first; + SourceLocation DefArgLoc = + SourceMgr.getImmediateExpansionRange(Loc).getBegin(); SourceLocation ImmediateExpansionLoc = - SourceMgr.getImmediateExpansionRange(DefArgLoc).first; + SourceMgr.getImmediateExpansionRange(DefArgLoc).getBegin(); ExpansionLoc = ImmediateExpansionLoc; while (SourceMgr.isMacroBodyExpansion(ExpansionLoc)) - ExpansionLoc = SourceMgr.getImmediateExpansionRange(ExpansionLoc).first; + ExpansionLoc = + SourceMgr.getImmediateExpansionRange(ExpansionLoc).getBegin(); SmallString<20> Buf; StringRef ArgName = Lexer::getSpelling(SourceMgr.getSpellingLoc(DefArgLoc), Buf, SourceMgr, LangOpts); -- cgit v1.2.3