diff --git a/llvm/lib/Passes/StandardInstrumentations.cpp b/llvm/lib/Passes/StandardInstrumentations.cpp --- a/llvm/lib/Passes/StandardInstrumentations.cpp +++ b/llvm/lib/Passes/StandardInstrumentations.cpp @@ -540,6 +540,13 @@ void IRChangedPrinter::handleAfter(StringRef PassID, std::string &Name, const std::string &Before, const std::string &After, Any) { + // We might not get anything to print if we only want to print a specific + // function but it gets deleted. + if (After.empty()) { + Out << "*** IR Deleted After " << PassID << Name << " ***\n"; + return; + } + assert(After.find("*** IR Dump") == 0 && "Unexpected banner format."); StringRef AfterRef = After; StringRef Banner = diff --git a/llvm/test/Other/print-changed-deleted.ll b/llvm/test/Other/print-changed-deleted.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Other/print-changed-deleted.ll @@ -0,0 +1,7 @@ +; RUN: opt -passes=globaldce < %s -disable-output -print-changed -filter-print-funcs=f 2>&1 | FileCheck %s + +; CHECK-NOT: IR Dump After GlobalDCEPass +; CHECK: IR Deleted After GlobalDCEPass +; CHECK-NOT: IR Dump After GlobalDCEPass + +declare void @f()