[clang] [clang][ExtractAPI] Fix iteration order of TopLevelRecords (PR #106411)
Daniel Grumberg via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 28 09:04:52 PDT 2024
https://github.com/daniel-grumberg created https://github.com/llvm/llvm-project/pull/106411
Fixes #106355
>From 5b47537dd49e79e102f7a809b434c18086274b4b Mon Sep 17 00:00:00 2001
From: Daniel Grumberg <dgrumberg at apple.com>
Date: Wed, 28 Aug 2024 17:03:22 +0100
Subject: [PATCH] [clang][ExtractAPI] Fix iteration order of TopLevelRecords
---
clang/include/clang/ExtractAPI/API.h | 11 +++++------
clang/lib/ExtractAPI/API.cpp | 6 ++++--
2 files changed, 9 insertions(+), 8 deletions(-)
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