From: Seth Cantrell Date: Thu, 24 May 2012 05:14:44 +0000 (+0000) Subject: fix Bug 12924 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c5493d7d60005fc8aa9b0e06d326026a9f9a688d;p=clang fix Bug 12924 http://llvm.org/bugs/show_bug.cgi?id=12924 This issue was that the source location was pointing to a non-printable character and so CaretEnd was pointing one _column_ past the caret but not one _character_ past the caret. So the conversion between column and byte locations wasn't working (because the conversion is only valid from the first column or byte of a character). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@157372 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Frontend/TextDiagnostic.cpp b/lib/Frontend/TextDiagnostic.cpp index 454018b296..663dc96af7 100644 --- a/lib/Frontend/TextDiagnostic.cpp +++ b/lib/Frontend/TextDiagnostic.cpp @@ -333,6 +333,22 @@ static void selectInterestingSourceRegion(std::string &SourceLine, CaretEnd = std::max(FixItEnd, CaretEnd); } + // CaretEnd may have been set at the middle of a character + // If it's not at a character's first column then advance it past the current + // character. + while (static_cast(CaretEnd) < map.columns() && + -1 == map.columnToByte(CaretEnd)) + ++CaretEnd; + + assert((static_cast(CaretStart) > map.columns() || + -1!=map.columnToByte(CaretStart)) && + "CaretStart must not point to a column in the middle of a source" + " line character"); + assert((static_cast(CaretEnd) > map.columns() || + -1!=map.columnToByte(CaretEnd)) && + "CaretEnd must not point to a column in the middle of a source line" + " character"); + // CaretLine[CaretStart, CaretEnd) contains all of the interesting // parts of the caret line. While this slice is smaller than the // number of columns we have, try to grow the slice to encompass