Skip to content

Commit 005f019

Browse files
authored
Merge pull request #7874 from DougGregor/apinotes-anon-tags-with-typedef-names-5.10
[API Notes] Allow tag-based API notes on anonymous tag decls with typedef names
2 parents 57d4e30 + c6312d0 commit 005f019

File tree

6 files changed

+22
-2
lines changed

6 files changed

+22
-2
lines changed

clang/lib/Sema/SemaAPINotes.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,15 @@ void Sema::ProcessAPINotes(Decl *D) {
906906

907907
// Tags
908908
if (auto Tag = dyn_cast<TagDecl>(D)) {
909-
std::string LookupName = Tag->getName().str();
909+
// Determine the name of the entity to search for. If this is an
910+
// anonymous tag that gets its linked name from a typedef, look for the
911+
// typedef name. This allows tag-specific information to be added
912+
// to the declaration.
913+
std::string LookupName;
914+
if (auto typedefName = Tag->getTypedefNameForAnonDecl())
915+
LookupName = typedefName->getName().str();
916+
else
917+
LookupName = Tag->getName().str();
910918

911919
// Use the source location to discern if this Tag is an OPTIONS macro.
912920
// For now we would like to limit this trick of looking up the APINote tag

clang/lib/Sema/SemaDecl.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5026,6 +5026,9 @@ void Sema::setTagNameForLinkagePurposes(TagDecl *TagFromDeclSpec,
50265026

50275027
// Otherwise, set this as the anon-decl typedef for the tag.
50285028
TagFromDeclSpec->setTypedefNameForAnonDecl(NewTD);
5029+
5030+
// Now that we have a name for the tag, process API notes again.
5031+
ProcessAPINotes(TagFromDeclSpec);
50295032
}
50305033

50315034
static unsigned GetDiagnosticTypeSpecifierID(DeclSpec::TST T) {

clang/test/APINotes/Inputs/Frameworks/SimpleKit.framework/Headers/SimpleKit.apinotes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,5 @@ Tags:
4646
SwiftName: SuccessfullyRenamedA
4747
- Name: RenamedAgainInAPINotesB
4848
SwiftName: SuccessfullyRenamedB
49+
- Name: AnonEnumWithTypedefName
50+
SwiftName: SuccessfullyRenamedC

clang/test/APINotes/Inputs/Frameworks/SimpleKit.framework/Headers/SimpleKit.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@ void *getCFAuditedToNone_DUMP(void);
2727
- (id)getOwnedToUnowned __attribute__((__ns_returns_retained__));
2828
- (id)getUnownedToOwned __attribute__((__ns_returns_not_retained__));
2929
@end
30+
31+
typedef enum {
32+
kConstantInAnonEnum
33+
} AnonEnumWithTypedefName;

clang/test/APINotes/types.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
// CHECK: struct __attribute__((swift_name("SuccessfullyRenamedA"))) RenamedAgainInAPINotesA {
99
// CHECK: struct __attribute__((swift_name("SuccessfullyRenamedB"))) RenamedAgainInAPINotesB {
10+
// CHECK: typedef enum __attribute__((swift_name("SuccessfullyRenamedC"))) {
11+
// CHECK-NEXT: kConstantInAnonEnum
12+
// CHECK-NEXT: } AnonEnumWithTypedefName
1013

1114
void test(OverriddenTypes *overridden) {
1215
int *ip1 = global_int_ptr; // expected-warning{{incompatible pointer types initializing 'int *' with an expression of type 'double (*)(int, int)'}}

clang/test/APINotes/yaml-roundtrip-2.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ REQUIRES: shell
77

88
We expect only the document markers to be emitted
99

10-
CHECK: 50d
10+
CHECK: 52d
1111
CHECK: 1d

0 commit comments

Comments
 (0)