Index: llvm/test/tools/llvm-reduce/Inputs/test-crash-vars.py =================================================================== --- /dev/null +++ llvm/test/tools/llvm-reduce/Inputs/test-crash-vars.py @@ -0,0 +1,9 @@ +import os +import sys + +disable_crash_report = os.getenv("LLVM_DISABLE_CRASH_REPORT") +disable_symbolization = os.getenv("LLVM_DISABLE_SYMBOLIZATION") + +# Test that this is an explicitly set true value. If we preserve the +# debug environment a pre-set explicit 0 should work. +sys.exit(disable_crash_report != "1" or disable_symbolization != "1") Index: llvm/test/tools/llvm-reduce/disable-crash-reports.test =================================================================== --- /dev/null +++ llvm/test/tools/llvm-reduce/disable-crash-reports.test @@ -0,0 +1,12 @@ +# RUN: llvm-reduce --delta-passes=global-variables --test %python --test-arg %p/Inputs/test-crash-vars.py %p/Inputs/test-output-format.ll 2>&1 | FileCheck -check-prefix=INTERESTING %s + +# RUN: LLVM_DISABLE_CRASH_REPORT=0 llvm-reduce --delta-passes=global-variables --test %python --test-arg %p/Inputs/test-crash-vars.py %p/Inputs/test-output-format.ll 2>&1 | FileCheck -check-prefix=INTERESTING %s + +# RUN: not llvm-reduce --preserve-debug-environment --delta-passes=global-variables --test %python --test-arg %p/Inputs/test-crash-vars.py %p/Inputs/test-output-format.ll 2>&1 | FileCheck -check-prefix=NOTINTERESTING %s + +# RUN: LLVM_DISABLE_CRASH_REPORT=0 not llvm-reduce --preserve-debug-environment --delta-passes=global-variables --test %python --test-arg %p/Inputs/test-crash-vars.py %p/Inputs/test-output-format.ll 2>&1 | FileCheck -check-prefix=NOTINTERESTING %s + +# RUN: LLVM_DISABLE_CRASH_REPORT=1 LLVM_DISABLE_SYMBOLIZATION=1 llvm-reduce --preserve-debug-environment --delta-passes=global-variables --test %python --test-arg %p/Inputs/test-crash-vars.py %p/Inputs/test-output-format.ll 2>&1 | FileCheck -check-prefix=INTERESTING %s + +INTERESTING: Done reducing! Reduced testcase: +NOTINTERESTING: Input isn't interesting! Verify 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 @@ -18,14 +18,18 @@ #include "ReducerWorkItem.h" #include "TestRunner.h" #include "llvm/CodeGen/CommandFlags.h" - #include "llvm/Support/CommandLine.h" #include "llvm/Support/InitLLVM.h" +#include "llvm/Support/Process.h" #include "llvm/Support/WithColor.h" #include "llvm/Support/raw_ostream.h" #include #include +#ifdef _WIN32 +#include +#endif + using namespace llvm; cl::OptionCategory LLVMReduceOptions("llvm-reduce options"); @@ -35,6 +39,12 @@ static cl::opt Version("v", cl::desc("Alias for -version"), cl::Hidden, cl::cat(LLVMReduceOptions)); +static cl::opt PreserveDebugEnvironment( + "preserve-debug-environment", + cl::desc("Don't disable features used for crash " + "debugging (crash reports, llvm-symbolizer and core dumps)"), + cl::cat(LLVMReduceOptions)); + static cl::opt PrintDeltaPasses("print-delta-passes", cl::desc("Print list of delta passes, passable to " @@ -93,6 +103,23 @@ bool isReduced(ReducerWorkItem &M, const TestRunner &Test); +/// Turn off crash debugging features +/// +/// Crash is expected, so disable crash reports and symbolization to reduce +/// 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, bool InputIsBitcode) { bool OutputBitcode = ForceOutputBitcode || InputIsBitcode; @@ -146,6 +173,9 @@ return 0; } + if (!PreserveDebugEnvironment) + disableEnvironmentDebugFeatures(); + LLVMContext Context; std::unique_ptr TM;