https://github.com/bjope created 
https://github.com/llvm/llvm-project/pull/120487

Found assertion failures when using EXPENSIVE_CHECKS and running lit tests for 
APINotes:
   Assertion `left.first != right.first && "two entries for the same version"' 
failed.

It seems like std::is_sorted is verifying that the comparison function is 
reflective (comp(a,a)=false) when using expensive checks. So we would get 
callbacks to the lambda used for comparison, even for vectors with a single 
element in APINotesReader::VersionedInfo<T>::VersionedInfo, with "left" and 
"right" being the same object. Therefore the assert checking that we never 
found equal values would fail.

Fix makes sure that we skip the check for equal values when "left" and "right" 
is the same object.

From b3d95e794735c3f8242643c3d187c24a1ad51421 Mon Sep 17 00:00:00 2001
From: Bjorn Pettersson <bjorn.a.petters...@ericsson.com>
Date: Wed, 18 Dec 2024 19:32:34 +0100
Subject: [PATCH] [APINotes] Avoid "two entries for the same version" failure
 with expensive checks

Found assertion failures when using EXPENSIVE_CHECKS and running
lit tests for APINotes. It seems like std::is_sorted is verifying
that the comparison function is reflective (comp(a,a)=false) when
using expensive checks. So we would get callbacks to the lambda
used for comparison, even for vectors with a single element
in APINotesReader::VersionedInfo<T>::VersionedInfo, with "left"
and "right" being the same object. Therefore the assert checking
that we never found equal values would fail.

Fix makes sure that we skip the check for equal values when
"left" and "right" is the same object.
---
 clang/lib/APINotes/APINotesReader.cpp | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/clang/lib/APINotes/APINotesReader.cpp 
b/clang/lib/APINotes/APINotesReader.cpp
index fa06dffdd14b03..646eabd2a5ecd3 100644
--- a/clang/lib/APINotes/APINotesReader.cpp
+++ b/clang/lib/APINotes/APINotesReader.cpp
@@ -2045,7 +2045,12 @@ APINotesReader::VersionedInfo<T>::VersionedInfo(
       Results.begin(), Results.end(),
       [](const std::pair<llvm::VersionTuple, T> &left,
          const std::pair<llvm::VersionTuple, T> &right) -> bool {
-        assert(left.first != right.first && "two entries for the same 
version");
+        // The comparison function should be reflective, and with expensive
+        // checks we can get callbacks basically checking that lambda(a,a) is
+        // false. We could still check that we do not find equal elements when
+        // left!=right.
+        assert((&left == &right || left.first != right.first) &&
+               "two entries for the same version");
         return left.first < right.first;
       }));
 

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to