r266089 - [FileManager] Don't crash if reading from stdin and stat(".") fails

David Majnemer via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 12 09:33:54 PDT 2016


Author: majnemer
Date: Tue Apr 12 11:33:53 2016
New Revision: 266089

URL: http://llvm.org/viewvc/llvm-project?rev=266089&view=rev
Log:
[FileManager] Don't crash if reading from stdin and stat(".") fails

addAncestorsAsVirtualDirs("<stdin>") quickly returns without doing work
because "<stdin>" has no parent_path.  This violates the expectation
that a subsequent call to getDirectoryFromFile("<stdin>") would succeed.
Instead, it fails because it uses the "." if the file has no path
component.

Fix this by keeping the behavior between addAncestorsAsVirtualDirs and
getDirectoryFromFile symmetric.

Modified:
    cfe/trunk/lib/Basic/FileManager.cpp

Modified: cfe/trunk/lib/Basic/FileManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=266089&r1=266088&r2=266089&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/FileManager.cpp (original)
+++ cfe/trunk/lib/Basic/FileManager.cpp Tue Apr 12 11:33:53 2016
@@ -123,7 +123,7 @@ static const DirectoryEntry *getDirector
 void FileManager::addAncestorsAsVirtualDirs(StringRef Path) {
   StringRef DirName = llvm::sys::path::parent_path(Path);
   if (DirName.empty())
-    return;
+    DirName = ".";
 
   auto &NamedDirEnt =
       *SeenDirEntries.insert(std::make_pair(DirName, nullptr)).first;




More information about the cfe-commits mailing list