diff --git a/llvm/tools/llvm-reduce/deltas/Delta.cpp b/llvm/tools/llvm-reduce/deltas/Delta.cpp --- a/llvm/tools/llvm-reduce/deltas/Delta.cpp +++ b/llvm/tools/llvm-reduce/deltas/Delta.cpp @@ -99,35 +99,54 @@ /// 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 void runDeltaPassInt( TestRunner &Test, function_ref ExtractChunksFromModule) { + assert(!verifyReducerWorkItem(Test.getProgram(), &errs()) && + "input module is broken before making changes"); + + SmallString<128> CurrentFilepath; + if (!isReduced(Test.getProgram(), Test, CurrentFilepath)) { + errs() << "\nInput isn't interesting! Verify interesting-ness test\n"; + exit(1); + } + int Targets; { - // Count the number of targets by counting the number of calls to + // 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 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 NoChunks; + Oracle NoChunksCounter(NoChunks); + std::unique_ptr Clone = + cloneReducerWorkItem(Test.getProgram()); + Test.getProgram().print(errs()); + Clone->print(errs()); + ExtractChunksFromModule(NoChunksCounter, *Clone); + assert(Targets == NoChunksCounter.count() && + "number of chunks changes when reducing"); +#endif } if (!Targets) { errs() << "\nNothing to reduce\n"; return; } - SmallString<128> CurrentFilepath; - if (!isReduced(Test.getProgram(), Test, CurrentFilepath)) { - errs() << "\nInput isn't interesting! Verify interesting-ness test\n"; - exit(1); - } - - assert(!verifyReducerWorkItem(Test.getProgram(), &errs()) && - "input module is broken before making changes"); - std::vector ChunksStillConsideredInteresting = {{0, Targets - 1}}; std::unique_ptr ReducedProgram;