diff --git a/llvm/test/Reduce/remove-function-bodies-used-in-globals.ll b/llvm/test/Reduce/remove-function-bodies-used-in-globals.ll --- a/llvm/test/Reduce/remove-function-bodies-used-in-globals.ll +++ b/llvm/test/Reduce/remove-function-bodies-used-in-globals.ll @@ -1,12 +1,15 @@ ; RUN: llvm-reduce --test FileCheck --test-arg --check-prefixes=CHECK-ALL,CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t ; RUN: cat %t | FileCheck --check-prefixes=CHECK-ALL,CHECK-FINAL %s +; We cannot change the @alias to undef, because it would result in invalid IR +; (Aliasee should be either GlobalValue or ConstantExpr). + ; CHECK-INTERESTINGNESS: @alias = -; CHECK-FINAL: @alias = alias void (i32), void (i32)* undef +; CHECK-FINAL: @alias = alias void (i32), bitcast (void ()* @func to void (i32)*) @alias = alias void (i32), void (i32)* @func -; CHECK-FINAL-NOT: @func() +; CHECK-FINAL: @func() define void @func(i32 %arg) { entry: 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 @@ -105,6 +106,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}}; @@ -135,6 +139,13 @@ // Generate Module with only Targets inside Current Chunks ExtractChunksFromModule(CurrentChunks, Clone.get()); + // Some reductions may result in invalid IR. Skip such reductions. + if (verifyModule(*Clone.get(), &errs())) { + errs() << " **** WARNING | reduction resulted in invalid module, " + "skipping\n"; + continue; + } + errs() << "Ignoring: "; ChunkToCheckForUninterestingness.print(); for (const Chunk &C : UninterestingChunks)