[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.

llvm-svn: 266089
This commit is contained in:
David Majnemer 2016-04-12 16:33:53 +00:00
parent 279970c0dc
commit 1834dc7520
1 changed files with 1 additions and 1 deletions

View File

@ -123,7 +123,7 @@ static const DirectoryEntry *getDirectoryFromFile(FileManager &FileMgr,
void FileManager::addAncestorsAsVirtualDirs(StringRef Path) { void FileManager::addAncestorsAsVirtualDirs(StringRef Path) {
StringRef DirName = llvm::sys::path::parent_path(Path); StringRef DirName = llvm::sys::path::parent_path(Path);
if (DirName.empty()) if (DirName.empty())
return; DirName = ".";
auto &NamedDirEnt = auto &NamedDirEnt =
*SeenDirEntries.insert(std::make_pair(DirName, nullptr)).first; *SeenDirEntries.insert(std::make_pair(DirName, nullptr)).first;