[llvm] be00edf - [NewPM] Fix -print-changed when a -filter-print-funcs function is removed

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 12 12:01:00 PDT 2021


Author: Arthur Eubanks
Date: 2021-04-12T11:55:17-07:00
New Revision: be00edfee55ee00b76a113e825d6614302abf983

URL: https://github.com/llvm/llvm-project/commit/be00edfee55ee00b76a113e825d6614302abf983
DIFF: https://github.com/llvm/llvm-project/commit/be00edfee55ee00b76a113e825d6614302abf983.diff

LOG: [NewPM] Fix -print-changed when a -filter-print-funcs function is removed

-filter-print-funcs -print-changed was crashing after the filter func
was removed by a pass with
  Assertion failed: After.find("*** IR Dump") == 0 && "Unexpected banner format."
We weren't printing the banner because when we have -filter-print-funcs,
we print each function separately, letting the print function filter out
unwanted functions.

Reviewed By: jamieschmeiser

Differential Revision: https://reviews.llvm.org/D100237

Added: 
    llvm/test/Other/print-changed-deleted.ll

Modified: 
    llvm/lib/Passes/StandardInstrumentations.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Passes/StandardInstrumentations.cpp b/llvm/lib/Passes/StandardInstrumentations.cpp
index 71482030fed61..557b099ba4f9a 100644
--- a/llvm/lib/Passes/StandardInstrumentations.cpp
+++ b/llvm/lib/Passes/StandardInstrumentations.cpp
@@ -540,6 +540,13 @@ void IRChangedPrinter::generateIRRepresentation(Any IR, StringRef PassID,
 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
index 0000000000000..9e59b84d17889
--- /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()


        


More information about the llvm-commits mailing list