[clang] e748db0 - Support: Convert Program APIs to std::optional

Matt Arsenault via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 1 14:00:49 PST 2022


Author: Matt Arsenault
Date: 2022-12-01T17:00:44-05:00
New Revision: e748db0f7f0971dc258c6631ae1fb0a38cfdf9dd

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

LOG: Support: Convert Program APIs to std::optional

Added: 
    

Modified: 
    clang/include/clang/Driver/Compilation.h
    clang/include/clang/Driver/Job.h
    clang/lib/Driver/Compilation.cpp
    clang/lib/Driver/Driver.cpp
    clang/lib/Driver/Job.cpp
    clang/lib/Driver/ToolChains/AMDGPU.cpp
    clang/tools/clang-scan-deps/ClangScanDeps.cpp
    llvm/include/llvm/Support/Program.h
    llvm/lib/IR/PrintPasses.cpp
    llvm/lib/Support/Program.cpp
    llvm/lib/Support/Signals.cpp
    llvm/lib/Support/Unix/Program.inc
    llvm/lib/Support/Windows/Program.inc
    llvm/tools/bugpoint/OptimizerDriver.cpp
    llvm/tools/bugpoint/ToolRunner.cpp
    llvm/tools/llvm-cov/CodeCoverage.cpp
    llvm/tools/llvm-profgen/PerfReader.cpp
    llvm/tools/llvm-reduce/TestRunner.cpp
    llvm/unittests/Support/Host.cpp
    llvm/unittests/Support/ProgramTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Driver/Compilation.h b/clang/include/clang/Driver/Compilation.h
index 842efda9f0774..f58b5a8cc9fdb 100644
--- a/clang/include/clang/Driver/Compilation.h
+++ b/clang/include/clang/Driver/Compilation.h
@@ -15,13 +15,13 @@
 #include "clang/Driver/Util.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
-#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Option/Option.h"
 #include <cassert>
 #include <iterator>
 #include <map>
 #include <memory>
+#include <optional>
 #include <utility>
 #include <vector>
 
@@ -113,7 +113,7 @@ class Compilation {
   ArgStringMap FailureResultFiles;
 
   /// Optional redirection for stdin, stdout, stderr.
-  std::vector<Optional<StringRef>> Redirects;
+  std::vector<std::optional<StringRef>> Redirects;
 
   /// Callback called after compilation job has been finished.
   /// Arguments of the callback are the compilation job as an instance of
@@ -332,8 +332,8 @@ class Compilation {
   ///
   /// \param Redirects - array of optional paths. The array should have a size
   /// of three. The inferior process's stdin(0), stdout(1), and stderr(2) will
-  /// be redirected to the corresponding paths, if provided (not llvm::None).
-  void Redirect(ArrayRef<Optional<StringRef>> Redirects);
+  /// be redirected to the corresponding paths, if provided (not std::nullopt).
+  void Redirect(ArrayRef<std::optional<StringRef>> Redirects);
 };
 
 } // namespace driver

diff  --git a/clang/include/clang/Driver/Job.h b/clang/include/clang/Driver/Job.h
index 96cdd6fd957aa..01f8c42ef2cdb 100644
--- a/clang/include/clang/Driver/Job.h
+++ b/clang/include/clang/Driver/Job.h
@@ -12,13 +12,13 @@
 #include "clang/Basic/LLVM.h"
 #include "clang/Driver/InputInfo.h"
 #include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/iterator.h"
 #include "llvm/Option/Option.h"
 #include "llvm/Support/Program.h"
 #include <memory>
+#include <optional>
 #include <string>
 #include <utility>
 #include <vector>
