[llvm-reduce] Assert that the number of chunks does not change with reductions

Followup to D113537.

Reviewed By: Meinersbur

Differential Revision: https://reviews.llvm.org/D113816
This commit is contained in:
Arthur Eubanks 2021-11-12 16:05:31 -08:00
parent 512534bc16
commit 7cbb6e9a8f
1 changed files with 34 additions and 17 deletions
llvm/tools/llvm-reduce/deltas

View File

@ -211,25 +211,14 @@ SmallString<0> ProcessChunkFromSerializedBitcode(
/// Runs the Delta Debugging algorithm, splits the code into chunks and
/// reduces the amount of chunks that are considered interesting by the
/// given test.
/// given test. The number of chunks is determined by a preliminary run of the
/// reduction pass where no change must be made to the module.
template <typename T>
void runDeltaPassInt(
TestRunner &Test,
function_ref<void(Oracle &, T &)> ExtractChunksFromModule) {
int Targets;
{
// Count the number of targets by counting the number of calls to
// Oracle::shouldKeep() but always returning true so no changes are
// made.
std::vector<Chunk> AllChunks = {{0, INT_MAX}};
Oracle Counter(AllChunks);
ExtractChunksFromModule(Counter, Test.getProgram());
Targets = Counter.count();
}
if (!Targets) {
errs() << "\nNothing to reduce\n";
return;
}
assert(!verifyReducerWorkItem(Test.getProgram(), &errs()) &&
"input module is broken before making changes");
SmallString<128> CurrentFilepath;
if (!isReduced(Test.getProgram(), Test, CurrentFilepath)) {
@ -237,8 +226,36 @@ void runDeltaPassInt(
exit(1);
}
assert(!verifyReducerWorkItem(Test.getProgram(), &errs()) &&
"input module is broken before making changes");
int Targets;
{
// Count the number of chunks by counting the number of calls to
// Oracle::shouldKeep() but always returning true so no changes are
// made.
std::vector<Chunk> AllChunks = {{0, INT_MAX}};
Oracle Counter(AllChunks);
ExtractChunksFromModule(Counter, Test.getProgram());
Targets = Counter.count();
assert(!verifyReducerWorkItem(Test.getProgram(), &errs()) &&
"input module is broken after counting chunks");
assert(isReduced(Test.getProgram(), Test, CurrentFilepath) &&
"input module no longer interesting after counting chunks");
#ifndef NDEBUG
// Make sure that the number of chunks does not change as we reduce.
std::vector<Chunk> NoChunks;
Oracle NoChunksCounter(NoChunks);
std::unique_ptr<ReducerWorkItem> Clone =
cloneReducerWorkItem(Test.getProgram());
ExtractChunksFromModule(NoChunksCounter, *Clone);
assert(Targets == NoChunksCounter.count() &&
"number of chunks changes when reducing");
#endif
}
if (!Targets) {
errs() << "\nNothing to reduce\n";
return;
}
std::vector<Chunk> ChunksStillConsideredInteresting = {{0, Targets - 1}};
std::unique_ptr<ReducerWorkItem> ReducedProgram;