Skip to content

Commit 49206b7

Browse files
[ExtractAPI] merge anon declarators even if they're array types (llvm#120801)
1 parent 6d9fdaf commit 49206b7

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

clang/include/clang/ExtractAPI/ExtractAPIVisitor.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,11 @@ class ExtractAPIVisitorBase : public RecursiveASTVisitor<Derived> {
252252
if (!NewRecordContext)
253253
return;
254254
auto *Tag = D.getType()->getAsTagDecl();
255+
if (!Tag) {
256+
if (const auto *AT = D.getASTContext().getAsArrayType(D.getType())) {
257+
Tag = AT->getElementType()->getAsTagDecl();
258+
}
259+
}
255260
SmallString<128> TagUSR;
256261
clang::index::generateUSRForDecl(Tag, TagUSR);
257262
if (auto *Record = llvm::dyn_cast_if_present<TagRecord>(

clang/test/ExtractAPI/anonymous_record_no_typedef.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,4 +175,44 @@ union Vector {
175175
// VEC-DAG: "!testRelLabel": "memberOf $ c:@U@Vector@Sa@FI@X $ c:@U@Vector"
176176
// VEC-DAG: "!testRelLabel": "memberOf $ c:@U@Vector@Sa@FI@Y $ c:@U@Vector"
177177

178+
// RUN: FileCheck %s --input-file %t/output-c.symbols.json --check-prefix MYSTRUCT
179+
// RUN: FileCheck %s --input-file %t/output-cxx.symbols.json --check-prefix MYSTRUCT
180+
// RUN: FileCheck %s --input-file %t/output-c.symbols.json --check-prefix COUNTS
181+
// RUN: FileCheck %s --input-file %t/output-cxx.symbols.json --check-prefix COUNTS
182+
struct MyStruct {
183+
struct {
184+
int count;
185+
} counts[1];
186+
};
187+
// MYSTRUCT-NOT: "spelling": ""
188+
// MYSTRUCT-NOT: "title": ""
189+
190+
// COUNTS-LABEL: "!testLabel": "c:@S@MyStruct@FI@counts"
191+
// COUNTS: "declarationFragments": [
192+
// COUNTS-NEXT: {
193+
// COUNTS-NEXT: "kind": "keyword",
194+
// COUNTS-NEXT: "spelling": "struct"
195+
// COUNTS-NEXT: },
196+
// COUNTS-NEXT: {
197+
// COUNTS-NEXT: "kind": "text",
198+
// COUNTS-NEXT: "spelling": " { ... } "
199+
// COUNTS-NEXT: },
200+
// COUNTS-NEXT: {
201+
// COUNTS-NEXT: "kind": "identifier",
202+
// COUNTS-NEXT: "spelling": "counts"
203+
// COUNTS-NEXT: },
204+
// COUNTS-NEXT: {
205+
// COUNTS-NEXT: "kind": "text",
206+
// COUNTS-NEXT: "spelling": "["
207+
// COUNTS-NEXT: },
208+
// COUNTS-NEXT: {
209+
// COUNTS-NEXT: "kind": "number",
210+
// COUNTS-NEXT: "spelling": "1"
211+
// COUNTS-NEXT: },
212+
// COUNTS-NEXT: {
213+
// COUNTS-NEXT: "kind": "text",
214+
// COUNTS-NEXT: "spelling": "];"
215+
// COUNTS-NEXT: }
216+
// COUNTS-NEXT: ],
217+
178218
// expected-no-diagnostics

0 commit comments

Comments
 (0)