Skip to content

Commit a368402

Browse files
[ExtractAPI] merge anon declarators even if they're array types (#120801)
1 parent bac9575 commit a368402

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
@@ -191,4 +191,44 @@ union Vector {
191191
// VEC-DAG: "!testRelLabel": "memberOf $ c:@U@Vector@Sa@FI@X $ c:@U@Vector"
192192
// VEC-DAG: "!testRelLabel": "memberOf $ c:@U@Vector@Sa@FI@Y $ c:@U@Vector"
193193

194+
// RUN: FileCheck %s --input-file %t/output-c.symbols.json --check-prefix MYSTRUCT
195+
// RUN: FileCheck %s --input-file %t/output-cxx.symbols.json --check-prefix MYSTRUCT
196+
// RUN: FileCheck %s --input-file %t/output-c.symbols.json --check-prefix COUNTS
197+
// RUN: FileCheck %s --input-file %t/output-cxx.symbols.json --check-prefix COUNTS
198+
struct MyStruct {
199+
struct {
200+
int count;
201+
} counts[1];
202+
};
203+
// MYSTRUCT-NOT: "spelling": ""
204+
// MYSTRUCT-NOT: "title": ""
205+
206+
// COUNTS-LABEL: "!testLabel": "c:@S@MyStruct@FI@counts"
207+
// COUNTS: "declarationFragments": [
208+
// COUNTS-NEXT: {
209+
// COUNTS-NEXT: "kind": "keyword",
210+
// COUNTS-NEXT: "spelling": "struct"
211+
// COUNTS-NEXT: },
212+
// COUNTS-NEXT: {
213+
// COUNTS-NEXT: "kind": "text",
214+
// COUNTS-NEXT: "spelling": " { ... } "
215+
// COUNTS-NEXT: },
216+
// COUNTS-NEXT: {
217+
// COUNTS-NEXT: "kind": "identifier",
218+
// COUNTS-NEXT: "spelling": "counts"
219+
// COUNTS-NEXT: },
220+
// COUNTS-NEXT: {
221+
// COUNTS-NEXT: "kind": "text",
222+
// COUNTS-NEXT: "spelling": "["
223+
// COUNTS-NEXT: },
224+
// COUNTS-NEXT: {
225+
// COUNTS-NEXT: "kind": "number",
226+
// COUNTS-NEXT: "spelling": "1"
227+
// COUNTS-NEXT: },
228+
// COUNTS-NEXT: {
229+
// COUNTS-NEXT: "kind": "text",
230+
// COUNTS-NEXT: "spelling": "];"
231+
// COUNTS-NEXT: }
232+
// COUNTS-NEXT: ],
233+
194234
// expected-no-diagnostics

0 commit comments

Comments
 (0)