[clang] db15ace - [clang] NFC, replace llvm::writeFileAtomically with llvm::writeToOutput

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 30 01:20:08 PDT 2023


Author: Haojian Wu
Date: 2023-06-30T10:18:49+02:00
New Revision: db15ace6ab667af302f8788ab2a14c3382522ed4

URL: https://github.com/llvm/llvm-project/commit/db15ace6ab667af302f8788ab2a14c3382522ed4
DIFF: https://github.com/llvm/llvm-project/commit/db15ace6ab667af302f8788ab2a14c3382522ed4.diff

LOG: [clang] NFC, replace llvm::writeFileAtomically with llvm::writeToOutput
API in ASTUnit.cpp

writeFileAtomically is going to be deprecated, in favor of
writeToOutput.

Added: 
    

Modified: 
    clang/lib/Frontend/ASTUnit.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp
index f6a74fcfbd08cb..aac449bfbc4061 100644
--- a/clang/lib/Frontend/ASTUnit.cpp
+++ b/clang/lib/Frontend/ASTUnit.cpp
@@ -68,7 +68,6 @@
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/ScopeExit.h"
-#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
@@ -83,7 +82,6 @@
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/ErrorOr.h"
 #include "llvm/Support/FileSystem.h"
-#include "llvm/Support/FileUtilities.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/SaveAndRestore.h"
 #include "llvm/Support/Timer.h"
@@ -2315,16 +2313,11 @@ bool ASTUnit::Save(StringRef File) {
   if (HadModuleLoaderFatalFailure)
     return true;
 
-  // Write to a temporary file and later rename it to the actual file, to avoid
-  // possible race conditions.
-  SmallString<128> TempPath;
-  TempPath = File;
-  TempPath += "-%%%%%%%%";
   // FIXME: Can we somehow regenerate the stat cache here, or do we need to
   // unconditionally create a stat cache when we parse the file?
 
-  if (llvm::Error Err = llvm::writeFileAtomically(
-          TempPath, File, [this](llvm::raw_ostream &Out) {
+  if (llvm::Error Err = llvm::writeToOutput(
+          File, [this](llvm::raw_ostream &Out) {
             return serialize(Out) ? llvm::make_error<llvm::StringError>(
                                         "ASTUnit serialization failed",
                                         llvm::inconvertibleErrorCode())


        


More information about the cfe-commits mailing list