diff --git a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp --- 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 @@ 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())); } };