llvm-reduce: Disable crash reports, symbolization and core dumps

These are going to waste a lot of time and produce clutter when we're
bulk introducing crashes. Add a flag to disable this behavior in case
this matters to a reproducer.
This commit is contained in:
Matt Arsenault
2022-12-20 07:32:55 -05:00
committed by Matt Arsenault
parent be9d3edee8
commit 95abdeba61
3 changed files with 52 additions and 1 deletions

View File

@@ -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")

View File

@@ -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

View File

@@ -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 <system_error>
#include <vector>
#ifdef _WIN32
#include <windows.h>
#endif
using namespace llvm;
cl::OptionCategory LLVMReduceOptions("llvm-reduce options");
@@ -35,6 +39,12 @@ static cl::opt<bool> Help("h", cl::desc("Alias for -help"), cl::Hidden,
static cl::opt<bool> Version("v", cl::desc("Alias for -version"), cl::Hidden,
cl::cat(LLVMReduceOptions));
static cl::opt<bool> 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<bool>
PrintDeltaPasses("print-delta-passes",
cl::desc("Print list of delta passes, passable to "
@@ -93,6 +103,23 @@ static codegen::RegisterCodeGenFlags CGF;
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<StringRef, bool> determineOutputType(bool IsMIR,
bool InputIsBitcode) {
bool OutputBitcode = ForceOutputBitcode || InputIsBitcode;
@@ -146,6 +173,9 @@ int main(int Argc, char **Argv) {
return 0;
}
if (!PreserveDebugEnvironment)
disableEnvironmentDebugFeatures();
LLVMContext Context;
std::unique_ptr<TargetMachine> TM;