r187359 - Fix handling of "clang c:foo"
Rafael Espindola
rafael.espindola at gmail.com
Mon Jul 29 08:47:24 PDT 2013
Author: rafael
Date: Mon Jul 29 10:47:24 2013
New Revision: 187359
URL: http://llvm.org/viewvc/llvm-project?rev=187359&view=rev
Log:
Fix handling of "clang c:foo"
On windows, c:foo is a valid file path, but stat fails on just "c:". This
causes a problem for clang since its file manager wants to cache data about
the parent directory.
There are refactorings to be done in here, but this gives clang the correct
behavior and testing first.
Patch by Yunzhong Gao!
Modified:
cfe/trunk/lib/Basic/FileManager.cpp
cfe/trunk/unittests/Basic/FileManagerTest.cpp
Modified: cfe/trunk/lib/Basic/FileManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=187359&r1=187358&r2=187359&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/FileManager.cpp (original)
+++ cfe/trunk/lib/Basic/FileManager.cpp Mon Jul 29 10:47:24 2013
@@ -292,6 +292,16 @@ const DirectoryEntry *FileManager::getDi
DirName != llvm::sys::path::root_path(DirName) &&
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
+ std::string DirNameStr;
+ if (DirName.size() > 1 && DirName.back() == ':' &&
+ DirName.equals_lower(llvm::sys::path::root_name(DirName))) {
+ DirNameStr = DirName.str() + '.';
+ DirName = DirNameStr;
+ }
+#endif
++NumDirLookups;
llvm::StringMapEntry<DirectoryEntry *> &NamedDirEnt =
Modified: cfe/trunk/unittests/Basic/FileManagerTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Basic/FileManagerTest.cpp?rev=187359&r1=187358&r2=187359&view=diff
==============================================================================
--- cfe/trunk/unittests/Basic/FileManagerTest.cpp (original)
+++ cfe/trunk/unittests/Basic/FileManagerTest.cpp Mon Jul 29 10:47:24 2013
@@ -125,6 +125,14 @@ TEST_F(FileManagerTest, getFileReturnsVa
FakeStatCache *statCache = new FakeStatCache;
statCache->InjectDirectory("/tmp", 42);
statCache->InjectFile("/tmp/test", 43);
+
+#ifdef _WIN32
+ const char *DirName = "C:.";
+ const char *FileName = "C:test";
+ statCache->InjectDirectory(DirName, 44);
+ statCache->InjectFile(FileName, 45);
+#endif
+
manager.addStatCache(statCache);
const FileEntry *file = manager.getFile("/tmp/test");
@@ -134,6 +142,15 @@ TEST_F(FileManagerTest, getFileReturnsVa
const DirectoryEntry *dir = file->getDir();
ASSERT_TRUE(dir != NULL);
EXPECT_STREQ("/tmp", dir->getName());
+
+#ifdef _WIN32
+ file = manager.getFile(FileName);
+ ASSERT_TRUE(file != NULL);
+
+ dir = file->getDir();
+ ASSERT_TRUE(dir != NULL);
+ EXPECT_STREQ(DirName, dir->getName());
+#endif
}
// getFile() returns non-NULL if a virtual file exists at the given path.
More information about the cfe-commits
mailing list