summaryrefslogtreecommitdiffstats
path: root/llvm/lib/LTO
diff options
context:
space:
mode:
authorReid Kleckner <rnk@google.com>2019-07-11 20:29:32 +0000
committerReid Kleckner <rnk@google.com>2019-07-11 20:29:32 +0000
commitf002fcb2ad64a75a2f0aea3eb067614f4681284b (patch)
treee13291958d4eaad57805ed119666bb5c52d04969 /llvm/lib/LTO
parentf4af9a9d806f0471a94d9c803c581e9ef1ea9424 (diff)
downloadbcm5719-llvm-f002fcb2ad64a75a2f0aea3eb067614f4681284b.tar.gz
bcm5719-llvm-f002fcb2ad64a75a2f0aea3eb067614f4681284b.zip
Open native file handles to avoid converting from FDs, NFC
Follow up to r365588. llvm-svn: 365820
Diffstat (limited to 'llvm/lib/LTO')
-rw-r--r--llvm/lib/LTO/Caching.cpp19
-rw-r--r--llvm/lib/LTO/ThinLTOCodeGenerator.cpp14
2 files changed, 16 insertions, 17 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
diff --git a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
index 5c447a14b06..1c52218836c 100644
--- a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
+++ b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
@@ -349,16 +349,14 @@ public:
ErrorOr<std::unique_ptr<MemoryBuffer>> tryLoadingBuffer() {
if (EntryPath.empty())
return std::error_code();
- int FD;
SmallString<64> ResultPath;
- std::error_code EC = sys::fs::openFileForRead(
- Twine(EntryPath), FD, sys::fs::OF_UpdateAtime, &ResultPath);
- if (EC)
- return EC;
+ Expected<sys::fs::file_t> FDOrErr = sys::fs::openNativeFileForRead(
+ Twine(EntryPath), sys::fs::OF_UpdateAtime, &ResultPath);
+ if (!FDOrErr)
+ return errorToErrorCode(FDOrErr.takeError());
ErrorOr<std::unique_ptr<MemoryBuffer>> MBOrErr = MemoryBuffer::getOpenFile(
- sys::fs::convertFDToNativeFile(FD), EntryPath,
- /*FileSize=*/-1, /*RequiresNullTerminator=*/false);
- close(FD);
+ *FDOrErr, EntryPath, /*FileSize=*/-1, /*RequiresNullTerminator=*/false);
+ sys::fs::closeFile(*FDOrErr);
return MBOrErr;
}
OpenPOWER on IntegriCloud