[llvm] 64f29e2 - Fix bad assert in print-changed code

Jamie Schmeiser via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 13 07:54:40 PDT 2021


Author: Jamie Schmeiser
Date: 2021-08-13T10:54:30-04:00
New Revision: 64f29e2dd12905b2d71e6f4b3d390c3df4cb0a80

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

LOG: Fix bad assert in print-changed code

Summary:
The assertion that both functions were not missing was incorrect and would
fail when one of the functions was missing. Fixed it and moved the
assertion earlier to check the input parameters to better capture
first-failure.  Added lit test.

Author: Jamie Schmeiser <schmeise at ca.ibm.com>
Reviewed By: aeubanks (Arthur Eubanks)
Differential Revision: https://reviews.llvm.org/D107989

Added: 
    llvm/test/Other/ChangePrinters/print-changed-D107989.ll

Modified: 
    llvm/lib/Passes/StandardInstrumentations.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Passes/StandardInstrumentations.cpp b/llvm/lib/Passes/StandardInstrumentations.cpp
index 5a48923bce8ab..fbe4f25242c2d 100644
--- a/llvm/lib/Passes/StandardInstrumentations.cpp
+++ b/llvm/lib/Passes/StandardInstrumentations.cpp
@@ -647,13 +647,12 @@ void ChangedIRComparer::compare(Any IR, StringRef Prefix, StringRef PassID,
 
   ChangedIRData::report(
       Before, After, [&](const ChangedFuncData *B, const ChangedFuncData *A) {
+        assert((B || A) && "Both functions cannot be missing.");
         ChangedFuncData Missing;
         if (!B)
           B = &Missing;
         else if (!A)
           A = &Missing;
-        assert(B != &Missing && A != &Missing &&
-               "Both functions cannot be missing.");
         handleFunctionCompare(Name, Prefix, PassID, true, *B, *A);
       });
 }

diff  --git a/llvm/test/Other/ChangePrinters/print-changed-D107989.ll b/llvm/test/Other/ChangePrinters/print-changed-D107989.ll
new file mode 100644
index 0000000000000..9e56e430d096e
--- /dev/null
+++ b/llvm/test/Other/ChangePrinters/print-changed-D107989.ll
@@ -0,0 +1,13 @@
+; D107989 This triggered an assert
+
+; RUN: opt  -passes=globalopt < %s -disable-output -print-changed=
diff -quiet
+
+define signext i32 @main()  {
+entry:
+  ret i32 0
+}
+
+define internal void @f() {
+entry:
+  ret void
+}


        


More information about the llvm-commits mailing list