[PATCH] Fixing a driver bug where clang cannot locate source file at drive root

Yunzhong Gao Yunzhong_Gao at playstation.sony.com
Mon Jul 1 10:11:48 PDT 2013


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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D937.1.patch
Type: text/x-patch
Size: 722 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130701/bd8ef6cf/attachment.bin>


More information about the cfe-commits mailing list