Skip to content

Commit 769486d

Browse files
authored
Merge pull request #7871 from DougGregor/apinotes-anon-tags-with-typedef-names
2 parents d23d90c + 5e56bb2 commit 769486d

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
@@ -908,7 +908,15 @@ void Sema::ProcessAPINotes(Decl *D) {
908908

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

913921
// Use the source location to discern if this Tag is an OPTIONS macro.
914922
// 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
@@ -5041,6 +5041,9 @@ void Sema::setTagNameForLinkagePurposes(TagDecl *TagFromDeclSpec,
50415041

50425042
// Otherwise, set this as the anon-decl typedef for the tag.
50435043
TagFromDeclSpec->setTypedefNameForAnonDecl(NewTD);
5044+
5045+
// Now that we have a name for the tag, process API notes again.
5046+
ProcessAPINotes(TagFromDeclSpec);
50445047
}
50455048

50465049
static unsigned GetDiagnosticTypeSpecifierID(const DeclSpec &DS) {

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)