[clang] 916b434 - Sema: add support for `__attribute__((__swift_objc_members__))`
Saleem Abdulrasool via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 14 08:36:57 PDT 2020
Author: Saleem Abdulrasool
Date: 2020-09-14T15:24:41Z
New Revision: 916b43403588a85425bbc82712427cf53ed877cc
URL: https://github.com/llvm/llvm-project/commit/916b43403588a85425bbc82712427cf53ed877cc
DIFF: https://github.com/llvm/llvm-project/commit/916b43403588a85425bbc82712427cf53ed877cc.diff
LOG: Sema: add support for `__attribute__((__swift_objc_members__))`
This adds the `__swift_objc_members__` attribute to the semantic
analysis. It allows for annotating ObjC interfaces to provide Swift
semantics indicating that the types derived from this interface will be
back-bridged to Objective-C to allow interoperability with Objective-C
and Swift.
This is based on the work of the original changes in
https://github.com/llvm/llvm-project-staging/commit/8afaf3aad2af43cfedca7a24cd817848c4e95c0c
Differential Revision: https://reviews.llvm.org/D87395
Reviewed By: Aaron Ballman, Dmitri Gribenko
Added:
clang/test/SemaObjC/attr-swift_objc_members.m
Modified:
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/Misc/pragma-attribute-supported-attributes-list.test
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td
index 1790ae01497fb..3221cf23c4b53 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2130,6 +2130,12 @@ def Regparm : TypeAttr {
let ASTNode = 0;
}
+def SwiftObjCMembers : Attr {
+ let Spellings = [GNU<"swift_objc_members">];
+ let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
+ let Documentation = [SwiftObjCMembersDocs];
+}
+
def SwiftError : InheritableAttr {
let Spellings = [GNU<"swift_error">];
let Args = [
diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td
index 2fffc0daabee3..939f52dae3d5a 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -3476,6 +3476,16 @@ Swift.
}];
}
+def SwiftObjCMembersDocs : Documentation {
+ let Category = SwiftDocs;
+ let Heading = "swift_objc_members";
+ let Content = [{
+This attribute indicates that Swift subclasses and members of Swift extensions
+of this class will be implicitly marked with the ``@objcMembers`` Swift
+attribute, exposing them back to Objective-C.
+ }];
+}
+
def SwiftErrorDocs : Documentation {
let Category = SwiftDocs;
let Heading = "swift_error";
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index e317211d8bee8..bf9d8497f5a26 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -7536,6 +7536,9 @@ static void ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D,
case ParsedAttr::AT_SwiftError:
handleSwiftError(S, D, AL);
break;
+ case ParsedAttr::AT_SwiftObjCMembers:
+ handleSimpleAttribute<SwiftObjCMembersAttr>(S, D, AL);
+ break;
// XRay attributes.
case ParsedAttr::AT_XRayLogArgs:
diff --git a/clang/test/Misc/pragma-attribute-supported-attributes-list.test b/clang/test/Misc/pragma-attribute-supported-attributes-list.test
index 12800b9d54eaa..dcf7cd2b7f1a4 100644
--- a/clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ b/clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -150,6 +150,7 @@
// CHECK-NEXT: SwiftError (SubjectMatchRule_function, SubjectMatchRule_objc_method)
// CHECK-NEXT: SwiftErrorResult (SubjectMatchRule_variable_is_parameter)
// CHECK-NEXT: SwiftIndirectResult (SubjectMatchRule_variable_is_parameter)
+// CHECK-NEXT: SwiftObjCMembers (SubjectMatchRule_objc_interface)
// CHECK-NEXT: TLSModel (SubjectMatchRule_variable_is_thread_local)
// CHECK-NEXT: Target (SubjectMatchRule_function)
// CHECK-NEXT: TestTypestate (SubjectMatchRule_function_is_member)
diff --git a/clang/test/SemaObjC/attr-swift_objc_members.m b/clang/test/SemaObjC/attr-swift_objc_members.m
new file mode 100644
index 0000000000000..81328b6245947
--- /dev/null
+++ b/clang/test/SemaObjC/attr-swift_objc_members.m
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -verify -fsyntax-only %s
+
+#if !__has_attribute(swift_objc_members)
+#error cannot verify presence of swift_objc_members attribute
+#endif
+
+__attribute__((__swift_objc_members__))
+__attribute__((__objc_root_class__))
+ at interface I
+ at end
+
+__attribute__((swift_objc_members))
+ at protocol P
+ at end
+// expected-error at -3 {{'swift_objc_members' attribute only applies to Objective-C interfaces}}
+
+__attribute__((swift_objc_members))
+extern void f(void);
+// expected-error at -2 {{'swift_objc_members' attribute only applies to Objective-C interfaces}}
+
+// expected-error at +1 {{'__swift_objc_members__' attribute takes no arguments}}
+__attribute__((__swift_objc_members__("J")))
+ at interface J
+ at end
More information about the cfe-commits
mailing list