[clang] 219511a - [APINotes] Make an assert in a std::sort call tolerate self-comparisons

Dmitri Gribenko via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 28 15:14:24 PDT 2024


Author: Dmitri Gribenko
Date: 2024-03-28T23:11:58+01:00
New Revision: 219511aee21cc652e1ede0458de4a4a66f04c81c

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

LOG: [APINotes] Make an assert in a std::sort call tolerate self-comparisons

libc++ debug mode verifies that a comparator passed to std::sort defines
a strict weak order by calling it with the same element.

See also:

- RFC that introduced the feature:
  https://discourse.llvm.org/t/rfc-strict-weak-ordering-checks-in-the-debug-libc/70217

- `strict_weak_ordering_check.h` in libc++ sources.

Added: 
    

Modified: 
    clang/lib/APINotes/APINotesWriter.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/APINotes/APINotesWriter.cpp b/clang/lib/APINotes/APINotesWriter.cpp
index 76fd24ccfae984..e3f5d102fcd07f 100644
--- a/clang/lib/APINotes/APINotesWriter.cpp
+++ b/clang/lib/APINotes/APINotesWriter.cpp
@@ -441,7 +441,7 @@ void emitVersionedInfo(
   std::sort(VI.begin(), VI.end(),
             [](const std::pair<VersionTuple, T> &LHS,
                const std::pair<VersionTuple, T> &RHS) -> bool {
-              assert(LHS.first != RHS.first &&
+              assert((&LHS == &RHS || LHS.first != RHS.first) &&
                      "two entries for the same version");
               return LHS.first < RHS.first;
             });


        


More information about the cfe-commits mailing list