[PATCH] D11944: Nativize filename in FileManager::getFile().

Manuel Klimek via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 11 07:15:23 PDT 2015


klimek created this revision.
klimek added reviewers: rsmith, chapuni.
klimek added a subscriber: cfe-commits.

For virtual files to work correctly on Windows, we need to canonicalize
the paths before looking into the caches.

This is basically a request for comments - if we want to go this route, I will
make all FileManager methods canonicalize the paths.

http://reviews.llvm.org/D11944

Files:
  lib/Basic/FileManager.cpp

Index: lib/Basic/FileManager.cpp
===================================================================
--- lib/Basic/FileManager.cpp
+++ lib/Basic/FileManager.cpp
@@ -218,9 +218,12 @@
                                       bool CacheFailure) {
   ++NumFileLookups;
 
+  SmallString<1024> NativeFilename;
+  llvm::sys::path::native(Filename, NativeFilename);
+
   // See if there is already an entry in the map.
   auto &NamedFileEnt =
-      *SeenFileEntries.insert(std::make_pair(Filename, nullptr)).first;
+      *SeenFileEntries.insert(std::make_pair(NativeFilename, nullptr)).first;
 
   // See if there is already an entry in the map.
   if (NamedFileEnt.second)
@@ -241,11 +244,11 @@
   // subdirectory.  This will let us avoid having to waste time on known-to-fail
   // searches when we go to find sys/bar.h, because all the search directories
   // without a 'sys' subdir will get a cached failure result.
-  const DirectoryEntry *DirInfo = getDirectoryFromFile(*this, Filename,
+  const DirectoryEntry *DirInfo = getDirectoryFromFile(*this, NativeFilename,
                                                        CacheFailure);
   if (DirInfo == nullptr) { // Directory doesn't exist, file can't exist.
     if (!CacheFailure)
-      SeenFileEntries.erase(Filename);
+      SeenFileEntries.erase(NativeFilename);
 
     return nullptr;
   }
@@ -259,7 +262,7 @@
   if (getStatValue(InterndFileName, Data, true, openFile ? &F : nullptr)) {
     // There's no real file at the given path.
     if (!CacheFailure)
-      SeenFileEntries.erase(Filename);
+      SeenFileEntries.erase(NativeFilename);
 
     return nullptr;
   }
@@ -272,9 +275,9 @@
 
   NamedFileEnt.second = &UFE;
 
-  // If the name returned by getStatValue is different than Filename, re-intern
+  // If the name returned by getStatValue is different than NativeFilename, re-intern
   // the name.
-  if (Data.Name != Filename) {
+  if (Data.Name != NativeFilename) {
     auto &NamedFileEnt =
         *SeenFileEntries.insert(std::make_pair(Data.Name, nullptr)).first;
     if (!NamedFileEnt.second)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11944.31813.patch
Type: text/x-patch
Size: 2074 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150811/63be21f0/attachment.bin>


More information about the cfe-commits mailing list