llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: NagaChaitanya Vellanki (chaitanyav) <details> <summary>Changes</summary> Keep anonymous structs/unions embedded in var declarators Fixes #<!-- -->61477 --- Full diff: https://github.com/llvm/llvm-project/pull/159698.diff 1 Files Affected: - (modified) clang/include/clang/ExtractAPI/ExtractAPIVisitor.h (+17-23) ``````````diff diff --git a/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h b/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h index 9ea664f57f828..5b7a8266d2092 100644 --- a/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h +++ b/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h @@ -261,15 +261,9 @@ class ExtractAPIVisitorBase : public RecursiveASTVisitor<Derived> { Tag = AT->getElementType()->getAsTagDecl(); } } - SmallString<128> TagUSR; - clang::index::generateUSRForDecl(Tag, TagUSR); - if (auto *Record = llvm::dyn_cast_if_present<TagRecord>( - API.findRecordForUSR(TagUSR))) { - if (Record->IsEmbeddedInVarDeclarator) { - NewRecordContext->stealRecordChain(*Record); - API.removeRecord(Record); - } - } + // For anonymous structs/unions embedded in var declarators, + // we keep them in the hierarchy (don't remove them) + // This preserves the path components while maintaining relationships } }; @@ -566,13 +560,7 @@ bool ExtractAPIVisitorBase<Derived>::VisitNamespaceDecl( template <typename Derived> bool ExtractAPIVisitorBase<Derived>::TraverseRecordDecl(RecordDecl *Decl) { bool Ret = Base::TraverseRecordDecl(Decl); - - if (!isEmbeddedInVarDeclarator(*Decl) && Decl->isAnonymousStructOrUnion()) { - SmallString<128> USR; - index::generateUSRForDecl(Decl, USR); - API.removeRecord(USR); - } - + // Keep anonymous structs in the hierarchy to preserve path components return Ret; } @@ -620,13 +608,7 @@ template <typename Derived> bool ExtractAPIVisitorBase<Derived>::TraverseCXXRecordDecl( CXXRecordDecl *Decl) { bool Ret = Base::TraverseCXXRecordDecl(Decl); - - if (!isEmbeddedInVarDeclarator(*Decl) && Decl->isAnonymousStructOrUnion()) { - SmallString<128> USR; - index::generateUSRForDecl(Decl, USR); - API.removeRecord(USR); - } - + // Keep anonymous structs in the hierarchy to preserve path components return Ret; } @@ -643,6 +625,11 @@ bool ExtractAPIVisitorBase<Derived>::VisitCXXRecordDecl( SmallString<128> USR; index::generateUSRForDecl(Decl, USR); + + if (auto *USRRecord = API.findRecordForUSR(USR)) { + return true; + } + PresumedLoc Loc = Context.getSourceManager().getPresumedLoc(Decl->getLocation()); DocComment Comment; @@ -679,6 +666,13 @@ bool ExtractAPIVisitorBase<Derived>::VisitCXXRecordDecl( Record->KindForDisplay = getKindForDisplay(Decl); Record->Bases = getBases(Decl); + // Visit nested records + for (const auto *NestedDecl : Decl->decls()) { + if (auto *NestedRecord = dyn_cast<CXXRecordDecl>(NestedDecl)) { + VisitCXXRecordDecl(NestedRecord); + } + } + return true; } `````````` </details> https://github.com/llvm/llvm-project/pull/159698 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
