diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-09-20 22:14:54 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-09-20 22:14:54 +0000 |
commit | 7c2b28a16f0eb745aad265eb5de751483b5cd24c (patch) | |
tree | 8082309345ade1cc7b1bd50cef4521a916eaca08 /clang/lib/Basic/SourceManager.cpp | |
parent | b89327ec84443df78b51ce83b3ae2d591d02448f (diff) | |
download | bcm5719-llvm-7c2b28a16f0eb745aad265eb5de751483b5cd24c.tar.gz bcm5719-llvm-7c2b28a16f0eb745aad265eb5de751483b5cd24c.zip |
In SourceManager::translateLineCol, handle the case where we are pointing
directly at the end of the source file.
llvm-svn: 140192
Diffstat (limited to 'clang/lib/Basic/SourceManager.cpp')
-rw-r--r-- | clang/lib/Basic/SourceManager.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index 68c98fe02c6..f15c5dc3345 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -1453,8 +1453,10 @@ SourceLocation SourceManager::translateLineCol(FileID FID, if (!Entry.isFile()) return SourceLocation(); + SourceLocation FileLoc = SourceLocation::getFileLoc(Entry.getOffset()); + if (Line == 1 && Col == 1) - return getLocForStartOfFile(FID); + return FileLoc; ContentCache *Content = const_cast<ContentCache *>(Entry.getFile().getContentCache()); @@ -1474,21 +1476,24 @@ SourceLocation SourceManager::translateLineCol(FileID FID, unsigned Size = Content->getBuffer(Diag, *this)->getBufferSize(); if (Size > 0) --Size; - return getLocForStartOfFile(FID).getLocWithOffset(Size); + return FileLoc.getLocWithOffset(Size); } unsigned FilePos = Content->SourceLineCache[Line - 1]; const char *Buf = Content->getBuffer(Diag, *this)->getBufferStart() + FilePos; unsigned BufLength = Content->getBuffer(Diag, *this)->getBufferEnd() - Buf; + if (BufLength == 0) + return FileLoc.getLocWithOffset(FilePos); + unsigned i = 0; // Check that the given column is valid. while (i < BufLength-1 && i < Col-1 && Buf[i] != '\n' && Buf[i] != '\r') ++i; if (i < Col-1) - return getLocForStartOfFile(FID).getLocWithOffset(FilePos + i); + return FileLoc.getLocWithOffset(FilePos + i); - return getLocForStartOfFile(FID).getLocWithOffset(FilePos + Col - 1); + return FileLoc.getLocWithOffset(FilePos + Col - 1); } /// \brief Compute a map of macro argument chunks to their expanded source |