Skip to content

Commit 6b373a5

Browse files
[clang][ExtractAPI] Remove stale anonymous records
Remove stale anonymous records representing the type of a VarDecl after we migrate the children to the record representing the variable. rdar://128092236
1 parent 8e3909e commit 6b373a5

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

clang/include/clang/ExtractAPI/ExtractAPIVisitor.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@
2323
#include "clang/AST/RecursiveASTVisitor.h"
2424
#include "clang/Basic/LLVM.h"
2525
#include "clang/Basic/Module.h"
26-
#include "clang/Basic/SourceManager.h"
2726
#include "clang/Basic/Specifiers.h"
2827
#include "clang/ExtractAPI/API.h"
2928
#include "clang/ExtractAPI/DeclarationFragments.h"
3029
#include "clang/ExtractAPI/TypedefUnderlyingTypeResolver.h"
3130
#include "clang/Index/USRGeneration.h"
32-
#include "llvm/ADT/SmallString.h"
3331
#include "llvm/ADT/StringRef.h"
3432
#include "llvm/Support/Casting.h"
3533
#include <type_traits>
@@ -240,7 +238,7 @@ class ExtractAPIVisitorBase : public RecursiveASTVisitor<Derived> {
240238

241239
bool isEmbeddedInVarDeclarator(const TagDecl &D) {
242240
return D.getName().empty() && getTypedefName(&D).empty() &&
243-
D.isEmbeddedInDeclarator();
241+
D.isEmbeddedInDeclarator() && !D.isFreeStanding();
244242
}
245243

246244
void maybeMergeWithAnonymousTag(const DeclaratorDecl &D,
@@ -252,8 +250,10 @@ class ExtractAPIVisitorBase : public RecursiveASTVisitor<Derived> {
252250
clang::index::generateUSRForDecl(Tag, TagUSR);
253251
if (auto *Record = llvm::dyn_cast_if_present<TagRecord>(
254252
API.findRecordForUSR(TagUSR))) {
255-
if (Record->IsEmbeddedInVarDeclarator)
253+
if (Record->IsEmbeddedInVarDeclarator) {
256254
NewRecordContext->stealRecordChain(*Record);
255+
API.removeRecord(Record);
256+
}
257257
}
258258
}
259259
};

clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -673,14 +673,6 @@ bool SymbolGraphSerializer::shouldSkip(const APIRecord *Record) const {
673673
if (Record->Availability.isUnconditionallyUnavailable())
674674
return true;
675675

676-
// Filter out symbols without a name as we can generate correct symbol graphs
677-
// for them. In practice these are anonymous record types that aren't attached
678-
// to a declaration.
679-
if (auto *Tag = dyn_cast<TagRecord>(Record)) {
680-
if (Tag->IsEmbeddedInVarDeclarator)
681-
return true;
682-
}
683-
684676
// Filter out symbols prefixed with an underscored as they are understood to
685677
// be symbols clients should not use.
686678
if (Record->Name.starts_with("_"))

0 commit comments

Comments
 (0)