[llvm-branch-commits] [cfe-branch] r125370 - /cfe/branches/Apple/whitney/lib/Basic/SourceManager.cpp

Daniel Dunbar daniel at zuster.org
Fri Feb 11 09:19:32 PST 2011


Author: ddunbar
Date: Fri Feb 11 11:19:32 2011
New Revision: 125370

URL: http://llvm.org/viewvc/llvm-project?rev=125370&view=rev
Log:
Merge r124800:
--
Author: Douglas Gregor <dgregor at apple.com>
Date:   Thu Feb 3 17:17:35 2011 +0000

    Teach SourceManager::getLocation() how to cope with a source file
    whose inode has changed since the file was first created and that is
    being seen through a different path name (e.g., due to symlinks or
    relative path elements), such that its FileEntry pointer doesn't match
    a known FileEntry pointer. Since this requires a system call (to
    stat()), we only perform this deeper checking if we can't find the
    file by comparing FileEntry pointers.

    Also, add a micro-optimization where we don't bother to compute line
    numbers when given the location (1, 1). This improves the
    efficiency of clang_getLocationForOffset().

*** CUSTOM MERGE ***

Modified:
    cfe/branches/Apple/whitney/lib/Basic/SourceManager.cpp

Modified: cfe/branches/Apple/whitney/lib/Basic/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/lib/Basic/SourceManager.cpp?rev=125370&r1=125369&r2=125370&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/Basic/SourceManager.cpp (original)
+++ cfe/branches/Apple/whitney/lib/Basic/SourceManager.cpp Fri Feb 11 11:19:32 2011
@@ -1130,6 +1130,16 @@
   return StatBuf.st_ino;
 }
 
+template<typename T>
+bool operator==(const llvm::Optional<T> &X, const llvm::Optional<T> &Y) {
+  return (!X && !Y) || (X && Y && *X == *Y);
+}
+
+template<typename T>
+bool operator!=(const llvm::Optional<T> &X, const llvm::Optional<T> &Y) {
+  return !(X == Y);
+}
+
 /// \brief Get the source location for the given file:line:col triplet.
 ///
 /// If the source file is included multiple times, the source location will
@@ -1145,15 +1155,17 @@
   // First, check the main file ID, since it is common to look for a
   // location in the main file.
   llvm::Optional<ino_t> SourceFileInode;
-  llvm::Optional<llvm::StringRef> SourceFileName;
+  llvm::Optional<std::string> SourceFileName;
   if (!MainFileID.isInvalid()) {
     const SLocEntry &MainSLoc = getSLocEntry(MainFileID);
     if (MainSLoc.isFile()) {
       const ContentCache *MainContentCache
         = MainSLoc.getFile().getContentCache();
-      if (MainContentCache->Entry == SourceFile)
+      if (!MainContentCache) {
+        // Can't do anything
+      } else if (MainContentCache->Entry == SourceFile) {
         FirstFID = MainFileID;
-      else if (MainContentCache) {
+      } else {
         // Fall back: check whether we have the same base name and inode
         // as the main file.
         const FileEntry *MainFile = MainContentCache->Entry;





More information about the llvm-branch-commits mailing list