[cfe-commits] r140192 - /cfe/trunk/lib/Basic/SourceManager.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Tue Sep 20 15:14:54 PDT 2011


Author: akirtzidis
Date: Tue Sep 20 17:14:54 2011
New Revision: 140192

URL: http://llvm.org/viewvc/llvm-project?rev=140192&view=rev
Log:
In SourceManager::translateLineCol, handle the case where we are pointing
directly at the end of the source file.

Modified:
    cfe/trunk/lib/Basic/SourceManager.cpp

Modified: cfe/trunk/lib/Basic/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/SourceManager.cpp?rev=140192&r1=140191&r2=140192&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/SourceManager.cpp (original)
+++ cfe/trunk/lib/Basic/SourceManager.cpp Tue Sep 20 17:14:54 2011
@@ -1453,8 +1453,10 @@
   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 @@
     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





More information about the cfe-commits mailing list