ygao added you to the CC list for the revision "Fixing a driver bug where clang 
cannot locate source file at drive root".

Hi,
If I run the following command on Windows, I get an error that clang cannot 
find the source file. MinGW/GCC seems to work fine.

C:> clang C:test.c
error: error reading 'C:test.c'
1 error generated.

This change attempts to fix it by patching the directory name if the directory 
name is the same as a drive name.

I am not sure how to write a regression test for this bug :(
Any suggestions? Maybe write a test that copies itself to the drive root at the 
beginning of the RUN line?

Would appreciate it if someone could review and commit this for me.

Many thanks,
- Gao.

http://llvm-reviews.chandlerc.com/D937

Files:
  lib/Basic/FileManager.cpp

Index: lib/Basic/FileManager.cpp
===================================================================
--- lib/Basic/FileManager.cpp
+++ lib/Basic/FileManager.cpp
@@ -293,6 +293,14 @@
       llvm::sys::path::is_separator(DirName.back()))
     DirName = DirName.substr(0, DirName.size()-1);
 
+#ifdef LLVM_ON_WIN32
+  // Fixing a problem with "clang C:test.c" on Windows.
+  // Stat("C:") does not recognize "C:" as a valid directory
+  if (DirName.size() > 1 && DirName.back() == ':' &&
+      DirName.equals_lower(llvm::sys::path::root_name(DirName)))
+    DirName = DirName.str() + '\\';
+#endif
+
   ++NumDirLookups;
   llvm::StringMapEntry<DirectoryEntry *> &NamedDirEnt =
     SeenDirEntries.GetOrCreateValue(DirName);
Index: lib/Basic/FileManager.cpp
===================================================================
--- lib/Basic/FileManager.cpp
+++ lib/Basic/FileManager.cpp
@@ -293,6 +293,14 @@
       llvm::sys::path::is_separator(DirName.back()))
     DirName = DirName.substr(0, DirName.size()-1);
 
+#ifdef LLVM_ON_WIN32
+  // Fixing a problem with "clang C:test.c" on Windows.
+  // Stat("C:") does not recognize "C:" as a valid directory
+  if (DirName.size() > 1 && DirName.back() == ':' &&
+      DirName.equals_lower(llvm::sys::path::root_name(DirName)))
+    DirName = DirName.str() + '\\';
+#endif
+
   ++NumDirLookups;
   llvm::StringMapEntry<DirectoryEntry *> &NamedDirEnt =
     SeenDirEntries.GetOrCreateValue(DirName);
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to