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 @@ -14,6 +14,7 @@ #include "Delta.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/IR/Verifier.h" #include "llvm/Support/ToolOutputFile.h" #include "llvm/Transforms/Utils/Cloning.h" #include @@ -103,6 +104,9 @@ errs() << "\nInput isn't interesting! Verify interesting-ness test\n"; exit(1); } + + assert(!verifyModule(*Program, &errs()) && + "input module is broken before making changes"); } std::vector ChunksStillConsideredInteresting = {{1, Targets}}; @@ -133,6 +137,14 @@ // Generate Module with only Targets inside Current Chunks ExtractChunksFromModule(CurrentChunks, Clone.get()); + // Some reductions may result in invalid IR. Skip those chunks, to ensure + // the program stays valid. + if (verifyModule(*Clone.get(), &errs())) { + errs() << " **** WARNING | reduction resulted in invalid module, " + "skipping\n"; + continue; + } + errs() << "Ignoring: "; ChunkToCheckForUninterestingness.print(); for (const Chunk &C : UninterestingChunks)