[clang] a368402 - [ExtractAPI] merge anon declarators even if they're array types (#120801)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 29 12:03:36 PST 2025
Author: QuietMisdreavus
Date: 2025-01-29T13:03:33-07:00
New Revision: a368402d633098fc211c29f9726eef6e1874da5f
URL: https://github.com/llvm/llvm-project/commit/a368402d633098fc211c29f9726eef6e1874da5f
DIFF: https://github.com/llvm/llvm-project/commit/a368402d633098fc211c29f9726eef6e1874da5f.diff
LOG: [ExtractAPI] merge anon declarators even if they're array types (#120801)
Added:
Modified:
clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
clang/test/ExtractAPI/anonymous_record_no_typedef.c
Removed:
################################################################################
diff --git a/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h b/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
index b09b8b44d9abaa..aa86e418067114 100644
--- a/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
+++ b/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
@@ -252,6 +252,11 @@ class ExtractAPIVisitorBase : public RecursiveASTVisitor<Derived> {
if (!NewRecordContext)
return;
auto *Tag = D.getType()->getAsTagDecl();
+ if (!Tag) {
+ if (const auto *AT = D.getASTContext().getAsArrayType(D.getType())) {
+ Tag = AT->getElementType()->getAsTagDecl();
+ }
+ }
SmallString<128> TagUSR;
clang::index::generateUSRForDecl(Tag, TagUSR);
if (auto *Record = llvm::dyn_cast_if_present<TagRecord>(
diff --git a/clang/test/ExtractAPI/anonymous_record_no_typedef.c b/clang/test/ExtractAPI/anonymous_record_no_typedef.c
index c0c76ef1f06b57..d278cbb8ec348b 100644
--- a/clang/test/ExtractAPI/anonymous_record_no_typedef.c
+++ b/clang/test/ExtractAPI/anonymous_record_no_typedef.c
@@ -191,4 +191,44 @@ union Vector {
// VEC-DAG: "!testRelLabel": "memberOf $ c:@U at Vector@Sa at FI@X $ c:@U at Vector"
// VEC-DAG: "!testRelLabel": "memberOf $ c:@U at Vector@Sa at FI@Y $ c:@U at Vector"
+// RUN: FileCheck %s --input-file %t/output-c.symbols.json --check-prefix MYSTRUCT
+// RUN: FileCheck %s --input-file %t/output-cxx.symbols.json --check-prefix MYSTRUCT
+// RUN: FileCheck %s --input-file %t/output-c.symbols.json --check-prefix COUNTS
+// RUN: FileCheck %s --input-file %t/output-cxx.symbols.json --check-prefix COUNTS
+struct MyStruct {
+ struct {
+ int count;
+ } counts[1];
+};
+// MYSTRUCT-NOT: "spelling": ""
+// MYSTRUCT-NOT: "title": ""
+
+// COUNTS-LABEL: "!testLabel": "c:@S at MyStruct@FI at counts"
+// COUNTS: "declarationFragments": [
+// COUNTS-NEXT: {
+// COUNTS-NEXT: "kind": "keyword",
+// COUNTS-NEXT: "spelling": "struct"
+// COUNTS-NEXT: },
+// COUNTS-NEXT: {
+// COUNTS-NEXT: "kind": "text",
+// COUNTS-NEXT: "spelling": " { ... } "
+// COUNTS-NEXT: },
+// COUNTS-NEXT: {
+// COUNTS-NEXT: "kind": "identifier",
+// COUNTS-NEXT: "spelling": "counts"
+// COUNTS-NEXT: },
+// COUNTS-NEXT: {
+// COUNTS-NEXT: "kind": "text",
+// COUNTS-NEXT: "spelling": "["
+// COUNTS-NEXT: },
+// COUNTS-NEXT: {
+// COUNTS-NEXT: "kind": "number",
+// COUNTS-NEXT: "spelling": "1"
+// COUNTS-NEXT: },
+// COUNTS-NEXT: {
+// COUNTS-NEXT: "kind": "text",
+// COUNTS-NEXT: "spelling": "];"
+// COUNTS-NEXT: }
+// COUNTS-NEXT: ],
+
// expected-no-diagnostics
More information about the cfe-commits
mailing list