Skip to content

Commit b3d95e7

Browse files
committed
[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.
1 parent 5ca3794 commit b3d95e7

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

clang/lib/APINotes/APINotesReader.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2045,7 +2045,12 @@ APINotesReader::VersionedInfo<T>::VersionedInfo(
20452045
Results.begin(), Results.end(),
20462046
[](const std::pair<llvm::VersionTuple, T> &left,
20472047
const std::pair<llvm::VersionTuple, T> &right) -> bool {
2048-
assert(left.first != right.first && "two entries for the same version");
2048+
// The comparison function should be reflective, and with expensive
2049+
// checks we can get callbacks basically checking that lambda(a,a) is
2050+
// false. We could still check that we do not find equal elements when
2051+
// left!=right.
2052+
assert((&left == &right || left.first != right.first) &&
2053+
"two entries for the same version");
20492054
return left.first < right.first;
20502055
}));
20512056

0 commit comments

Comments
 (0)