[cfe-commits] Fix for files located in the rood directory (windows)

Nikola Smiljanic popizdeh at gmail.com
Fri Jun 15 06:32:01 PDT 2012


This patch should fix http://llvm.org/bugs/show_bug.cgi?id=10331

As you all know Clang can't read files that are located in the root
dir on Windows. This was introduced while trying to fix the fact that
::stat on windows can't work with paths that end with slash character
(this broke msys users). The solution was to remove the trailing slash
that is detected via llvm::sys::path::is_separator. But this exposed
another shortcoming of ::stat on Windows, it can't accept root dir
path that doesn't end in backslash character.

The fix is simple, do an explicit check for '/' and only truncate the
path in this case. This should cover both msys and root dir problem.
-------------- next part --------------
Index: lib/Basic/FileManager.cpp
===================================================================
--- lib/Basic/FileManager.cpp	(revision 158514)
+++ lib/Basic/FileManager.cpp	(working copy)
@@ -265,10 +265,9 @@
 ///
 const DirectoryEntry *FileManager::getDirectory(StringRef DirName,
                                                 bool CacheFailure) {
-  // stat doesn't like trailing separators.
-  // At least, on Win32 MSVCRT, stat() cannot strip trailing '/'.
-  // (though it can strip '\\')
-  if (DirName.size() > 1 && llvm::sys::path::is_separator(DirName.back()))
+  // stat() can't strip trailing '/' (though it can strip '\\') and 
+  // can't chew root dir path 'c:' without a trailing '\' on Win32 MSVCRT
+  if (DirName.size() > 1 && DirName.back() == '/')
     DirName = DirName.substr(0, DirName.size()-1);
 
   ++NumDirLookups;


More information about the cfe-commits mailing list