summaryrefslogtreecommitdiffstats
path: root/llvm/lib/LTO/Caching.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/LTO/Caching.cpp')
-rw-r--r--llvm/lib/LTO/Caching.cpp19
1 files changed, 10 insertions, 9 deletions
diff --git a/llvm/lib/LTO/Caching.cpp b/llvm/lib/LTO/Caching.cpp
index 7b3fc020d6e..000ab91dba7 100644
--- a/llvm/lib/LTO/Caching.cpp
+++ b/llvm/lib/LTO/Caching.cpp
@@ -38,22 +38,23 @@ Expected<NativeObjectCache> lto::localCache(StringRef CacheDirectoryPath,
SmallString<64> EntryPath;
sys::path::append(EntryPath, CacheDirectoryPath, "llvmcache-" + Key);
// First, see if we have a cache hit.
- int FD;
SmallString<64> ResultPath;
- std::error_code EC = sys::fs::openFileForRead(
- Twine(EntryPath), FD, sys::fs::OF_UpdateAtime, &ResultPath);
- if (!EC) {
+ Expected<sys::fs::file_t> FDOrErr = sys::fs::openNativeFileForRead(
+ Twine(EntryPath), sys::fs::OF_UpdateAtime, &ResultPath);
+ std::error_code EC;
+ if (FDOrErr) {
ErrorOr<std::unique_ptr<MemoryBuffer>> MBOrErr =
- MemoryBuffer::getOpenFile(sys::fs::convertFDToNativeFile(FD),
- EntryPath,
- /*FileSize*/ -1,
- /*RequiresNullTerminator*/ false);
- close(FD);
+ MemoryBuffer::getOpenFile(*FDOrErr, EntryPath,
+ /*FileSize=*/-1,
+ /*RequiresNullTerminator=*/false);
+ sys::fs::closeFile(*FDOrErr);
if (MBOrErr) {
AddBuffer(Task, std::move(*MBOrErr));
return AddStreamFn();
}
EC = MBOrErr.getError();
+ } else {
+ EC = errorToErrorCode(FDOrErr.takeError());
}
// On Windows we can fail to open a cache file with a permission denied
OpenPOWER on IntegriCloud