[llvm] b59d672 - [Assignment Tracking] Fix faulty assertion inside std::sort predicate

via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 26 03:15:23 PDT 2023


Author: OCHyams
Date: 2023-04-26T11:14:51+01:00
New Revision: b59d672ed489ddb3373db62be168bb0926c4f5f3

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

LOG: [Assignment Tracking] Fix faulty assertion inside std::sort predicate

The vectors being sorted here shouldn't contain duplicate entries. Prior to
this patch this was checked with an assert within the `std::sort`
predicate. However, `std::sort` may compare an element against itself which
causes the assert to fire (false positive). Move the assert outside of the sort
predicate to avoid such issues.

Reviewed By: StephenTozer

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

Added: 
    

Modified: 
    llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp b/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp
index cd094d6d89c5..d5e133d88c60 100644
--- a/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp
+++ b/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp
@@ -2011,16 +2011,17 @@ static AssignmentTrackingLowering::OverlapMap buildOverlapMapAndRecordDeclares(
     }
   }
 
-  // Sort the fragment map for each DebugAggregate in non-descending
-  // order of fragment size. Assert no entries are duplicates.
+  // Sort the fragment map for each DebugAggregate in ascending
+  // order of fragment size - there should be no duplicates.
   for (auto &Pair : FragmentMap) {
     SmallVector<DebugVariable, 8> &Frags = Pair.second;
-    std::sort(
-        Frags.begin(), Frags.end(), [](DebugVariable Next, DebugVariable Elmt) {
-          assert(!(Elmt.getFragmentOrDefault() == Next.getFragmentOrDefault()));
-          return Elmt.getFragmentOrDefault().SizeInBits >
-                 Next.getFragmentOrDefault().SizeInBits;
-        });
+    std::sort(Frags.begin(), Frags.end(),
+              [](const DebugVariable &Next, const DebugVariable &Elmt) {
+                return Elmt.getFragmentOrDefault().SizeInBits >
+                       Next.getFragmentOrDefault().SizeInBits;
+              });
+    // Check for duplicates.
+    assert(std::adjacent_find(Frags.begin(), Frags.end()) == Frags.end());
   }
 
   // Build the map.


        


More information about the llvm-commits mailing list