diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -2177,6 +2177,11 @@ let HasCustomParsing = 1; } +def SwiftPrivate : InheritableAttr { + let Spellings = [GNU<"swift_private">]; + let Documentation = [SwiftPrivateDocs]; +} + def NoDeref : TypeAttr { let Spellings = [Clang<"noderef">]; let Documentation = [NoDerefDocs]; diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -3713,6 +3713,19 @@ }]; } +def SwiftPrivateDocs : Documentation { + let Category = SwiftDocs; + let Heading = "swift_private"; + let Content = [{ +Declarations marked with the ``swift_private`` attribute are hidden from the +framework client but are still made available for use within the framework or +Swift SDK overlay. + +The purpose of this attribute is to permit a more idomatic implementation of +declarations in Swift while hiding the non-idiomatic one. + }]; +} + def OMPDeclareSimdDocs : Documentation { let Category = DocCatFunction; let Heading = "#pragma omp declare simd"; diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -7899,6 +7899,9 @@ case ParsedAttr::AT_SwiftObjCMembers: handleSimpleAttribute(S, D, AL); break; + case ParsedAttr::AT_SwiftPrivate: + handleSimpleAttribute(S, D, AL); + break; // XRay attributes. case ParsedAttr::AT_XRayLogArgs: diff --git a/clang/test/AST/attr-swift_private.m b/clang/test/AST/attr-swift_private.m new file mode 100644 --- /dev/null +++ b/clang/test/AST/attr-swift_private.m @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -ast-dump %s | FileCheck %s + +@interface I +- (void)method __attribute__((__swift_private__)); +@end + +// CHECK: ObjCInterfaceDecl {{.*}} I +// CHECK: ObjCMethodDecl {{.*}} method 'void' +// CHECK: SwiftPrivateAttr + +@interface J : I +- (void)method; +@end + +// CHECK: ObjCInterfaceDecl {{.*}} J +// CHECK: ObjCMethodDecl {{.*}} method 'void' +// CHECK: SwiftPrivateAttr {{.*}} Inherited + +void f(void) __attribute__((__swift_private__)); +// CHECK: FunctionDecl {{.*}} f 'void (void)' +// CHECK: SwiftPrivateAttr + +void f(void) { +} +// CHECK: FunctionDecl {{.*}} f 'void (void)' +// CHECK: SwiftPrivateAttr {{.*}} Inherited diff --git a/clang/test/SemaObjC/attr-swift_private.m b/clang/test/SemaObjC/attr-swift_private.m new file mode 100644 --- /dev/null +++ b/clang/test/SemaObjC/attr-swift_private.m @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -verify -fsyntax-only -fobjc-arc %s + +__attribute__((__swift_private__)) +@protocol P +@end + +__attribute__((__swift_private__)) +@interface I +@end + +@interface J +@property id property __attribute__((__swift_private__)); +- (void)instanceMethod __attribute__((__swift_private__)); ++ (void)classMethod __attribute__((__swift_private__)); +@end + +void f(void) __attribute__((__swift_private__)); + +struct __attribute__((__swift_private__)) S {}; + +enum __attribute__((__swift_private__)) E { + one, + two, +}; + +typedef struct { } T __attribute__((__swift_private__)); + +void g(void) __attribute__((__swift_private__("private"))); +// expected-error@-1 {{'__swift_private__' attribute takes no arguments}}