diff --git a/llvm/test/tools/llvm-reduce/remove-bbs-entry.ll b/llvm/test/tools/llvm-reduce/remove-bbs-entry.ll new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-reduce/remove-bbs-entry.ll @@ -0,0 +1,18 @@ +; Test that llvm-reduce correctly removes the entry block of functions for +; linkages other than external and weak. +; +; RUN: llvm-reduce --abort-on-invalid-reduction --delta-passes=basic-blocks --test FileCheck --test-arg --check-prefixes=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t +; RUN: cat %t | FileCheck %s + +; CHECK-INTERESTINGNESS: interesting1: + +; CHECK-NOT: uninteresting +define linkonce_odr i32 @foo() { +uninteresting: + ret i32 0 +} + +define i32 @main(i1 %c) { +interesting1: + ret i32 0 +} diff --git a/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp b/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp --- a/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp @@ -126,7 +126,15 @@ // Instructions might be referenced in other BBs for (auto &I : *BB) I.replaceAllUsesWith(UndefValue::get(I.getType())); - BB->eraseFromParent(); + if (BB->getParent()->size() == 1) { + // this is the last basic block of the function, thus we must also make + // sure to remove comdat and set linkage to external + auto F = BB->getParent(); + F->deleteBody(); + F->setComdat(nullptr); + } else { + BB->eraseFromParent(); + } } }