[llvm] 6ecc6b1 - [LTO] Replace llvm::writeFileAtomically with llvm::writeToOutput API.
Haojian Wu via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 30 23:28:36 PDT 2023
Author: Haojian Wu
Date: 2023-07-01T08:22:01+02:00
New Revision: 6ecc6b1250b253816703cbca18af432b95fb4089
URL: https://github.com/llvm/llvm-project/commit/6ecc6b1250b253816703cbca18af432b95fb4089
DIFF: https://github.com/llvm/llvm-project/commit/6ecc6b1250b253816703cbca18af432b95fb4089.diff
LOG: [LTO] Replace llvm::writeFileAtomically with llvm::writeToOutput API.
Added:
Modified:
llvm/lib/LTO/ThinLTOCodeGenerator.cpp
Removed:
################################################################################
diff --git a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
index 0aae5bdfe3a35f..c20dfd0fd1d4a1 100644
--- a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
+++ b/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 @@ class ModuleCacheEntry {
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()));
}
};
More information about the llvm-commits
mailing list