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 @@ -140,8 +140,13 @@ FoundAtLeastOneNewUninterestingChunkWithCurrentGranularity = false; std::set UninterestingChunks; - for (Chunk &ChunkToCheckForUninterestingness : - reverse(ChunksStillConsideredInteresting)) { + + // Check if \p ChunkToCheckForUninterestingness is interesting. Returns the + // modified module if the chunk resulted in a reduction. + auto CheckChunk = [&UninterestingChunks, &Test, &ExtractChunksFromModule, + &ChunksStillConsideredInteresting]( + Chunk &ChunkToCheckForUninterestingness) + -> std::unique_ptr { // Take all of ChunksStillConsideredInteresting chunks, except those we've // already deemed uninteresting (UninterestingChunks) but didn't remove // from ChunksStillConsideredInteresting yet, and additionally ignore @@ -170,7 +175,7 @@ } errs() << " **** WARNING | reduction resulted in invalid module, " "skipping\n"; - continue; + return nullptr; } errs() << "Ignoring: "; @@ -182,12 +187,21 @@ if (!isReduced(*Clone, Test, CurrentFilepath)) { // Program became non-reduced, so this chunk appears to be interesting. errs() << "\n"; - continue; + return nullptr; } + return Clone; + }; + + for (Chunk &ChunkToCheckForUninterestingness : + reverse(ChunksStillConsideredInteresting)) { + std::unique_ptr Result = + CheckChunk(ChunkToCheckForUninterestingness); + if (!Result) + continue; FoundAtLeastOneNewUninterestingChunkWithCurrentGranularity = true; UninterestingChunks.insert(ChunkToCheckForUninterestingness); - ReducedProgram = std::move(Clone); + ReducedProgram = std::move(Result); errs() << " **** SUCCESS | lines: " << getLines(CurrentFilepath) << "\n"; writeOutput(*ReducedProgram, "Saved new best reduction to "); }