Skip to content

Commit 924930d

Browse files
committed
[apinotes] Add support for global functions in namespaces.
1 parent 8e7ea0c commit 924930d

File tree

4 files changed

+37
-13
lines changed

4 files changed

+37
-13
lines changed

clang/lib/Sema/SemaAPINotes.cpp

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -835,18 +835,6 @@ void Sema::ProcessAPINotes(Decl *D) {
835835
return;
836836
}
837837

838-
// Global functions.
839-
if (auto FD = dyn_cast<FunctionDecl>(D)) {
840-
if (FD->getDeclName().isIdentifier()) {
841-
for (auto Reader : APINotes.findAPINotes(D->getLocation())) {
842-
auto Info = Reader->lookupGlobalFunction(FD->getName());
843-
ProcessVersionedAPINotes(*this, FD, Info);
844-
}
845-
}
846-
847-
return;
848-
}
849-
850838
// Objective-C classes.
851839
if (auto Class = dyn_cast<ObjCInterfaceDecl>(D)) {
852840
for (auto Reader : APINotes.findAPINotes(D->getLocation())) {
@@ -946,6 +934,31 @@ void Sema::ProcessAPINotes(Decl *D) {
946934
auto Info = Reader->lookupMemberFunction(Name);
947935
ProcessVersionedAPINotes(*this, Method, Info);
948936
}
937+
938+
return;
939+
}
940+
941+
// Global functions.
942+
if (auto FD = dyn_cast<FunctionDecl>(D)) {
943+
if (FD->getDeclName().isIdentifier()) {
944+
for (auto Reader : APINotes.findAPINotes(D->getLocation())) {
945+
std::string Name = FD->getName().str();
946+
947+
auto parent = FD->getParent();
948+
while (isa<clang::NamespaceDecl>(parent)) {
949+
if (auto Namespace = dyn_cast<clang::NamespaceDecl>(parent)) {
950+
Name = Namespace->getNameAsString() + "." + Name;
951+
}
952+
953+
parent = parent->getParent();
954+
}
955+
956+
auto Info = Reader->lookupGlobalFunction(Name);
957+
ProcessVersionedAPINotes(*this, FD, Info);
958+
}
959+
}
960+
961+
return;
949962
}
950963

951964
if (auto Namespace = dyn_cast<NamespaceDecl>(D)) {
@@ -954,6 +967,8 @@ void Sema::ProcessAPINotes(Decl *D) {
954967
ProcessAPINotes(Member);
955968
}
956969
}
970+
971+
return;
957972
}
958973

959974
// Enumerators.

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,7 @@ Tags:
2020
- Name: ParentNS.ChildNS.ParentStruct.ChildStruct
2121
Methods:
2222
- Name: 'method'
23-
SwiftName: nestedMethod()
23+
SwiftName: nestedMethod()
24+
Functions:
25+
- Name: ParentNS.ChildNS.gloablFnInNS
26+
SwiftName: childFnInNS()

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ struct GlobalStruct {
3030
namespace ParentNS {
3131
namespace ChildNS {
3232

33+
void gloablFnInNS();
34+
3335
struct ParentStruct {
3436
int x;
3537
struct ChildStruct {

clang/test/APINotes/objcxx-swift-name.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// RUN: %clang_cc1 -fmodules -fblocks -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache/CxxInterop -fdisable-module-hash -fapinotes-modules -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -x objective-c++
33
// RUN: %clang_cc1 -fmodules -fblocks -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache/CxxInterop -fdisable-module-hash -fapinotes-modules -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -ast-dump -ast-dump-filter SomeClass -x objective-c++ | FileCheck %s
44
// RUN: %clang_cc1 -fmodules -fblocks -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache/CxxInterop -fdisable-module-hash -fapinotes-modules -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -ast-dump -ast-dump-filter method -x objective-c++ | FileCheck -check-prefix=CHECK-METHOD %s
5+
// RUN: %clang_cc1 -fmodules -fblocks -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache/CxxInterop -fdisable-module-hash -fapinotes-modules -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -ast-dump -ast-dump-filter gloablFnInNS -x objective-c++ | FileCheck -check-prefix=CHECK-FN %s
56
// RUN: %clang_cc1 -fmodules -fblocks -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache/CxxInterop -fdisable-module-hash -fapinotes-modules -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -ast-dump -ast-dump-filter "(anonymous)" -x objective-c++ | FileCheck -check-prefix=CHECK-ANONYMOUS-ENUM %s
67

78
#import <CXXInteropKit/CXXInteropKit.h>
@@ -24,6 +25,9 @@
2425
// CHECK-METHOD: Dumping ParentNS::ChildNS::ParentStruct::ChildStruct::method:
2526
// CHECK-METHOD: SwiftNameAttr {{.+}} <<invalid sloc>> "nestedMethod()"
2627

28+
// CHECK-FN: Dumping ParentNS::ChildNS::gloablFnInNS:
29+
// CHECK-FN: SwiftNameAttr {{.+}} <<invalid sloc>> "childFnInNS()"
30+
2731
// CHECK-ANONYMOUS-ENUM: Dumping (anonymous):
2832
// CHECK-ANONYMOUS-ENUM-NEXT: EnumDecl {{.+}} imported in CXXInteropKit <undeserialized declarations> 'NSSomeEnumOptions':'unsigned long'
2933
// CHECK-ANONYMOUS-ENUM-NEXT: SwiftNameAttr {{.+}} <<invalid sloc>> "SomeEnum.Options"

0 commit comments

Comments
 (0)