Skip to content

Commit 3e0d37f

Browse files
committed
llvm-reduce: Simplify argument setup for ExecuteAndWait
Only need to append the input file for each iteration.
1 parent 6d216fb commit 3e0d37f

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

llvm/tools/llvm-reduce/TestRunner.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,18 @@
1313

1414
using namespace llvm;
1515

16-
TestRunner::TestRunner(StringRef TestName,
17-
const std::vector<std::string> &TestArgs,
16+
TestRunner::TestRunner(StringRef TestName, ArrayRef<std::string> RawTestArgs,
1817
std::unique_ptr<ReducerWorkItem> Program,
1918
std::unique_ptr<TargetMachine> TM, StringRef ToolName,
2019
StringRef OutputName, bool InputIsBitcode,
2120
bool OutputBitcode)
22-
: TestName(TestName), ToolName(ToolName), TestArgs(TestArgs),
23-
Program(std::move(Program)), TM(std::move(TM)),
24-
OutputFilename(OutputName), InputIsBitcode(InputIsBitcode),
25-
EmitBitcode(OutputBitcode) {
21+
: TestName(TestName), ToolName(ToolName), Program(std::move(Program)),
22+
TM(std::move(TM)), OutputFilename(OutputName),
23+
InputIsBitcode(InputIsBitcode), EmitBitcode(OutputBitcode) {
2624
assert(this->Program && "Initialized with null program?");
25+
26+
TestArgs.push_back(TestName); // argv[0]
27+
TestArgs.append(RawTestArgs.begin(), RawTestArgs.end());
2728
}
2829

2930
static constexpr std::array<std::optional<StringRef>, 3> DefaultRedirects = {
@@ -33,18 +34,13 @@ static constexpr std::array<std::optional<StringRef>, 3> NullRedirects;
3334
/// Runs the interestingness test, passes file to be tested as first argument
3435
/// and other specified test arguments after that.
3536
int TestRunner::run(StringRef Filename) const {
36-
std::vector<StringRef> ProgramArgs;
37-
ProgramArgs.push_back(TestName);
38-
39-
for (const auto &Arg : TestArgs)
40-
ProgramArgs.push_back(Arg);
41-
42-
ProgramArgs.push_back(Filename);
37+
SmallVector<StringRef> ExecArgs(TestArgs);
38+
ExecArgs.push_back(Filename);
4339

4440
std::string ErrMsg;
4541

4642
int Result =
47-
sys::ExecuteAndWait(TestName, ProgramArgs, /*Env=*/std::nullopt,
43+
sys::ExecuteAndWait(TestName, ExecArgs, /*Env=*/std::nullopt,
4844
Verbose ? DefaultRedirects : NullRedirects,
4945
/*SecondsToWait=*/0, /*MemoryLimit=*/0, &ErrMsg);
5046

llvm/tools/llvm-reduce/TestRunner.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace llvm {
2525
// respective filename.
2626
class TestRunner {
2727
public:
28-
TestRunner(StringRef TestName, const std::vector<std::string> &TestArgs,
28+
TestRunner(StringRef TestName, ArrayRef<std::string> TestArgs,
2929
std::unique_ptr<ReducerWorkItem> Program,
3030
std::unique_ptr<TargetMachine> TM, StringRef ToolName,
3131
StringRef OutputFilename, bool InputIsBitcode, bool OutputBitcode);
@@ -55,7 +55,7 @@ class TestRunner {
5555
private:
5656
StringRef TestName;
5757
StringRef ToolName;
58-
const std::vector<std::string> &TestArgs;
58+
SmallVector<StringRef> TestArgs;
5959
std::unique_ptr<ReducerWorkItem> Program;
6060
std::unique_ptr<TargetMachine> TM;
6161
StringRef OutputFilename;

0 commit comments

Comments
 (0)