[PATCH] Fix for include file resolution on Windows

Sharif Elcott sharifelcottclangllvm at mailinator.com
Thu Jan 8 08:28:50 PST 2015


http://reviews.llvm.org/D6871

Files:
  lib/Basic/FileManager.cpp
  lib/Lex/HeaderSearch.cpp
  lib/Lex/PPDirectives.cpp

Index: lib/Lex/HeaderSearch.cpp
===================================================================
--- lib/Lex/HeaderSearch.cpp
+++ lib/Lex/HeaderSearch.cpp
@@ -613,10 +613,8 @@
       const FileEntry *Includer = IncluderAndDir.first;

       // Concatenate the requested file onto the directory.
-      // FIXME: Portability.  Filename concatenation should be in sys::Path.
       TmpDir = IncluderAndDir.second->getName();
-      TmpDir.push_back('/');
-      TmpDir.append(Filename.begin(), Filename.end());
+      llvm::sys::path::append(TmpDir, Filename);

       // FIXME: We don't cache the result of getFileInfo across the call to
       // getFileAndSuggestModule, because it's a reference to an element of
Index: lib/Lex/PPDirectives.cpp
===================================================================
--- lib/Lex/PPDirectives.cpp
+++ lib/Lex/PPDirectives.cpp
@@ -1553,9 +1553,7 @@
   SmallString<128> NormalizedPath;
   if (LangOpts.MSVCCompat) {
     NormalizedPath = Filename.str();
-#ifndef LLVM_ON_WIN32
     llvm::sys::path::native(NormalizedPath);
-#endif
   }
   const FileEntry *File = LookupFile(
       FilenameLoc, LangOpts.MSVCCompat ? NormalizedPath.c_str() : Filename,
Index: lib/Basic/FileManager.cpp
===================================================================
--- lib/Basic/FileManager.cpp
+++ lib/Basic/FileManager.cpp
@@ -332,10 +332,35 @@
   if (NamedFileEnt.second && NamedFileEnt.second != NON_EXISTENT_FILE)
     return NamedFileEnt.second;
 
+  // The file name should probably be added to the map in its normalized form
+  // so that searches for the same file in a different form will find it. But
+  // instead of doing that, in order to maintain backwards compatibility I'll
+  // keep the original entry and add a second one in addition to it, keyed on
+  // the normalized form and pointing to the same FileEntry.
+  // Note that this is only necessary here in getVirtualFile but not getFile
+  // because in the case of getFile the key is always the path returned by the
+  // OS after stat'ing the file, which is always the same.
+  SmallString<128> NormalizedPath = Filename;
+  llvm::sys::path::native(NormalizedPath);
+  auto *NormalizedNamedFileEnt = &NamedFileEnt;
+  if (!NormalizedPath.equals(Filename)) {
+    NormalizedNamedFileEnt = &*SeenFileEntries.insert(
+      std::make_pair(NormalizedPath.c_str(), nullptr)).first;
+
+    // If this search succeeded then the file has already been added but in a
+    // different form. This will add another entry corresponding to the form
+    // that was just queried.
+    if (NormalizedNamedFileEnt->second &&
+        NormalizedNamedFileEnt->second != NON_EXISTENT_FILE) {
+      NamedFileEnt.second = NormalizedNamedFileEnt->second;
+      return NormalizedNamedFileEnt->second;
+    }
+  }
+
   ++NumFileCacheMisses;
 
   // By default, initialize it to invalid.
-  NamedFileEnt.second = NON_EXISTENT_FILE;
+  NamedFileEnt.second = NormalizedNamedFileEnt->second = NON_EXISTENT_FILE;
 
   addAncestorsAsVirtualDirs(Filename);
   FileEntry *UFE = nullptr;
@@ -356,7 +381,7 @@
     Data.ModTime = ModificationTime;
     UFE = &UniqueRealFiles[Data.UniqueID];
 
-    NamedFileEnt.second = UFE;
+    NamedFileEnt.second = NormalizedNamedFileEnt->second = UFE;
 
     // If we had already opened this file, close it now so we don't
     // leak the descriptor. We're not going to use the file
@@ -376,7 +401,7 @@
   if (!UFE) {
     UFE = new FileEntry();
     VirtualFileEntries.push_back(UFE);
-    NamedFileEnt.second = UFE;
+    NamedFileEnt.second = NormalizedNamedFileEnt->second = UFE;
   }
 
   UFE->Name    = InterndFileName;

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D6871.17899.patch
Type: text/x-patch
Size: 3643 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150108/bc3c66c1/attachment.bin>


More information about the cfe-commits mailing list