summaryrefslogtreecommitdiffstats
path: root/clang/lib/Basic/FileManager.cpp
diff options
context:
space:
mode:
authorAlex Lorenz <arphaman@gmail.com>2019-08-31 01:26:04 +0000
committerAlex Lorenz <arphaman@gmail.com>2019-08-31 01:26:04 +0000
commit0377ca641c9af0262270d091578cab19523b1bc6 (patch)
tree07dd78901eff6d926370fdd5414576a90fdfd40e /clang/lib/Basic/FileManager.cpp
parent09490012afde4ef89165f42d143e18a81e7a1054 (diff)
downloadbcm5719-llvm-0377ca641c9af0262270d091578cab19523b1bc6.tar.gz
bcm5719-llvm-0377ca641c9af0262270d091578cab19523b1bc6.zip
Introduce a DirectoryEntryRef that stores both a reference and an
accessed name to the directory entry This commit introduces a parallel API that returns a DirectoryEntryRef to the FileManager, similar to the parallel FileEntryRef API. All uses will have to be update in follow-up patches. The immediate use of the new API in this patch fixes the issue where a file manager was reused in clang-scan-deps, but reported an different file path whenever a framework lookup was done through a symlink. Differential Revision: https://reviews.llvm.org/D67026 llvm-svn: 370562
Diffstat (limited to 'clang/lib/Basic/FileManager.cpp')
-rw-r--r--clang/lib/Basic/FileManager.cpp31
1 files changed, 17 insertions, 14 deletions
diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp
index cc6c2613fb3..f14bd0884a0 100644
--- a/clang/lib/Basic/FileManager.cpp
+++ b/clang/lib/Basic/FileManager.cpp
@@ -107,16 +107,8 @@ void FileManager::addAncestorsAsVirtualDirs(StringRef Path) {
addAncestorsAsVirtualDirs(DirName);
}
-/// Converts a llvm::ErrorOr<T &> to an llvm::ErrorOr<T *> by promoting
-/// the address of the inner reference to a pointer or by propagating the error.
-template <typename T>
-static llvm::ErrorOr<T *> promoteInnerReference(llvm::ErrorOr<T &> value) {
- if (value) return &*value;
- return value.getError();
-}
-
-llvm::ErrorOr<const DirectoryEntry *>
-FileManager::getDirectory(StringRef DirName, bool CacheFailure) {
+llvm::Expected<DirectoryEntryRef>
+FileManager::getDirectoryRef(StringRef DirName, bool CacheFailure) {
// stat doesn't like trailing separators except for root directory.
// At least, on Win32 MSVCRT, stat() cannot strip trailing '/'.
// (though it can strip '\\')
@@ -141,8 +133,11 @@ FileManager::getDirectory(StringRef DirName, bool CacheFailure) {
// contains both virtual and real directories.
auto SeenDirInsertResult =
SeenDirEntries.insert({DirName, std::errc::no_such_file_or_directory});
- if (!SeenDirInsertResult.second)
- return promoteInnerReference(SeenDirInsertResult.first->second);
+ if (!SeenDirInsertResult.second) {
+ if (SeenDirInsertResult.first->second)
+ return DirectoryEntryRef(&*SeenDirInsertResult.first);
+ return llvm::errorCodeToError(SeenDirInsertResult.first->second.getError());
+ }
// We've not seen this before. Fill it in.
++NumDirCacheMisses;
@@ -163,7 +158,7 @@ FileManager::getDirectory(StringRef DirName, bool CacheFailure) {
NamedDirEnt.second = statError;
else
SeenDirEntries.erase(DirName);
- return statError;
+ return llvm::errorCodeToError(statError);
}
// It exists. See if we have already opened a directory with the
@@ -179,7 +174,15 @@ FileManager::getDirectory(StringRef DirName, bool CacheFailure) {
UDE.Name = InterndDirName;
}
- return &UDE;
+ return DirectoryEntryRef(&NamedDirEnt);
+}
+
+llvm::ErrorOr<const DirectoryEntry *>
+FileManager::getDirectory(StringRef DirName, bool CacheFailure) {
+ auto Result = getDirectoryRef(DirName, CacheFailure);
+ if (Result)
+ return &Result->getDirEntry();
+ return llvm::errorToErrorCode(Result.takeError());
}
llvm::ErrorOr<const FileEntry *>
OpenPOWER on IntegriCloud