Skip to content

[clang][ExtractAPI] Fix iteration order of TopLevelRecords #106411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions clang/include/clang/ExtractAPI/API.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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());
}
Expand Down
6 changes: 4 additions & 2 deletions clang/lib/ExtractAPI/API.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading