[PATCH] D31713: [Basic] getColumnNumber returns location of CR+LF on Windows
Chih-Hung Hsieh via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 5 09:54:59 PDT 2017
chh created this revision.
When fixing a Clang-Tidy bug in https://reviews.llvm.org/D31406,
http://bugs.llvm.org/show_bug.cgi?id=32402,
reuse of FileID enabled the missing highlightRange function.
Assertion in highlightRange failed because the end-of-range column
number was 2 + the last column of a line on Windows.
This fix is required to enable https://reviews.llvm.org/D31406.
Repository:
rL LLVM
https://reviews.llvm.org/D31713
Files:
lib/Basic/SourceManager.cpp
Index: lib/Basic/SourceManager.cpp
===================================================================
--- lib/Basic/SourceManager.cpp
+++ lib/Basic/SourceManager.cpp
@@ -1144,8 +1144,18 @@
unsigned *SourceLineCache = LastLineNoContentCache->SourceLineCache;
unsigned LineStart = SourceLineCache[LastLineNoResult - 1];
unsigned LineEnd = SourceLineCache[LastLineNoResult];
- if (FilePos >= LineStart && FilePos < LineEnd)
+ if (FilePos >= LineStart && FilePos < LineEnd) {
+ // LineEnd is the LineStart of the next line.
+ // A line ends with separator LF or CR+LF on Windows.
+ // FilePos might point to the last separator,
+ // but we need a column number at most 1 + the last column.
+ if (FilePos + 1 == LineEnd && FilePos > LineStart) {
+ const char *Buf = MemBuf->getBufferStart();
+ if (Buf[FilePos - 1] == '\r' || Buf[FilePos - 1] == '\n')
+ --FilePos;
+ }
return FilePos - LineStart + 1;
+ }
}
const char *Buf = MemBuf->getBufferStart();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31713.94249.patch
Type: text/x-patch
Size: 1039 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170405/7fcbc461/attachment.bin>
More information about the cfe-commits
mailing list