@@ -142,10 +142,10 @@ class Command {
   std::vector<const char *> Environment;
 
   /// Optional redirection for stdin, stdout, stderr.
-  std::vector<Optional<std::string>> RedirectFiles;
+  std::vector<std::optional<std::string>> RedirectFiles;
 
   /// Information on executable run provided by OS.
-  mutable Optional<llvm::sys::ProcessStatistics> ProcStat;
+  mutable std::optional<llvm::sys::ProcessStatistics> ProcStat;
 
   /// When a response file is needed, we try to put most arguments in an
   /// exclusive file, while others remains as regular command line arguments.
@@ -178,7 +178,7 @@ class Command {
   virtual void Print(llvm::raw_ostream &OS, const char *Terminator, bool Quote,
                      CrashReportInfo *CrashInfo = nullptr) const;
 
-  virtual int Execute(ArrayRef<Optional<StringRef>> Redirects,
+  virtual int Execute(ArrayRef<std::optional<StringRef>> Redirects,
                       std::string *ErrMsg, bool *ExecutionFailed) const;
 
   /// getSource - Return the Action which caused the creation of this job.
@@ -207,7 +207,8 @@ class Command {
   ///         from the parent process will be used.
   virtual void setEnvironment(llvm::ArrayRef<const char *> NewEnvironment);
 
-  void setRedirectFiles(const std::vector<Optional<std::string>> &Redirects);
+  void
+  setRedirectFiles(const std::vector<std::optional<std::string>> &Redirects);
 
   void replaceArguments(llvm::opt::ArgStringList List) {
     Arguments = std::move(List);
@@ -225,7 +226,7 @@ class Command {
     return OutputFilenames;
   }
 
-  Optional<llvm::sys::ProcessStatistics> getProcessStatistics() const {
+  std::optional<llvm::sys::ProcessStatistics> getProcessStatistics() const {
     return ProcStat;
   }
 
@@ -245,7 +246,7 @@ class CC1Command : public Command {
   void Print(llvm::raw_ostream &OS, const char *Terminator, bool Quote,
              CrashReportInfo *CrashInfo = nullptr) const override;
 
-  int Execute(ArrayRef<Optional<StringRef>> Redirects, std::string *ErrMsg,
+  int Execute(ArrayRef<std::optional<StringRef>> Redirects, std::string *ErrMsg,
               bool *ExecutionFailed) const override;
 
   void setEnvironment(llvm::ArrayRef<const char *> NewEnvironment) override;
@@ -264,7 +265,7 @@ class ForceSuccessCommand : public Command {
   void Print(llvm::raw_ostream &OS, const char *Terminator, bool Quote,
              CrashReportInfo *CrashInfo = nullptr) const override;
 
-  int Execute(ArrayRef<Optional<StringRef>> Redirects, std::string *ErrMsg,
+  int Execute(ArrayRef<std::optional<StringRef>> Redirects, std::string *ErrMsg,
               bool *ExecutionFailed) const override;
 };
 

diff  --git a/clang/lib/Driver/Compilation.cpp b/clang/lib/Driver/Compilation.cpp
index 90d2e0659a39a..07ecab95798e5 100644
--- a/clang/lib/Driver/Compilation.cpp
+++ b/clang/lib/Driver/Compilation.cpp
@@ -307,6 +307,6 @@ StringRef Compilation::getSysRoot() const {
   return getDriver().SysRoot;
 }
 
-void Compilation::Redirect(ArrayRef<Optional<StringRef>> Redirects) {
+void Compilation::Redirect(ArrayRef<std::optional<StringRef>> Redirects) {
   this->Redirects = Redirects;
 }

diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 0be996275a221..5423fdc9855eb 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4659,7 +4659,7 @@ void Driver::BuildJobs(Compilation &C) const {
 
   if (CCPrintProcessStats) {
     C.setPostCallback([=](const Command &Cmd, int Res) {
-      Optional<llvm::sys::ProcessStatistics> ProcStat =
+      std::optional<llvm::sys::ProcessStatistics> ProcStat =
           Cmd.getProcessStatistics();
       if (!ProcStat)
         return;

diff  --git a/clang/lib/Driver/Job.cpp b/clang/lib/Driver/Job.cpp
index c34ae13a5fc52..af596658c5b11 100644
--- a/clang/lib/Driver/Job.cpp
+++ b/clang/lib/Driver/Job.cpp
@@ -302,7 +302,7 @@ void Command::setEnvironment(llvm::ArrayRef<const char *> NewEnvironment) {
 }
 
 void Command::setRedirectFiles(
-    const std::vector<Optional<std::string>> &Redirects) {
+    const std::vector<std::optional<std::string>> &Redirects) {
   RedirectFiles = Redirects;
 }
 
@@ -314,7 +314,7 @@ void Command::PrintFileNames() const {
   }
 }
 
-int Command::Execute(ArrayRef<llvm::Optional<StringRef>> Redirects,
+int Command::Execute(ArrayRef<std::optional<StringRef>> Redirects,
                      std::string *ErrMsg, bool *ExecutionFailed) const {
   PrintFileNames();
 
@@ -347,7 +347,7 @@ int Command::Execute(ArrayRef<llvm::Optional<StringRef>> Redirects,
     }
   }
 
-  Optional<ArrayRef<StringRef>> Env;
+  std::optional<ArrayRef<StringRef>> Env;
   std::vector<StringRef> ArgvVectorStorage;
   if (!Environment.empty()) {
     assert(Environment.back() == nullptr &&
@@ -360,12 +360,12 @@ int Command::Execute(ArrayRef<llvm::Optional<StringRef>> Redirects,
 
   // Use Job-specific redirect files if they are present.
   if (!RedirectFiles.empty()) {
-    std::vector<Optional<StringRef>> RedirectFilesOptional;
+    std::vector<std::optional<StringRef>> RedirectFilesOptional;
     for (const auto &Ele : RedirectFiles)
       if (Ele)
-        RedirectFilesOptional.push_back(Optional<StringRef>(*Ele));
+        RedirectFilesOptional.push_back(std::optional<StringRef>(*Ele));
       else
-        RedirectFilesOptional.push_back(None);
+        RedirectFilesOptional.push_back(std::nullopt);
 
     return llvm::sys::ExecuteAndWait(Executable, Args, Env,
                                      makeArrayRef(RedirectFilesOptional),
@@ -395,7 +395,7 @@ void CC1Command::Print(raw_ostream &OS, const char *Terminator, bool Quote,
   Command::Print(OS, Terminator, Quote, CrashInfo);
 }
 
-int CC1Command::Execute(ArrayRef<llvm::Optional<StringRef>> Redirects,
+int CC1Command::Execute(ArrayRef<std::optional<StringRef>> Redirects,
                         std::string *ErrMsg, bool *ExecutionFailed) const {
   // FIXME: Currently, if there're more than one job, we disable
   // -fintegrate-cc1. If we're no longer a integrated-cc1 job, fallback to
@@ -452,7 +452,7 @@ void ForceSuccessCommand::Print(raw_ostream &OS, const char *Terminator,
   OS << " || (exit 0)" << Terminator;
 }
 
-int ForceSuccessCommand::Execute(ArrayRef<llvm::Optional<StringRef>> Redirects,
+int ForceSuccessCommand::Execute(ArrayRef<std::optional<StringRef>> Redirects,
                                  std::string *ErrMsg,
                                  bool *ExecutionFailed) const {
   int Status = Command::Execute(Redirects, ErrMsg, ExecutionFailed);

diff  --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index 153537c45d2d6..f8d3cab00b70c 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -778,7 +778,7 @@ AMDGPUToolChain::detectSystemGPUs(const ArgList &Args,
   llvm::sys::fs::createTemporaryFile("print-system-gpus", "" /* No Suffix */,
                                      OutputFile);
   llvm::FileRemover OutputRemover(OutputFile.c_str());
-  llvm::Optional<llvm::StringRef> Redirects[] = {
+  std::optional<llvm::StringRef> Redirects[] = {
       {""},
       OutputFile.str(),
       {""},

diff  --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
index 0b91234e1083e..51c7f37f93cd8 100644
--- a/clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -82,7 +82,7 @@ class ResourceDirectoryCache {
                                        "" /*no-suffix*/, ErrorFile);
     llvm::FileRemover OutputRemover(OutputFile.c_str());
     llvm::FileRemover ErrorRemover(ErrorFile.c_str());
-    llvm::Optional<StringRef> Redirects[] = {
+    std::optional<StringRef> Redirects[] = {
         {""}, // Stdin
         OutputFile.str(),
         ErrorFile.str(),

diff  --git a/llvm/include/llvm/Support/Program.h b/llvm/include/llvm/Support/Program.h
index 4cb55c42c377f..5f1058920cd43 100644
--- a/llvm/include/llvm/Support/Program.h
+++ b/llvm/include/llvm/Support/Program.h
@@ -14,12 +14,12 @@
 #define LLVM_SUPPORT_PROGRAM_H
 
 #include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/Support/ErrorOr.h"
 #include "llvm/Support/FileSystem.h"
 #include <chrono>
+#include <optional>
 #include <system_error>
 
 namespace llvm {
@@ -107,11 +107,12 @@ namespace sys {
       ArrayRef<StringRef> Args, ///< An array of strings that are passed to the
       ///< program.  The first element should be the name of the program.
       ///< The array should **not** be terminated by an empty StringRef.
-      Optional<ArrayRef<StringRef>> Env = None, ///< An optional vector of
+      std::optional<ArrayRef<StringRef>> Env =
+          std::nullopt, ///< An optional vector of
       ///< strings to use for the program's environment. If not provided, the
       ///< current program's environment will be used.  If specified, the
       ///< vector should **not** be terminated by an empty StringRef.
-      ArrayRef<Optional<StringRef>> Redirects = {}, ///<
+      ArrayRef<std::optional<StringRef>> Redirects = {}, ///<
       ///< An array of optional paths. Should have a size of zero or three.
       ///< If the array is empty, no redirections are performed.
       ///< Otherwise, the inferior process's stdin(0), stdout(1), and stderr(2)
@@ -133,7 +134,7 @@ namespace sys {
       ///< string is non-empty upon return an error occurred while invoking the
       ///< program.
       bool *ExecutionFailed = nullptr,
-      Optional<ProcessStatistics> *ProcStat = nullptr, ///< If non-zero,
+      std::optional<ProcessStatistics> *ProcStat = nullptr, ///< If non-zero,
       /// provides a pointer to a structure in which process execution
       /// statistics will be stored.
       BitVector *AffinityMask = nullptr ///< CPUs or processors the new
@@ -146,8 +147,8 @@ namespace sys {
   /// \see Wait until the process finished execution or win32 CloseHandle() API
   /// on ProcessInfo.ProcessHandle to avoid memory leaks.
   ProcessInfo ExecuteNoWait(StringRef Program, ArrayRef<StringRef> Args,
-                            Optional<ArrayRef<StringRef>> Env,
-                            ArrayRef<Optional<StringRef>> Redirects = {},
+                            std::optional<ArrayRef<StringRef>> Env,
+                            ArrayRef<std::optional<StringRef>> Redirects = {},
                             unsigned MemoryLimit = 0,
                             std::string *ErrMsg = nullptr,
                             bool *ExecutionFailed = nullptr,
@@ -216,7 +217,8 @@ namespace sys {
       ///< string instance in which error messages will be returned. If the
       ///< string is non-empty upon return an error occurred while invoking the
       ///< program.
-      Optional<ProcessStatistics> *ProcStat = nullptr ///< If non-zero, provides
+      std::optional<ProcessStatistics> *ProcStat =
+          nullptr ///< If non-zero, provides
       /// a pointer to a structure in which process execution statistics will be
       /// stored.
   );

diff  --git a/llvm/lib/IR/PrintPasses.cpp b/llvm/lib/IR/PrintPasses.cpp
index 91a3438f73d9d..ce5ce618b2e8e 100644
--- a/llvm/lib/IR/PrintPasses.cpp
+++ b/llvm/lib/IR/PrintPasses.cpp
@@ -198,8 +198,9 @@ std::string llvm::doSystemDiff(StringRef Before, StringRef After,
 
   StringRef Args[] = {DiffBinary, "-w", "-d",        OLF,
                       NLF,        ULF,  FileName[0], FileName[1]};
-  Optional<StringRef> Redirects[] = {None, StringRef(FileName[2]), None};
-  int Result = sys::ExecuteAndWait(*DiffExe, Args, None, Redirects);
+  std::optional<StringRef> Redirects[] = {std::nullopt, StringRef(FileName[2]),
+                                          std::nullopt};
+  int Result = sys::ExecuteAndWait(*DiffExe, Args, std::nullopt, Redirects);
   if (Result < 0)
     return "Error executing system 
diff .";
   std::string Diff;

diff  --git a/llvm/lib/Support/Program.cpp b/llvm/lib/Support/Program.cpp
index 0560714a6acd4..dc58872b03c72 100644
--- a/llvm/lib/Support/Program.cpp
+++ b/llvm/lib/Support/Program.cpp
@@ -23,17 +23,18 @@ using namespace sys;
 //===----------------------------------------------------------------------===//
 
 static bool Execute(ProcessInfo &PI, StringRef Program,
-                    ArrayRef<StringRef> Args, Optional<ArrayRef<StringRef>> Env,
-                    ArrayRef<Optional<StringRef>> Redirects,
+                    ArrayRef<StringRef> Args,
+                    std::optional<ArrayRef<StringRef>> Env,
+                    ArrayRef<std::optional<StringRef>> Redirects,
                     unsigned MemoryLimit, std::string *ErrMsg,
                     BitVector *AffinityMask);
 
 int sys::ExecuteAndWait(StringRef Program, ArrayRef<StringRef> Args,
-                        Optional<ArrayRef<StringRef>> Env,
-                        ArrayRef<Optional<StringRef>> Redirects,
+                        std::optional<ArrayRef<StringRef>> Env,
+                        ArrayRef<std::optional<StringRef>> Redirects,
                         unsigned SecondsToWait, unsigned MemoryLimit,
                         std::string *ErrMsg, bool *ExecutionFailed,
-                        Optional<ProcessStatistics> *ProcStat,
+                        std::optional<ProcessStatistics> *ProcStat,
                         BitVector *AffinityMask) {
   assert(Redirects.empty() || Redirects.size() == 3);
   ProcessInfo PI;
@@ -54,8 +55,8 @@ int sys::ExecuteAndWait(StringRef Program, ArrayRef<StringRef> Args,
 }
 
 ProcessInfo sys::ExecuteNoWait(StringRef Program, ArrayRef<StringRef> Args,
-                               Optional<ArrayRef<StringRef>> Env,
-                               ArrayRef<Optional<StringRef>> Redirects,
+                               std::optional<ArrayRef<StringRef>> Env,
+                               ArrayRef<std::optional<StringRef>> Redirects,
                                unsigned MemoryLimit, std::string *ErrMsg,
                                bool *ExecutionFailed, BitVector *AffinityMask) {
   assert(Redirects.empty() || Redirects.size() == 3);

diff  --git a/llvm/lib/Support/Signals.cpp b/llvm/lib/Support/Signals.cpp
index c9cf7337c8c95..5773dfcc773e9 100644
--- a/llvm/lib/Support/Signals.cpp
+++ b/llvm/lib/Support/Signals.cpp
@@ -192,8 +192,8 @@ static bool printSymbolizedStackTrace(StringRef Argv0, void **StackTrace,
     }
   }
 
-  Optional<StringRef> Redirects[] = {InputFile.str(), OutputFile.str(),
-                                     StringRef("")};
+  std::optional<StringRef> Redirects[] = {InputFile.str(), OutputFile.str(),
+                                          StringRef("")};
   StringRef Args[] = {"llvm-symbolizer", "--functions=linkage", "--inlining",
 #ifdef _WIN32
                       // Pass --relative-address on Windows so that we don't

diff  --git a/llvm/lib/Support/Unix/Program.inc b/llvm/lib/Support/Unix/Program.inc
index eaa0e2a1f7317..9dab8e5da08b7 100644
--- a/llvm/lib/Support/Unix/Program.inc
+++ b/llvm/lib/Support/Unix/Program.inc
@@ -95,7 +95,7 @@ ErrorOr<std::string> sys::findProgramByName(StringRef Name,
   return errc::no_such_file_or_directory;
 }
 
-static bool RedirectIO(Optional<StringRef> Path, int FD, std::string *ErrMsg) {
+static bool RedirectIO(std::optional<StringRef> Path, int FD, std::string *ErrMsg) {
   if (!Path) // Noop
     return false;
   std::string File;
@@ -172,8 +172,8 @@ toNullTerminatedCStringArray(ArrayRef<StringRef> Strings, StringSaver &Saver) {
 }
 
 static bool Execute(ProcessInfo &PI, StringRef Program,
-                    ArrayRef<StringRef> Args, Optional<ArrayRef<StringRef>> Env,
-                    ArrayRef<Optional<StringRef>> Redirects,
+                    ArrayRef<StringRef> Args, std::optional<ArrayRef<StringRef>> Env,
+                    ArrayRef<std::optional<StringRef>> Redirects,
                     unsigned MemoryLimit, std::string *ErrMsg,
                     BitVector *AffinityMask) {
   if (!llvm::sys::fs::exists(Program)) {
@@ -386,7 +386,7 @@ pid_t(llvm::sys::wait4)(pid_t pid, int *status, int options,
 
 ProcessInfo llvm::sys::Wait(const ProcessInfo &PI, unsigned SecondsToWait,
                             bool WaitUntilTerminates, std::string *ErrMsg,
-                            Optional<ProcessStatistics> *ProcStat) {
+                            std::optional<ProcessStatistics> *ProcStat) {
   struct sigaction Act, Old;
   assert(PI.Pid && "invalid pid to wait on, process not started?");
 

diff  --git a/llvm/lib/Support/Windows/Program.inc b/llvm/lib/Support/Windows/Program.inc
index 5a82c9bef5e97..ae1c59ed84a49 100644
--- a/llvm/lib/Support/Windows/Program.inc
+++ b/llvm/lib/Support/Windows/Program.inc
@@ -127,7 +127,7 @@ bool MakeErrMsg(std::string *ErrMsg, const std::string &prefix) {
   return R != 0;
 }
 
-static HANDLE RedirectIO(Optional<StringRef> Path, int fd,
+static HANDLE RedirectIO(std::optional<StringRef> Path, int fd,
                          std::string *ErrMsg) {
   HANDLE h;
   if (!Path) {
@@ -172,8 +172,8 @@ static HANDLE RedirectIO(Optional<StringRef> Path, int fd,
 } // namespace llvm
 
 static bool Execute(ProcessInfo &PI, StringRef Program,
-                    ArrayRef<StringRef> Args, Optional<ArrayRef<StringRef>> Env,
-                    ArrayRef<Optional<StringRef>> Redirects,
+                    ArrayRef<StringRef> Args, std::optional<ArrayRef<StringRef>> Env,
+                    ArrayRef<std::optional<StringRef>> Redirects,
                     unsigned MemoryLimit, std::string *ErrMsg,
                     BitVector *AffinityMask) {
   if (!sys::fs::can_execute(Program)) {
@@ -410,7 +410,7 @@ ErrorOr<std::wstring> sys::flattenWindowsCommandLine(ArrayRef<StringRef> Args) {
 
 ProcessInfo sys::Wait(const ProcessInfo &PI, unsigned SecondsToWait,
                       bool WaitUntilChildTerminates, std::string *ErrMsg,
-                      Optional<ProcessStatistics> *ProcStat) {
+                      std::optional<ProcessStatistics> *ProcStat) {
   assert(PI.Pid && "invalid pid to wait on, process not started?");
   assert((PI.Process && PI.Process != INVALID_HANDLE_VALUE) &&
          "invalid process handle to wait on, process not started?");

diff  --git a/llvm/tools/bugpoint/OptimizerDriver.cpp b/llvm/tools/bugpoint/OptimizerDriver.cpp
index d425a8c5b49af..1197528d0dd30 100644
--- a/llvm/tools/bugpoint/OptimizerDriver.cpp
+++ b/llvm/tools/bugpoint/OptimizerDriver.cpp
@@ -232,7 +232,8 @@ bool BugDriver::runPasses(Module &Program,
              << " " << Args[i];
              errs() << "\n";);
 
-  Optional<StringRef> Redirects[3] = {None, None, None};
+  std::optional<StringRef> Redirects[3] = {std::nullopt, std::nullopt,
+                                           std::nullopt};
   // Redirect stdout and stderr to nowhere if SilencePasses is given.
   if (SilencePasses) {
     Redirects[1] = "";
@@ -240,7 +241,7 @@ bool BugDriver::runPasses(Module &Program,
   }
 
   std::string ErrMsg;
-  int result = sys::ExecuteAndWait(Prog, Args, None, Redirects, Timeout,
+  int result = sys::ExecuteAndWait(Prog, Args, std::nullopt, Redirects, Timeout,
                                    MemoryLimit, &ErrMsg);
 
   // If we are supposed to delete the bitcode file or if the passes crashed,

diff  --git a/llvm/tools/bugpoint/ToolRunner.cpp b/llvm/tools/bugpoint/ToolRunner.cpp
index d3111e574e7cc..3f4c6a6393c51 100644
--- a/llvm/tools/bugpoint/ToolRunner.cpp
+++ b/llvm/tools/bugpoint/ToolRunner.cpp
@@ -58,7 +58,7 @@ static int RunProgramWithTimeout(StringRef ProgramPath,
                                  unsigned NumSeconds = 0,
                                  unsigned MemoryLimit = 0,
                                  std::string *ErrMsg = nullptr) {
-  Optional<StringRef> Redirects[3] = {StdInFile, StdOutFile, StdErrFile};
+  std::optional<StringRef> Redirects[3] = {StdInFile, StdOutFile, StdErrFile};
   return sys::ExecuteAndWait(ProgramPath, Args, None, Redirects, NumSeconds,
                              MemoryLimit, ErrMsg);
 }
@@ -73,7 +73,7 @@ static int RunProgramRemotelyWithTimeout(
     StringRef RemoteClientPath, ArrayRef<StringRef> Args, StringRef StdInFile,
     StringRef StdOutFile, StringRef StdErrFile, unsigned NumSeconds = 0,
     unsigned MemoryLimit = 0) {
-  Optional<StringRef> Redirects[3] = {StdInFile, StdOutFile, StdErrFile};
+  std::optional<StringRef> Redirects[3] = {StdInFile, StdOutFile, StdErrFile};
 
   // Run the program remotely with the remote client
   int ReturnCode = sys::ExecuteAndWait(RemoteClientPath, Args, None, Redirects,

diff  --git a/llvm/tools/llvm-cov/CodeCoverage.cpp b/llvm/tools/llvm-cov/CodeCoverage.cpp
index 6380b7819ac55..fe35d8981be91 100644
--- a/llvm/tools/llvm-cov/CodeCoverage.cpp
+++ b/llvm/tools/llvm-cov/CodeCoverage.cpp
@@ -556,7 +556,8 @@ void CodeCoverageTool::demangleSymbols(const CoverageMapping &Coverage) {
   std::vector<StringRef> ArgsV;
   for (StringRef Arg : ViewOpts.DemanglerOpts)
     ArgsV.push_back(Arg);
-  Optional<StringRef> Redirects[] = {InputPath.str(), OutputPath.str(), {""}};
+  std::optional<StringRef> Redirects[] = {
+      InputPath.str(), OutputPath.str(), {""}};
   std::string ErrMsg;
   int RC = sys::ExecuteAndWait(ViewOpts.DemanglerOpts[0], ArgsV,
                                /*env=*/None, Redirects, /*secondsToWait=*/0,

diff  --git a/llvm/tools/llvm-profgen/PerfReader.cpp b/llvm/tools/llvm-profgen/PerfReader.cpp
index 66b4a0c6ce247..0f27429f9bb63 100644
--- a/llvm/tools/llvm-profgen/PerfReader.cpp
+++ b/llvm/tools/llvm-profgen/PerfReader.cpp
@@ -364,10 +364,10 @@ PerfInputFile PerfScriptReader::convertPerfDataToTrace(
   StringRef ScriptMMapArgs[] = {PerfPath, "script",   "--show-mmap-events",
                                 "-F",     "comm,pid", "-i",
                                 PerfData};
-  Optional<StringRef> Redirects[] = {llvm::None,               // Stdin
-                                     StringRef(PerfTraceFile), // Stdout
-                                     StringRef(ErrorFile)};    // Stderr
-  sys::ExecuteAndWait(PerfPath, ScriptMMapArgs, llvm::None, Redirects);
+  std::optional<StringRef> Redirects[] = {std::nullopt,             // Stdin
+                                          StringRef(PerfTraceFile), // Stdout
+                                          StringRef(ErrorFile)};    // Stderr
+  sys::ExecuteAndWait(PerfPath, ScriptMMapArgs, std::nullopt, Redirects);
 
   // Collect the PIDs
   TraceStream TraceIt(PerfTraceFile);

diff  --git a/llvm/tools/llvm-reduce/TestRunner.cpp b/llvm/tools/llvm-reduce/TestRunner.cpp
index f79d10667fe3a..e413f589eb22c 100644
--- a/llvm/tools/llvm-reduce/TestRunner.cpp
+++ b/llvm/tools/llvm-reduce/TestRunner.cpp
@@ -43,8 +43,8 @@ int TestRunner::run(StringRef Filename) const {
   ProgramArgs.push_back(Filename);
 
   std::string ErrMsg;
-  SmallVector<Optional<StringRef>, 3> Redirects;
-  Optional<StringRef> Empty = StringRef();
+  SmallVector<std::optional<StringRef>, 3> Redirects;
+  std::optional<StringRef> Empty = StringRef();
   if (!Verbose) {
     for (int i = 0; i < 3; ++i)
       Redirects.push_back(Empty);

diff  --git a/llvm/unittests/Support/Host.cpp b/llvm/unittests/Support/Host.cpp
index 2c89971f4f4d5..21f2e3b7a56bc 100644
--- a/llvm/unittests/Support/Host.cpp
+++ b/llvm/unittests/Support/Host.cpp
@@ -387,7 +387,7 @@ static bool runAndGetCommandOutput(
     path::append(OutputFile, "out");
     StringRef OutputPath = OutputFile.str();
 
-    const Optional<StringRef> Redirects[] = {
+    const std::optional<StringRef> Redirects[] = {
         /*STDIN=*/None, /*STDOUT=*/OutputPath, /*STDERR=*/None};
     int RetCode = ExecuteAndWait(ExePath, argv, /*env=*/llvm::None, Redirects);
     ASSERT_EQ(0, RetCode);

diff  --git a/llvm/unittests/Support/ProgramTest.cpp b/llvm/unittests/Support/ProgramTest.cpp
index f93a77ab67057..54ad9be41823a 100644
--- a/llvm/unittests/Support/ProgramTest.cpp
+++ b/llvm/unittests/Support/ProgramTest.cpp
@@ -151,7 +151,8 @@ TEST_F(ProgramEnvTest, CreateProcessLongPath) {
 
   std::string Error;
   bool ExecutionFailed;
-  Optional<StringRef> Redirects[] = {None, LongPath.str(), None};
+  std::optional<StringRef> Redirects[] = {std::nullopt, LongPath.str(),
+                                          std::nullopt};
   int RC = ExecuteAndWait(MyExe, ArgV, getEnviron(), Redirects,
     /*secondsToWait=*/ 10, /*memoryLimit=*/ 0, &Error,
     &ExecutionFailed);
@@ -194,7 +195,7 @@ TEST_F(ProgramEnvTest, CreateProcessTrailingSlash) {
 #else
   StringRef nul("/dev/null");
 #endif
-  Optional<StringRef> redirects[] = { nul, nul, None };
+  std::optional<StringRef> redirects[] = {nul, nul, None};
   int rc = ExecuteAndWait(my_exe, argv, getEnviron(), redirects,
                           /*secondsToWait=*/ 10, /*memoryLimit=*/ 0, &error,
                           &ExecutionFailed);
@@ -367,7 +368,7 @@ TEST_F(ProgramEnvTest, TestExecuteAndWaitStatistics) {
 
   std::string Error;
   bool ExecutionFailed;
-  Optional<ProcessStatistics> ProcStat;
+  std::optional<ProcessStatistics> ProcStat;
   int RetCode = ExecuteAndWait(Executable, argv, getEnviron(), {}, 0, 0, &Error,
                                &ExecutionFailed, &ProcStat);
   ASSERT_EQ(0, RetCode);


        


More information about the cfe-commits mailing list