[clang] e57b9c0 - [ExtractAPI] Include availability attributes for anonymous typedefs (#209187)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 17 08:42:37 PDT 2026
Author: Prajwal Nadig
Date: 2026-07-17T16:42:31+01:00
New Revision: e57b9c0761706905e42da3cfa485cebc3629d72a
URL: https://github.com/llvm/llvm-project/commit/e57b9c0761706905e42da3cfa485cebc3629d72a
DIFF: https://github.com/llvm/llvm-project/commit/e57b9c0761706905e42da3cfa485cebc3629d72a.diff
LOG: [ExtractAPI] Include availability attributes for anonymous typedefs (#209187)
When an anonymous type is defined and has availability attributes, the
attributes are attached to the typedef rather than the type being
defined. This patch updates the anonymous type handling logic to merge
the availability from the typedef in order to correctly include it in
the symbol graph.
rdar://125497949
Added:
clang/test/ExtractAPI/availability_typedef_anonymous_record.c
Modified:
clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
Removed:
################################################################################
diff --git a/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h b/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
index 38f57eeeddc3a..f716231645723 100644
--- a/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
+++ b/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
@@ -602,16 +602,20 @@ bool ExtractAPIVisitorBase<Derived>::VisitRecordDecl(const RecordDecl *Decl) {
DeclarationFragments SubHeading =
DeclarationFragmentsBuilder::getSubHeading(Decl);
+ AvailabilityInfo Availability = AvailabilityInfo::createFromDecl(Decl);
+ if (const auto *TypedefDecl = Decl->getTypedefNameForAnonDecl())
+ Availability.mergeWith(AvailabilityInfo::createFromDecl(TypedefDecl));
+
if (Decl->isUnion())
API.createRecord<UnionRecord>(
- USR, Name, createHierarchyInformationForDecl(*Decl), Loc,
- AvailabilityInfo::createFromDecl(Decl), Comment, Declaration,
- SubHeading, isInSystemHeader(Decl), isEmbeddedInVarDeclarator(*Decl));
+ USR, Name, createHierarchyInformationForDecl(*Decl), Loc, Availability,
+ Comment, Declaration, SubHeading, isInSystemHeader(Decl),
+ isEmbeddedInVarDeclarator(*Decl));
else
API.createRecord<StructRecord>(
- USR, Name, createHierarchyInformationForDecl(*Decl), Loc,
- AvailabilityInfo::createFromDecl(Decl), Comment, Declaration,
- SubHeading, isInSystemHeader(Decl), isEmbeddedInVarDeclarator(*Decl));
+ USR, Name, createHierarchyInformationForDecl(*Decl), Loc, Availability,
+ Comment, Declaration, SubHeading, isInSystemHeader(Decl),
+ isEmbeddedInVarDeclarator(*Decl));
return true;
}
diff --git a/clang/test/ExtractAPI/availability_typedef_anonymous_record.c b/clang/test/ExtractAPI/availability_typedef_anonymous_record.c
new file mode 100644
index 0000000000000..b1eba9d9eb534
--- /dev/null
+++ b/clang/test/ExtractAPI/availability_typedef_anonymous_record.c
@@ -0,0 +1,24 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -extract-api --pretty-sgf --emit-sgf-symbol-labels-for-testing -triple arm64-apple-macosx \
+// RUN: -x c-header %s -o %t/output.symbols.json -verify
+
+// RUN: FileCheck %s --input-file %t/output.symbols.json --check-prefix STRUCT
+
+typedef struct {
+ int x;
+} MyStruct __attribute__((availability(macos, introduced=12.0)));
+
+// STRUCT-LABEL: "!testLabel": "c:@SA at MyStruct"
+// STRUCT: "availability": [
+// STRUCT-NEXT: {
+// STRUCT-NEXT: "domain": "macos",
+// STRUCT-NEXT: "introduced": {
+// STRUCT-NEXT: "major": 12,
+// STRUCT-NEXT: "minor": 0,
+// STRUCT-NEXT: "patch": 0
+// STRUCT-NEXT: }
+// STRUCT-NEXT: }
+// STRUCT-NEXT: ]
+// STRUCT: "title": "MyStruct"
+
+// expected-no-diagnostics
More information about the cfe-commits
mailing list