]> granicus.if.org Git - clang/commitdiff
[FileSystem] Split up the OpenFlags enumeration.
authorZachary Turner <zturner@google.com>
Thu, 7 Jun 2018 19:58:58 +0000 (19:58 +0000)
committerZachary Turner <zturner@google.com>
Thu, 7 Jun 2018 19:58:58 +0000 (19:58 +0000)
This breaks the OpenFlags enumeration into two separate
enumerations: OpenFlags and CreationDisposition.  The first
controls the behavior of the API depending on whether or not
the target file already exists, and is not a flags-based
enum.  The second controls more flags-like values.

This yields a more easy to understand API, while also allowing
flags to be passed to the openForRead api, where most of the
values didn't make sense before.  This also makes the apis more
testable as it becomes easy to enumerate all the configurations
which make sense, so I've added many new tests to exercise all
the different values.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@334221 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Basic/VirtualFileSystem.cpp
lib/Driver/Driver.cpp
lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp

index 234adcd9aa0d50e9eb1af119d40ade59999e438d..bcfcbdbb90149abd0e3dd6455323afab0aa15777 100644 (file)
@@ -258,7 +258,8 @@ ErrorOr<std::unique_ptr<File>>
 RealFileSystem::openFileForRead(const Twine &Name) {
   int FD;
   SmallString<256> RealName;
-  if (std::error_code EC = sys::fs::openFileForRead(Name, FD, &RealName))
+  if (std::error_code EC =
+          sys::fs::openFileForRead(Name, FD, sys::fs::OF_None, &RealName))
     return EC;
   return std::unique_ptr<File>(new RealFile(FD, Name.str(), RealName.str()));
 }
index d0858764e7c0df43ac188cddf3827f208e249a07..b006eb3521f6b528f2fb06a3c04da7ca33c6b2cd 100644 (file)
@@ -1293,7 +1293,7 @@ void Driver::generateCompilationDiagnostics(
 
   std::string Script = CrashInfo.Filename.rsplit('.').first.str() + ".sh";
   std::error_code EC;
-  llvm::raw_fd_ostream ScriptOS(Script, EC, llvm::sys::fs::F_Excl);
+  llvm::raw_fd_ostream ScriptOS(Script, EC, llvm::sys::fs::CD_CreateNew);
   if (EC) {
     Diag(clang::diag::note_drv_command_failed_diag_msg)
         << "Error generating run script: " + Script + " " + EC.message();
index 1cb122a536de4eae38b200d2b46e70eae0c57e55..d5e5f96dee0f244610fd28391592c68cc5c447f6 100644 (file)
@@ -238,10 +238,8 @@ void HTMLDiagnostics::ReportDiag(const PathDiagnostic& D,
                    << "-" << i << ".html";
           llvm::sys::path::append(Model, Directory,
                                   filename.str());
-          EC = llvm::sys::fs::openFileForWrite(Model,
-                                               FD,
-                                               llvm::sys::fs::F_RW |
-                                               llvm::sys::fs::F_Excl);
+          EC = llvm::sys::fs::openFileForReadWrite(
+              Model, FD, llvm::sys::fs::CD_CreateNew, llvm::sys::fs::OF_None);
           if (EC && EC != llvm::errc::file_exists) {
               llvm::errs() << "warning: could not create file '" << Model
                            << "': " << EC.message() << '\n';