Author: Krzysztof Parzyszek Date: 2022-12-06T09:56:14-08:00 New Revision: 3c255f679c90e332fe0b38b09d5811a64db3f0f6
URL: https://github.com/llvm/llvm-project/commit/3c255f679c90e332fe0b38b09d5811a64db3f0f6 DIFF: https://github.com/llvm/llvm-project/commit/3c255f679c90e332fe0b38b09d5811a64db3f0f6.diff LOG: Process: convert Optional to std::optional This applies to GetEnv and FindInEnvPath. Added: Modified: bolt/lib/Profile/DataAggregator.cpp clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp clang-tools-extra/clangd/TidyProvider.cpp clang/lib/Driver/Driver.cpp clang/lib/Driver/ToolChains/AMDGPU.cpp clang/lib/Driver/ToolChains/CommonArgs.cpp clang/tools/driver/driver.cpp lld/COFF/Driver.cpp lld/COFF/DriverUtils.cpp llvm/include/llvm/Support/Process.h llvm/lib/LTO/LTOCodeGenerator.cpp llvm/lib/Support/CommandLine.cpp llvm/lib/Support/Process.cpp llvm/lib/Support/Unix/Process.inc llvm/lib/Support/Windows/Process.inc llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp llvm/lib/WindowsDriver/MSVCPaths.cpp llvm/tools/llvm-ml/llvm-ml.cpp llvm/unittests/Support/ProcessTest.cpp Removed: ################################################################################ diff --git a/bolt/lib/Profile/DataAggregator.cpp b/bolt/lib/Profile/DataAggregator.cpp index 39b0a6d0ce36f..6340795254bf4 100644 --- a/bolt/lib/Profile/DataAggregator.cpp +++ b/bolt/lib/Profile/DataAggregator.cpp @@ -30,6 +30,7 @@ #include "llvm/Support/Timer.h" #include "llvm/Support/raw_ostream.h" #include <map> +#include <optional> #include <unordered_map> #include <utility> @@ -144,7 +145,7 @@ void DataAggregator::deleteTempFiles() { } void DataAggregator::findPerfExecutable() { - Optional<std::string> PerfExecutable = + std::optional<std::string> PerfExecutable = sys::Process::FindInEnvPath("PATH", "perf"); if (!PerfExecutable) { outs() << "PERF2BOLT: No perf executable found!\n"; diff --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp index f089abf69dce6..422ae6c772d74 100644 --- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp +++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp @@ -308,10 +308,19 @@ static std::unique_ptr<ClangTidyOptionsProvider> createOptionsProvider( DefaultOptions.HeaderFilterRegex = HeaderFilter; DefaultOptions.SystemHeaders = SystemHeaders; DefaultOptions.FormatStyle = FormatStyle; - DefaultOptions.User = llvm::sys::Process::GetEnv("USER"); + if (auto User = llvm::sys::Process::GetEnv("USER")) // FIXME(kparzysz-quic) + DefaultOptions.User = *User; + else + DefaultOptions.User = std::nullopt; // USERNAME is used on Windows. - if (!DefaultOptions.User) - DefaultOptions.User = llvm::sys::Process::GetEnv("USERNAME"); + // if (!DefaultOptions.User) + // DefaultOptions.User = llvm::sys::Process::GetEnv("USERNAME"); + if (!DefaultOptions.User) { // FIXME(kparzysz-quic) + if (auto Username = llvm::sys::Process::GetEnv("USERNAME")) + DefaultOptions.User = *Username; + else + DefaultOptions.User = std::nullopt; + } ClangTidyOptions OverrideOptions; if (Checks.getNumOccurrences() > 0) diff --git a/clang-tools-extra/clangd/TidyProvider.cpp b/clang-tools-extra/clangd/TidyProvider.cpp index a0a37e86ba010..7f134d9232665 100644 --- a/clang-tools-extra/clangd/TidyProvider.cpp +++ b/clang-tools-extra/clangd/TidyProvider.cpp @@ -149,12 +149,13 @@ static void mergeCheckList(llvm::Optional<std::string> &Checks, TidyProviderRef provideEnvironment() { static const llvm::Optional<std::string> User = [] { - llvm::Optional<std::string> Ret = llvm::sys::Process::GetEnv("USER"); + std::optional<std::string> Ret = llvm::sys::Process::GetEnv("USER"); #ifdef _WIN32 if (!Ret) - return llvm::sys::Process::GetEnv("USERNAME"); + Ret = llvm::sys::Process::GetEnv("USERNAME"); #endif - return Ret; + return Ret ? llvm::Optional<std::string>(*Ret) + : llvm::Optional<std::string>(); }(); if (User) diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 05cc68e6b4e30..cf0a59688cec8 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -97,6 +97,7 @@ #include <cstdlib> // ::getenv #include <map> #include <memory> +#include <optional> #include <utility> #if LLVM_ON_UNIX #include <unistd.h> // getpid @@ -575,7 +576,7 @@ static llvm::Triple computeTargetTriple(const Driver &D, // On AIX, the env OBJECT_MODE may affect the resulting arch variant. if (Target.isOSAIX()) { - if (Optional<std::string> ObjectModeValue = + if (std::optional<std::string> ObjectModeValue = llvm::sys::Process::GetEnv("OBJECT_MODE")) { StringRef ObjectMode = *ObjectModeValue; llvm::Triple::ArchType AT = llvm::Triple::UnknownArch; @@ -1277,7 +1278,7 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) { A->claim(); PrefixDirs.push_back(A->getValue(0)); } - if (Optional<std::string> CompilerPathValue = + if (std::optional<std::string> CompilerPathValue = llvm::sys::Process::GetEnv("COMPILER_PATH")) { StringRef CompilerPath = *CompilerPathValue; while (!CompilerPath.empty()) { @@ -5460,7 +5461,7 @@ const char *Driver::CreateTempFile(Compilation &C, StringRef Prefix, StringRef BoundArch) const { SmallString<128> TmpName; Arg *A = C.getArgs().getLastArg(options::OPT_fcrash_diagnostics_dir); - Optional<std::string> CrashDirectory = + std::optional<std::string> CrashDirectory = CCGenDiagnostics && A ? std::string(A->getValue()) : llvm::sys::Process::GetEnv("CLANG_CRASH_DIAGNOSTICS_DIR"); diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp b/clang/lib/Driver/ToolChains/AMDGPU.cpp index ff77969bbec59..6a52c27fb1904 100644 --- a/clang/lib/Driver/ToolChains/AMDGPU.cpp +++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp @@ -22,6 +22,7 @@ #include "llvm/Support/Path.h" #include "llvm/Support/Process.h" #include "llvm/Support/VirtualFileSystem.h" +#include <optional> #include <system_error> #define AMDGPU_ARCH_PROGRAM_NAME "amdgpu-arch" @@ -200,7 +201,7 @@ RocmInstallationDetector::getInstallationPathCandidates() { ROCmSearchDirs.emplace_back(RocmPathArg.str()); DoPrintROCmSearchDirs(); return ROCmSearchDirs; - } else if (Optional<std::string> RocmPathEnv = + } else if (std::optional<std::string> RocmPathEnv = llvm::sys::Process::GetEnv("ROCM_PATH")) { if (!RocmPathEnv->empty()) { ROCmSearchDirs.emplace_back(std::move(*RocmPathEnv)); @@ -376,7 +377,7 @@ void RocmInstallationDetector::detectDeviceLibrary() { if (!RocmDeviceLibPathArg.empty()) LibDevicePath = RocmDeviceLibPathArg[RocmDeviceLibPathArg.size() - 1]; - else if (Optional<std::string> LibPathEnv = + else if (std::optional<std::string> LibPathEnv = llvm::sys::Process::GetEnv("HIP_DEVICE_LIB_PATH")) LibDevicePath = std::move(*LibPathEnv); diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 17e39948eea75..6f975ef5b9222 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -63,6 +63,7 @@ #include "llvm/Support/Threading.h" #include "llvm/Support/VirtualFileSystem.h" #include "llvm/Support/YAMLParser.h" +#include <optional> using namespace clang::driver; using namespace clang::driver::tools; @@ -2142,7 +2143,7 @@ void tools::AddStaticDeviceLibs(Compilation *C, const Tool *T, SmallVector<std::string, 8> LibraryPaths; // Add search directories from LIBRARY_PATH env variable - llvm::Optional<std::string> LibPath = + std::optional<std::string> LibPath = llvm::sys::Process::GetEnv("LIBRARY_PATH"); if (LibPath) { SmallVector<StringRef, 8> Frags; @@ -2309,7 +2310,7 @@ void tools::addOpenMPDeviceRTL(const Driver &D, LibraryPaths.emplace_back(DefaultLibPath.c_str()); // Add user defined library paths from LIBRARY_PATH. - llvm::Optional<std::string> LibPath = + std::optional<std::string> LibPath = llvm::sys::Process::GetEnv("LIBRARY_PATH"); if (LibPath) { SmallVector<StringRef, 8> Frags; diff --git a/clang/tools/driver/driver.cpp b/clang/tools/driver/driver.cpp index 702b60bd3226d..6529c45b79135 100644 --- a/clang/tools/driver/driver.cpp +++ b/clang/tools/driver/driver.cpp @@ -48,6 +48,7 @@ #include "llvm/Support/Timer.h" #include "llvm/Support/raw_ostream.h" #include <memory> +#include <optional> #include <set> #include <system_error> using namespace clang; @@ -412,7 +413,7 @@ int clang_main(int Argc, char **Argv) { // prepended or appended. if (ClangCLMode) { // Arguments in "CL" are prepended. - llvm::Optional<std::string> OptCL = llvm::sys::Process::GetEnv("CL"); + std::optional<std::string> OptCL = llvm::sys::Process::GetEnv("CL"); if (OptCL) { SmallVector<const char *, 8> PrependedOpts; getCLEnvVarOptions(OptCL.value(), Saver, PrependedOpts); @@ -421,7 +422,7 @@ int clang_main(int Argc, char **Argv) { Args.insert(Args.begin() + 1, PrependedOpts.begin(), PrependedOpts.end()); } // Arguments in "_CL_" are appended. - llvm::Optional<std::string> Opt_CL_ = llvm::sys::Process::GetEnv("_CL_"); + std::optional<std::string> Opt_CL_ = llvm::sys::Process::GetEnv("_CL_"); if (Opt_CL_) { SmallVector<const char *, 8> AppendedOpts; getCLEnvVarOptions(Opt_CL_.value(), Saver, AppendedOpts); diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp index 6a0c269b67a60..91497e781228a 100644 --- a/lld/COFF/Driver.cpp +++ b/lld/COFF/Driver.cpp @@ -639,7 +639,7 @@ void LinkerDriver::addWinSysRootLibSearchPaths() { // Parses LIB environment which contains a list of search paths. void LinkerDriver::addLibSearchPaths() { - Optional<std::string> envOpt = Process::GetEnv("LIB"); + std::optional<std::string> envOpt = Process::GetEnv("LIB"); if (!envOpt) return; StringRef env = saver().save(*envOpt); diff --git a/lld/COFF/DriverUtils.cpp b/lld/COFF/DriverUtils.cpp index 1943d1b6aabba..0987700ce7f42 100644 --- a/lld/COFF/DriverUtils.cpp +++ b/lld/COFF/DriverUtils.cpp @@ -34,6 +34,7 @@ #include "llvm/WindowsManifest/WindowsManifestMerger.h" #include <limits> #include <memory> +#include <optional> using namespace llvm::COFF; using namespace llvm; @@ -931,11 +932,11 @@ ParsedDirectives ArgParser::parseDirectives(StringRef s) { // So you can pass extra arguments using them. void ArgParser::addLINK(SmallVector<const char *, 256> &argv) { // Concatenate LINK env and command line arguments, and then parse them. - if (Optional<std::string> s = Process::GetEnv("LINK")) { + if (std::optional<std::string> s = Process::GetEnv("LINK")) { std::vector<const char *> v = tokenize(*s); argv.insert(std::next(argv.begin()), v.begin(), v.end()); } - if (Optional<std::string> s = Process::GetEnv("_LINK_")) { + if (std::optional<std::string> s = Process::GetEnv("_LINK_")) { std::vector<const char *> v = tokenize(*s); argv.insert(std::next(argv.begin()), v.begin(), v.end()); } diff --git a/llvm/include/llvm/Support/Process.h b/llvm/include/llvm/Support/Process.h index 9f56bd9b6e611..83f1fcd8b2abc 100644 --- a/llvm/include/llvm/Support/Process.h +++ b/llvm/include/llvm/Support/Process.h @@ -24,11 +24,11 @@ #ifndef LLVM_SUPPORT_PROCESS_H #define LLVM_SUPPORT_PROCESS_H -#include "llvm/ADT/Optional.h" #include "llvm/Support/Chrono.h" #include "llvm/Support/DataTypes.h" #include "llvm/Support/Error.h" #include "llvm/Support/Program.h" +#include <optional> #include <system_error> namespace llvm { @@ -97,7 +97,7 @@ class Process { // This function returns the environment variable \arg name's value as a UTF-8 // string. \arg Name is assumed to be in UTF-8 encoding too. - static Optional<std::string> GetEnv(StringRef name); + static std::optional<std::string> GetEnv(StringRef name); /// This function searches for an existing file in the list of directories /// in a PATH like environment variable, and returns the first file found, @@ -105,14 +105,14 @@ class Process { /// variable. If an ignore list is specified, then any folder which is in /// the PATH like environment variable but is also in IgnoreList is not /// considered. - static Optional<std::string> FindInEnvPath(StringRef EnvName, - StringRef FileName, - ArrayRef<std::string> IgnoreList, - char Separator = EnvPathSeparator); - - static Optional<std::string> FindInEnvPath(StringRef EnvName, - StringRef FileName, - char Separator = EnvPathSeparator); + static std::optional<std::string> + FindInEnvPath(StringRef EnvName, StringRef FileName, + ArrayRef<std::string> IgnoreList, + char Separator = EnvPathSeparator); + + static std::optional<std::string> + FindInEnvPath(StringRef EnvName, StringRef FileName, + char Separator = EnvPathSeparator); // This functions ensures that the standard file descriptors (input, output, // and error) are properly mapped to a file descriptor before we use any of diff --git a/llvm/lib/LTO/LTOCodeGenerator.cpp b/llvm/lib/LTO/LTOCodeGenerator.cpp index 461d9488d0b47..9d20fd63a84ac 100644 --- a/llvm/lib/LTO/LTOCodeGenerator.cpp +++ b/llvm/lib/LTO/LTOCodeGenerator.cpp @@ -62,6 +62,7 @@ #include "llvm/Transforms/IPO/WholeProgramDevirt.h" #include "llvm/Transforms/ObjCARC.h" #include "llvm/Transforms/Utils/ModuleUtils.h" +#include <optional> #include <system_error> using namespace llvm; @@ -274,7 +275,7 @@ bool LTOCodeGenerator::runAIXSystemAssembler(SmallString<128> &AssemblyFile) { // Setup the LDR_CNTRL variable std::string LDR_CNTRL_var = "LDR_CNTRL=MAXDATA32=0xA0000000@DSA"; - if (Optional<std::string> V = sys::Process::GetEnv("LDR_CNTRL")) + if (std::optional<std::string> V = sys::Process::GetEnv("LDR_CNTRL")) LDR_CNTRL_var += ("@" + *V); // Prepare inputs for the assember. diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp index abcfa7cb5be7d..20a2e8539ca18 100644 --- a/llvm/lib/Support/CommandLine.cpp +++ b/llvm/lib/Support/CommandLine.cpp @@ -45,6 +45,7 @@ #include "llvm/Support/VirtualFileSystem.h" #include "llvm/Support/raw_ostream.h" #include <cstdlib> +#include <optional> #include <string> using namespace llvm; using namespace cl; @@ -1363,7 +1364,7 @@ bool cl::expandResponseFiles(int Argc, const char *const *Argv, : cl::TokenizeGNUCommandLine; // The environment variable specifies initial options. if (EnvVar) - if (llvm::Optional<std::string> EnvValue = sys::Process::GetEnv(EnvVar)) + if (std::optional<std::string> EnvValue = sys::Process::GetEnv(EnvVar)) Tokenize(*EnvValue, Saver, NewArgv, /*MarkEOLs=*/false); // Command line options can override the environment variable. @@ -1456,7 +1457,7 @@ bool cl::ParseCommandLineOptions(int argc, const char *const *argv, // Parse options from environment variable. if (EnvVar) { - if (llvm::Optional<std::string> EnvValue = + if (std::optional<std::string> EnvValue = sys::Process::GetEnv(StringRef(EnvVar))) TokenizeGNUCommandLine(*EnvValue, Saver, NewArgv); } diff --git a/llvm/lib/Support/Process.cpp b/llvm/lib/Support/Process.cpp index 5476becc29453..a7fa5a4aeb27b 100644 --- a/llvm/lib/Support/Process.cpp +++ b/llvm/lib/Support/Process.cpp @@ -20,6 +20,7 @@ #include "llvm/Support/Path.h" #include "llvm/Support/Program.h" +#include <optional> #include <stdlib.h> // for _Exit using namespace llvm; @@ -30,18 +31,17 @@ using namespace sys; //=== independent code. //===----------------------------------------------------------------------===// -Optional<std::string> +std::optional<std::string> Process::FindInEnvPath(StringRef EnvName, StringRef FileName, char Separator) { return FindInEnvPath(EnvName, FileName, {}, Separator); } -Optional<std::string> Process::FindInEnvPath(StringRef EnvName, - StringRef FileName, - ArrayRef<std::string> IgnoreList, - char Separator) { +std::optional<std::string> +Process::FindInEnvPath(StringRef EnvName, StringRef FileName, + ArrayRef<std::string> IgnoreList, char Separator) { assert(!path::is_absolute(FileName)); - Optional<std::string> FoundPath; - Optional<std::string> OptPath = Process::GetEnv(EnvName); + std::optional<std::string> FoundPath; + std::optional<std::string> OptPath = Process::GetEnv(EnvName); if (!OptPath) return FoundPath; diff --git a/llvm/lib/Support/Unix/Process.inc b/llvm/lib/Support/Unix/Process.inc index cbb8ff71f78c5..2babf07944bf7 100644 --- a/llvm/lib/Support/Unix/Process.inc +++ b/llvm/lib/Support/Unix/Process.inc @@ -15,6 +15,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/Config/config.h" #include <mutex> +#include <optional> #if HAVE_FCNTL_H #include <fcntl.h> #endif @@ -173,7 +174,7 @@ void Process::PreventCoreFiles() { coreFilesPrevented = true; } -Optional<std::string> Process::GetEnv(StringRef Name) { +std::optional<std::string> Process::GetEnv(StringRef Name) { std::string NameStr = Name.str(); const char *Val = ::getenv(NameStr.c_str()); if (!Val) diff --git a/llvm/lib/Support/Windows/Process.inc b/llvm/lib/Support/Windows/Process.inc index 86ff261255a98..4786199b4d9e3 100644 --- a/llvm/lib/Support/Windows/Process.inc +++ b/llvm/lib/Support/Windows/Process.inc @@ -17,6 +17,7 @@ #include "llvm/Support/StringSaver.h" #include "llvm/Support/WindowsError.h" #include <malloc.h> +#include <optional> // The Windows.h header must be after LLVM and standard headers. #include "llvm/Support/Windows/WindowsSupport.h" @@ -116,7 +117,7 @@ void Process::PreventCoreFiles() { /// Returns the environment variable \arg Name's value as a string encoded in /// UTF-8. \arg Name is assumed to be in UTF-8 encoding. -Optional<std::string> Process::GetEnv(StringRef Name) { +std::optional<std::string> Process::GetEnv(StringRef Name) { // Convert the argument to UTF-16 to pass it to _wgetenv(). SmallVector<wchar_t, 128> NameUTF16; if (windows::UTF8ToUTF16(Name, NameUTF16)) diff --git a/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp b/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp index 5f4d0cdf2b577..bc473a2688aaa 100644 --- a/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp +++ b/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp @@ -28,6 +28,7 @@ #include "llvm/Support/Process.h" #include "llvm/Support/StringSaver.h" #include "llvm/Support/raw_ostream.h" +#include <optional> using namespace llvm; @@ -76,7 +77,7 @@ static std::vector<StringRef> getSearchPaths(opt::InputArgList *Args, Ret.push_back(Arg->getValue()); // Add $LIB. - Optional<std::string> EnvOpt = sys::Process::GetEnv("LIB"); + std::optional<std::string> EnvOpt = sys::Process::GetEnv("LIB"); if (!EnvOpt) return Ret; StringRef Env = Saver.save(*EnvOpt); diff --git a/llvm/lib/WindowsDriver/MSVCPaths.cpp b/llvm/lib/WindowsDriver/MSVCPaths.cpp index 36a6096bc3886..0afc9dbdf8103 100644 --- a/llvm/lib/WindowsDriver/MSVCPaths.cpp +++ b/llvm/lib/WindowsDriver/MSVCPaths.cpp @@ -19,6 +19,7 @@ #include "llvm/Support/Program.h" #include "llvm/Support/VersionTuple.h" #include "llvm/Support/VirtualFileSystem.h" +#include <optional> #include <string> #ifdef _WIN32 @@ -504,7 +505,7 @@ bool findVCToolChainViaEnvironment(vfs::FileSystem &VFS, std::string &Path, ToolsetLayout &VSLayout) { // These variables are typically set by vcvarsall.bat // when launching a developer command prompt. - if (Optional<std::string> VCToolsInstallDir = + if (std::optional<std::string> VCToolsInstallDir = sys::Process::GetEnv("VCToolsInstallDir")) { // This is only set by newer Visual Studios, and it leads straight to // the toolchain directory. @@ -512,7 +513,7 @@ bool findVCToolChainViaEnvironment(vfs::FileSystem &VFS, std::string &Path, VSLayout = ToolsetLayout::VS2017OrNewer; return true; } - if (Optional<std::string> VCInstallDir = + if (std::optional<std::string> VCInstallDir = sys::Process::GetEnv("VCINSTALLDIR")) { // If the previous variable isn't set but this one is, then we've found // an older Visual Studio. This variable is set by newer Visual Studios too, @@ -526,7 +527,7 @@ bool findVCToolChainViaEnvironment(vfs::FileSystem &VFS, std::string &Path, // We couldn't find any VC environment variables. Let's walk through PATH and // see if it leads us to a VC toolchain bin directory. If it does, pick the // first one that we find. - if (Optional<std::string> PathEnv = sys::Process::GetEnv("PATH")) { + if (std::optional<std::string> PathEnv = sys::Process::GetEnv("PATH")) { SmallVector<StringRef, 8> PathEntries; StringRef(*PathEnv).split(PathEntries, sys::EnvPathSeparator); for (StringRef PathEntry : PathEntries) { diff --git a/llvm/tools/llvm-ml/llvm-ml.cpp b/llvm/tools/llvm-ml/llvm-ml.cpp index 12cd727e722a0..49fb429059836 100644 --- a/llvm/tools/llvm-ml/llvm-ml.cpp +++ b/llvm/tools/llvm-ml/llvm-ml.cpp @@ -44,6 +44,7 @@ #include "llvm/Support/ToolOutputFile.h" #include "llvm/Support/WithColor.h" #include <ctime> +#include <optional> using namespace llvm; using namespace llvm::opt; @@ -303,7 +304,7 @@ int main(int Argc, char **Argv) { std::vector<std::string> IncludeDirs = InputArgs.getAllArgValues(OPT_include_path); if (!InputArgs.hasArg(OPT_ignore_include_envvar)) { - if (llvm::Optional<std::string> IncludeEnvVar = + if (std::optional<std::string> IncludeEnvVar = llvm::sys::Process::GetEnv("INCLUDE")) { SmallVector<StringRef, 8> Dirs; StringRef(*IncludeEnvVar) diff --git a/llvm/unittests/Support/ProcessTest.cpp b/llvm/unittests/Support/ProcessTest.cpp index 3169edb854757..34b7eb82b5028 100644 --- a/llvm/unittests/Support/ProcessTest.cpp +++ b/llvm/unittests/Support/ProcessTest.cpp @@ -11,6 +11,7 @@ #include "llvm/Support/Host.h" #include "llvm/Support/Process.h" #include "gtest/gtest.h" +#include <optional> #ifdef _WIN32 #include <windows.h> @@ -45,13 +46,13 @@ TEST(ProcessTest, GetRandomNumberTest) { #if HAVE_SETENV || _MSC_VER TEST(ProcessTest, Basic) { setenv("__LLVM_TEST_ENVIRON_VAR__", "abc", true); - Optional<std::string> val(Process::GetEnv("__LLVM_TEST_ENVIRON_VAR__")); + std::optional<std::string> val(Process::GetEnv("__LLVM_TEST_ENVIRON_VAR__")); EXPECT_TRUE(val.has_value()); EXPECT_STREQ("abc", val->c_str()); } TEST(ProcessTest, None) { - Optional<std::string> val( + std::optional<std::string> val( Process::GetEnv("__LLVM_TEST_ENVIRON_NO_SUCH_VAR__")); EXPECT_FALSE(val.has_value()); } @@ -61,14 +62,14 @@ TEST(ProcessTest, None) { TEST(ProcessTest, EmptyVal) { SetEnvironmentVariableA("__LLVM_TEST_ENVIRON_VAR__", ""); - Optional<std::string> val(Process::GetEnv("__LLVM_TEST_ENVIRON_VAR__")); + std::optional<std::string> val(Process::GetEnv("__LLVM_TEST_ENVIRON_VAR__")); EXPECT_TRUE(val.has_value()); EXPECT_STREQ("", val->c_str()); } TEST(ProcessTest, Wchar) { SetEnvironmentVariableW(L"__LLVM_TEST_ENVIRON_VAR__", L"abcdefghijklmnopqrs"); - Optional<std::string> val(Process::GetEnv("__LLVM_TEST_ENVIRON_VAR__")); + std::optional<std::string> val(Process::GetEnv("__LLVM_TEST_ENVIRON_VAR__")); EXPECT_TRUE(val.has_value()); EXPECT_STREQ("abcdefghijklmnopqrs", val->c_str()); } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits