[clang] ecdded5 - [Clang] Fix strict weak ordering in ItaniumVTableBuilder
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 2 06:25:14 PDT 2023
Author: Danila Kutenin
Date: 2023-08-02T09:22:05-04:00
New Revision: ecdded5692f99626af338792a4191d39d2a2377e
URL: https://github.com/llvm/llvm-project/commit/ecdded5692f99626af338792a4191d39d2a2377e
DIFF: https://github.com/llvm/llvm-project/commit/ecdded5692f99626af338792a4191d39d2a2377e.diff
LOG: [Clang] Fix strict weak ordering in ItaniumVTableBuilder
In sorting elements can compare with themselves and sometimes assert
further down the line was triggered.
The changes are somewhat NFC, which explains the lack of test coverage.
libc++ has a debug mode that enables extra precondition checking. When
Clang is built with libc++ in that special mode, a few of Clang's tests
would fail with the libc++ assertion because Clang was not honoring the
preconditions for std::stable_sort. However, Clang would not hit the
precondition failure with any release mode STL, so the changes have no
impact on users beyond ones in this very special circumstance.
Differential Revision: https://reviews.llvm.org/D155809
Added:
Modified:
clang/lib/AST/VTableBuilder.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/VTableBuilder.cpp b/clang/lib/AST/VTableBuilder.cpp
index 2a6f1e20202fd5..a587f9bdc75852 100644
--- a/clang/lib/AST/VTableBuilder.cpp
+++ b/clang/lib/AST/VTableBuilder.cpp
@@ -1560,6 +1560,8 @@ void ItaniumVTableBuilder::AddMethods(
std::stable_sort(
NewImplicitVirtualFunctions.begin(), NewImplicitVirtualFunctions.end(),
[](const CXXMethodDecl *A, const CXXMethodDecl *B) {
+ if (A == B)
+ return false;
if (A->isCopyAssignmentOperator() != B->isCopyAssignmentOperator())
return A->isCopyAssignmentOperator();
if (A->isMoveAssignmentOperator() != B->isMoveAssignmentOperator())
More information about the cfe-commits
mailing list