--- /dev/null
+# Print the help output if no arguments are specified
+# RUN: llvm-reduce --help | grep "LLVM automatic testcase reducer"
+# RUN: llvm-reduce | grep "LLVM automatic testcase reducer"
+
+# Don't require any other arguments for --print-delta-passes
+# RUN: llvm-reduce --print-delta-passes | grep "Delta passes (pass to \`--delta-passes=\` as a comma separated list)"
+
+# Missing test input
+# RUN: not llvm-reduce --test FileCheck 2>&1 | grep "error: reduction testcase positional argument must be specified"
+
+# Missing test script
+# RUN: not llvm-reduce some-input 2>&1 | grep "error: --test option must be specified"
cl::desc("Set the target triple"),
cl::cat(LLVMReduceOptions));
-void readBitcode(ReducerWorkItem &M, MemoryBufferRef Data, LLVMContext &Ctx, const char *ToolName);
+void readBitcode(ReducerWorkItem &M, MemoryBufferRef Data, LLVMContext &Ctx,
+ StringRef ToolName);
static void cloneFrameInfo(
MachineFrameInfo &DstMFI, const MachineFrameInfo &SrcMFI,
}
std::pair<std::unique_ptr<ReducerWorkItem>, bool>
-parseReducerWorkItem(const char *ToolName, StringRef Filename,
- LLVMContext &Ctxt, std::unique_ptr<TargetMachine> &TM,
- bool IsMIR) {
+parseReducerWorkItem(StringRef ToolName, StringRef Filename, LLVMContext &Ctxt,
+ std::unique_ptr<TargetMachine> &TM, bool IsMIR) {
bool IsBitcode = false;
Triple TheTriple;
(const unsigned char *)(*MB)->getBufferEnd())) {
std::unique_ptr<Module> Result = parseIRFile(Filename, Err, Ctxt);
if (!Result) {
- Err.print(ToolName, errs());
+ Err.print(ToolName.data(), errs());
return {nullptr, false};
}
MMM->M = std::move(Result);
};
std::pair<std::unique_ptr<ReducerWorkItem>, bool>
-parseReducerWorkItem(const char *ToolName, StringRef Filename,
- LLVMContext &Ctxt, std::unique_ptr<TargetMachine> &TM,
- bool IsMIR);
+parseReducerWorkItem(StringRef ToolName, StringRef Filename, LLVMContext &Ctxt,
+ std::unique_ptr<TargetMachine> &TM, bool IsMIR);
std::unique_ptr<ReducerWorkItem>
cloneReducerWorkItem(const ReducerWorkItem &MMM, const TargetMachine *TM);
TestRunner::TestRunner(StringRef TestName,
const std::vector<std::string> &TestArgs,
std::unique_ptr<ReducerWorkItem> Program,
- std::unique_ptr<TargetMachine> TM, const char *ToolName,
+ std::unique_ptr<TargetMachine> TM, StringRef ToolName,
StringRef OutputName, bool InputIsBitcode,
bool OutputBitcode)
: TestName(TestName), ToolName(ToolName), TestArgs(TestArgs),
public:
TestRunner(StringRef TestName, const std::vector<std::string> &TestArgs,
std::unique_ptr<ReducerWorkItem> Program,
- std::unique_ptr<TargetMachine> TM, const char *ToolName,
+ std::unique_ptr<TargetMachine> TM, StringRef ToolName,
StringRef OutputFilename, bool InputIsBitcode, bool OutputBitcode);
/// Runs the interesting-ness test for the specified file
const TargetMachine *getTargetMachine() const { return TM.get(); }
- const char *getToolName() const { return ToolName; }
+ StringRef getToolName() const { return ToolName; }
void writeOutput(StringRef Message);
private:
StringRef TestName;
- const char *ToolName;
+ StringRef ToolName;
const std::vector<std::string> &TestArgs;
std::unique_ptr<ReducerWorkItem> Program;
std::unique_ptr<TargetMachine> TM;
void writeBitcode(ReducerWorkItem &M, raw_ostream &OutStream);
void readBitcode(ReducerWorkItem &M, MemoryBufferRef Data, LLVMContext &Ctx,
- const char *ToolName);
+ StringRef ToolName);
bool isReduced(ReducerWorkItem &M, const TestRunner &Test) {
const bool UseBitcode = Test.inputIsBitcode() || TmpFilesAsBitcode;
"debugging (crash reports, llvm-symbolizer and core dumps)"),
cl::cat(LLVMReduceOptions));
+// FIXME: should be able to do this without other arguments, also add in help.
static cl::opt<bool>
PrintDeltaPasses("print-delta-passes",
cl::desc("Print list of delta passes, passable to "
"--delta-passes as a comma separated list"),
cl::cat(LLVMReduceOptions));
-static cl::opt<std::string> InputFilename(cl::Positional, cl::Required,
+static cl::opt<std::string> InputFilename(cl::Positional,
cl::desc("<input llvm ll/bc file>"),
cl::cat(LLVMReduceOptions));
static cl::opt<std::string>
- TestFilename("test", cl::Required,
+ TestFilename("test",
cl::desc("Name of the interesting-ness test to be run"),
cl::cat(LLVMReduceOptions));
return {OutputFilename, OutputBitcode};
}
-void readBitcode(ReducerWorkItem &M, MemoryBufferRef Data, LLVMContext &Ctx, const char *ToolName) {
+void readBitcode(ReducerWorkItem &M, MemoryBufferRef Data, LLVMContext &Ctx,
+ StringRef ToolName) {
Expected<BitcodeFileContents> IF = llvm::getBitcodeFileContents(Data);
if (!IF) {
WithColor::error(errs(), ToolName) << IF.takeError();
int main(int Argc, char **Argv) {
InitLLVM X(Argc, Argv);
+ const StringRef ToolName(Argv[0]);
cl::HideUnrelatedOptions({&LLVMReduceOptions, &getColorCategory()});
cl::ParseCommandLineOptions(Argc, Argv, "LLVM automatic testcase reducer.\n");
+ if (Argc == 1) {
+ cl::PrintHelpMessage();
+ return 0;
+ }
+
+ if (PrintDeltaPasses) {
+ printDeltaPasses(outs());
+ return 0;
+ }
+
bool ReduceModeMIR = false;
if (InputLanguage != InputLanguages::None) {
if (InputLanguage == InputLanguages::MIR)
ReduceModeMIR = true;
}
- if (PrintDeltaPasses) {
- printDeltaPasses(errs());
- return 0;
+ if (InputFilename.empty()) {
+ WithColor::error(errs(), ToolName)
+ << "reduction testcase positional argument must be specified\n";
+ return 1;
+ }
+
+ if (TestFilename.empty()) {
+ WithColor::error(errs(), ToolName) << "--test option must be specified\n";
+ return 1;
}
if (!PreserveDebugEnvironment)
std::unique_ptr<TargetMachine> TM;
auto [OriginalProgram, InputIsBitcode] =
- parseReducerWorkItem(Argv[0], InputFilename, Context, TM, ReduceModeMIR);
+ parseReducerWorkItem(ToolName, InputFilename, Context, TM, ReduceModeMIR);
if (!OriginalProgram) {
return 1;
}
// Initialize test environment
TestRunner Tester(TestFilename, TestArguments, std::move(OriginalProgram),
- std::move(TM), Argv[0], OutputFilename, InputIsBitcode,
+ std::move(TM), ToolName, OutputFilename, InputIsBitcode,
OutputBitcode);
// This parses and writes out the testcase into a temporary file copy for the