[clang] b9f4afa - [clang][ExtractAPI] Fix iteration order of TopLevelRecords (#106411)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 29 02:02:06 PDT 2024
Author: Daniel Grumberg
Date: 2024-08-29T10:02:01+01:00
New Revision: b9f4afa1674fe6f101b298d4893cde2ab2d16877
URL: https://github.com/llvm/llvm-project/commit/b9f4afa1674fe6f101b298d4893cde2ab2d16877
DIFF: https://github.com/llvm/llvm-project/commit/b9f4afa1674fe6f101b298d4893cde2ab2d16877.diff
LOG: [clang][ExtractAPI] Fix iteration order of TopLevelRecords (#106411)
Fixes #106355
Added:
Modified:
clang/include/clang/ExtractAPI/API.h
clang/lib/ExtractAPI/API.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/ExtractAPI/API.h b/clang/include/clang/ExtractAPI/API.h
index 188e35b72117b5..4f34fcc575e807 100644
--- a/clang/include/clang/ExtractAPI/API.h
+++ b/clang/include/clang/ExtractAPI/API.h
@@ -23,7 +23,7 @@
#include "clang/AST/RawCommentList.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/ExtractAPI/DeclarationFragments.h"
-#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/Casting.h"
#include "llvm/TargetParser/Triple.h"
@@ -1420,9 +1420,8 @@ class APISet {
typename std::enable_if_t<std::is_base_of_v<APIRecord, RecordTy>, RecordTy> *
createRecord(StringRef USR, StringRef Name, CtorArgsContTy &&...CtorArgs);
- auto getTopLevelRecords() const {
- return llvm::iterator_range<decltype(TopLevelRecords)::iterator>(
- TopLevelRecords);
+ ArrayRef<const APIRecord *> getTopLevelRecords() const {
+ return TopLevelRecords;
}
void removeRecord(StringRef USR);
@@ -1455,7 +1454,7 @@ class APISet {
// lives in the BumpPtrAllocator.
using APIRecordStoredPtr = std::unique_ptr<APIRecord, APIRecordDeleter>;
llvm::DenseMap<StringRef, APIRecordStoredPtr> USRBasedLookupTable;
- llvm::SmallPtrSet<const APIRecord *, 32> TopLevelRecords;
+ llvm::SmallVector<const APIRecord *, 32> TopLevelRecords;
public:
const std::string ProductName;
@@ -1481,7 +1480,7 @@ APISet::createRecord(StringRef USR, StringRef Name,
dyn_cast_if_present<RecordContext>(Record->Parent.Record))
ParentContext->addToRecordChain(Record);
else
- TopLevelRecords.insert(Record);
+ TopLevelRecords.push_back(Record);
} else {
Record = dyn_cast<RecordTy>(Result.first->second.get());
}
diff --git a/clang/lib/ExtractAPI/API.cpp b/clang/lib/ExtractAPI/API.cpp
index 9dbc023885c37f..a6ca0ae8d0d51d 100644
--- a/clang/lib/ExtractAPI/API.cpp
+++ b/clang/lib/ExtractAPI/API.cpp
@@ -150,11 +150,13 @@ void APISet::removeRecord(StringRef USR) {
if (auto *RecordAsCtx = llvm::dyn_cast<RecordContext>(Record))
ParentCtx->stealRecordChain(*RecordAsCtx);
} else {
- TopLevelRecords.erase(Record);
+ auto *It = llvm::find(TopLevelRecords, Record);
+ if (It != TopLevelRecords.end())
+ TopLevelRecords.erase(It);
if (auto *RecordAsCtx = llvm::dyn_cast<RecordContext>(Record)) {
for (const auto *Child = RecordAsCtx->First; Child != nullptr;
Child = Child->getNextInContext())
- TopLevelRecords.insert(Child);
+ TopLevelRecords.push_back(Child);
}
}
USRBasedLookupTable.erase(Result);
More information about the cfe-commits
mailing list