Index: llvm/tools/llvm-reduce/TestRunner.h =================================================================== --- llvm/tools/llvm-reduce/TestRunner.h +++ llvm/tools/llvm-reduce/TestRunner.h @@ -29,7 +29,8 @@ TestRunner(StringRef TestName, ArrayRef TestArgs, std::unique_ptr Program, std::unique_ptr TM, const char *ToolName, - StringRef OutputFilename, bool InputIsBitcode, bool OutputBitcode); + StringRef OutputFilename, bool InputIsBitcode, bool OutputBitcode, + bool PreserveDebugEnvironment); /// Runs the interesting-ness test for the specified file /// @returns 0 if test was successful, 1 if otherwise @@ -59,6 +60,7 @@ StringRef OutputFilename; const bool InputIsBitcode; bool EmitBitcode; + const bool PreserveDebugEnvironment; }; } // namespace llvm Index: llvm/tools/llvm-reduce/TestRunner.cpp =================================================================== --- llvm/tools/llvm-reduce/TestRunner.cpp +++ llvm/tools/llvm-reduce/TestRunner.cpp @@ -22,10 +22,11 @@ std::unique_ptr Program, std::unique_ptr TM, const char *ToolName, StringRef OutputName, bool InputIsBitcode, - bool OutputBitcode) + bool OutputBitcode, bool PreserveDebugEnvironment) : TestName(TestName), ToolName(ToolName), Program(std::move(Program)), TM(std::move(TM)), OutputFilename(OutputName), - InputIsBitcode(InputIsBitcode), EmitBitcode(OutputBitcode) { + InputIsBitcode(InputIsBitcode), EmitBitcode(OutputBitcode), + PreserveDebugEnvironment(PreserveDebugEnvironment) { assert(this->Program && "Initialized with null program?"); TestArgs.push_back(TestName); // argv[0] @@ -36,6 +37,11 @@ StringRef()}; static constexpr std::array, 3> NullRedirects; +static constexpr std::array DebugEnvironmentVars = { + "LLVM_DISABLE_CRASH_REPORT=1", + "LLVM_DISABLE_SYMBOLIZATION=1" +}; + /// Runs the interestingness test, passes file to be tested as first argument /// and other specified test arguments after that. int TestRunner::run(StringRef Filename) const { @@ -44,10 +50,15 @@ std::string ErrMsg; - int Result = - sys::ExecuteAndWait(TestName, ExecArgs, /*Env=*/std::nullopt, - Verbose ? DefaultRedirects : NullRedirects, - /*SecondsToWait=*/0, /*MemoryLimit=*/0, &ErrMsg); + const std::optional> Env = + PreserveDebugEnvironment ? std::nullopt + : std::make_optional(DebugEnvironmentVars); + + int Result = sys::ExecuteAndWait( + TestName, ExecArgs, + /*Env=*/Env, + /*Redirects=*/Verbose ? DefaultRedirects : NullRedirects, + /*SecondsToWait=*/0, /*MemoryLimit=*/0, &ErrMsg); if (Result < 0) { Error E = make_error("Error running interesting-ness test: " + Index: llvm/tools/llvm-reduce/llvm-reduce.cpp =================================================================== --- llvm/tools/llvm-reduce/llvm-reduce.cpp +++ llvm/tools/llvm-reduce/llvm-reduce.cpp @@ -26,10 +26,6 @@ #include #include -#ifdef _WIN32 -#include -#endif - using namespace llvm; cl::OptionCategory LLVMReduceOptions("llvm-reduce options"); @@ -109,15 +105,6 @@ /// output clutter and avoid potentially slow symbolization. static void disableEnvironmentDebugFeatures() { sys::Process::PreventCoreFiles(); - - // TODO: Copied from not. Should have a wrapper around setenv. -#ifdef _WIN32 - SetEnvironmentVariableA("LLVM_DISABLE_CRASH_REPORT", "1"); - SetEnvironmentVariableA("LLVM_DISABLE_SYMBOLIZATION", "1"); -#else - setenv("LLVM_DISABLE_CRASH_REPORT", "1", /*overwrite=*/1); - setenv("LLVM_DISABLE_SYMBOLIZATION", "1", /*overwrite=*/1); -#endif } static std::pair determineOutputType(bool IsMIR, @@ -193,7 +180,7 @@ // Initialize test environment TestRunner Tester(TestFilename, TestArguments, std::move(OriginalProgram), std::move(TM), Argv[0], OutputFilename, InputIsBitcode, - OutputBitcode); + OutputBitcode, PreserveDebugEnvironment); // This parses and writes out the testcase into a temporary file copy for the // test, rather than evaluating the source IR directly. This is for the