Skip to content

Commit b9f4afa

Browse files
authoredAug 29, 2024··
[clang][ExtractAPI] Fix iteration order of TopLevelRecords (#106411)
Fixes #106355
1 parent 31684c6 commit b9f4afa

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed
 

‎clang/include/clang/ExtractAPI/API.h

+5-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "clang/AST/RawCommentList.h"
2424
#include "clang/Basic/SourceLocation.h"
2525
#include "clang/ExtractAPI/DeclarationFragments.h"
26-
#include "llvm/ADT/SmallPtrSet.h"
26+
#include "llvm/ADT/SmallVector.h"
2727
#include "llvm/Support/Allocator.h"
2828
#include "llvm/Support/Casting.h"
2929
#include "llvm/TargetParser/Triple.h"
@@ -1420,9 +1420,8 @@ class APISet {
14201420
typename std::enable_if_t<std::is_base_of_v<APIRecord, RecordTy>, RecordTy> *
14211421
createRecord(StringRef USR, StringRef Name, CtorArgsContTy &&...CtorArgs);
14221422

1423-
auto getTopLevelRecords() const {
1424-
return llvm::iterator_range<decltype(TopLevelRecords)::iterator>(
1425-
TopLevelRecords);
1423+
ArrayRef<const APIRecord *> getTopLevelRecords() const {
1424+
return TopLevelRecords;
14261425
}
14271426

14281427
void removeRecord(StringRef USR);
@@ -1455,7 +1454,7 @@ class APISet {
14551454
// lives in the BumpPtrAllocator.
14561455
using APIRecordStoredPtr = std::unique_ptr<APIRecord, APIRecordDeleter>;
14571456
llvm::DenseMap<StringRef, APIRecordStoredPtr> USRBasedLookupTable;
1458-
llvm::SmallPtrSet<const APIRecord *, 32> TopLevelRecords;
1457+
llvm::SmallVector<const APIRecord *, 32> TopLevelRecords;
14591458

14601459
public:
14611460
const std::string ProductName;
@@ -1481,7 +1480,7 @@ APISet::createRecord(StringRef USR, StringRef Name,
14811480
dyn_cast_if_present<RecordContext>(Record->Parent.Record))
14821481
ParentContext->addToRecordChain(Record);
14831482
else
1484-
TopLevelRecords.insert(Record);
1483+
TopLevelRecords.push_back(Record);
14851484
} else {
14861485
Record = dyn_cast<RecordTy>(Result.first->second.get());
14871486
}

‎clang/lib/ExtractAPI/API.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,13 @@ void APISet::removeRecord(StringRef USR) {
150150
if (auto *RecordAsCtx = llvm::dyn_cast<RecordContext>(Record))
151151
ParentCtx->stealRecordChain(*RecordAsCtx);
152152
} else {
153-
TopLevelRecords.erase(Record);
153+
auto *It = llvm::find(TopLevelRecords, Record);
154+
if (It != TopLevelRecords.end())
155+
TopLevelRecords.erase(It);
154156
if (auto *RecordAsCtx = llvm::dyn_cast<RecordContext>(Record)) {
155157
for (const auto *Child = RecordAsCtx->First; Child != nullptr;
156158
Child = Child->getNextInContext())
157-
TopLevelRecords.insert(Child);
159+
TopLevelRecords.push_back(Child);
158160
}
159161
}
160162
USRBasedLookupTable.erase(Result);

0 commit comments

Comments
 (0)
Please sign in to comment.