Skip to content

Commit 26f5d1e

Browse files
authored
[APINotes] Avoid assertion failure with expensive checks (#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.
1 parent 8272b6b commit 26f5d1e

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)