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,10 @@ void IRChangedPrinter::handleAfter(StringRef PassID, std::string &Name, const std::string &Before, const std::string &After, Any) { + // We might not have anything to print if we only want to print a specific + // function but it gets deleted. + if (After.empty()) + 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,5 @@ +; RUN: opt -passes=globaldce < %s -disable-output -print-changed -filter-print-funcs=f 2>&1 | FileCheck %s + +; CHECK-NOT: IR Dump After GlobalDCEPass + +declare void @f()