[PATCH] D154191: [LTO] Replace llvm::writeFileAtomically with llvm::writeToOutput API.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 30 01:41:24 PDT 2023
hokein created this revision.
hokein added reviewers: jkorous, avl.
Herald added subscribers: ormris, steven_wu, hiraditya, inglorion.
Herald added a project: All.
hokein requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D154191
Files:
llvm/lib/LTO/ThinLTOCodeGenerator.cpp
Index: llvm/lib/LTO/ThinLTOCodeGenerator.cpp
===================================================================
--- llvm/lib/LTO/ThinLTOCodeGenerator.cpp
+++ llvm/lib/LTO/ThinLTOCodeGenerator.cpp
@@ -44,13 +44,14 @@
#include "llvm/Support/CachePruning.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Error.h"
-#include "llvm/Support/FileUtilities.h"
+#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/SHA1.h"
#include "llvm/Support/SmallVectorMemoryBuffer.h"
#include "llvm/Support/ThreadPool.h"
#include "llvm/Support/Threading.h"
#include "llvm/Support/ToolOutputFile.h"
+#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/TargetParser/SubtargetFeature.h"
#include "llvm/Transforms/IPO/FunctionAttrs.h"
@@ -415,29 +416,14 @@
if (EntryPath.empty())
return;
- // Write to a temporary to avoid race condition
- SmallString<128> TempFilename;
- SmallString<128> CachePath(EntryPath);
- llvm::sys::path::remove_filename(CachePath);
- sys::path::append(TempFilename, CachePath, "Thin-%%%%%%.tmp.o");
-
- if (auto Err = handleErrors(
- llvm::writeFileAtomically(TempFilename, EntryPath,
- OutputBuffer.getBuffer()),
- [](const llvm::AtomicFileWriteError &E) {
- std::string ErrorMsgBuffer;
- llvm::raw_string_ostream S(ErrorMsgBuffer);
- E.log(S);
-
- if (E.Error ==
- llvm::atomic_write_error::failed_to_create_uniq_file) {
- errs() << "Error: " << ErrorMsgBuffer << "\n";
- report_fatal_error("ThinLTO: Can't get a temporary file");
- }
- })) {
- // FIXME
- consumeError(std::move(Err));
- }
+ if (auto Err = handleErrors(llvm::writeToOutput(
+ EntryPath, [&OutputBuffer](llvm::raw_ostream &OS) -> llvm::Error {
+ OS << OutputBuffer.getBuffer();
+ return llvm::Error::success();
+ })))
+ report_fatal_error(llvm::formatv("ThinLTO: Can't write file {0}: {1}",
+ EntryPath,
+ toString(std::move(Err)).c_str()));
}
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154191.536141.patch
Type: text/x-patch
Size: 2282 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230630/d2e26bac/attachment.bin>
More information about the cfe-commits
mailing list