[PATCH] D87396: Sema: add support for `__attribute__((__swift_typedef_bridged__))`

2020-09-14 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd updated this revision to Diff 291621.
compnerd added a comment.

- Add additional test case that was requested


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87396/new/

https://reviews.llvm.org/D87396

Files:
  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
  clang/test/SemaObjC/attr-swift_bridged_typedef.m


Index: clang/test/SemaObjC/attr-swift_bridged_typedef.m
===
--- /dev/null
+++ clang/test/SemaObjC/attr-swift_bridged_typedef.m
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -verify -fsyntax-only %s
+
+@interface NSString
+@end
+
+typedef NSString *NSStringAlias __attribute__((__swift_bridged_typedef__));
+
+typedef int IntAlias __attribute__((__swift_bridged_typedef__));
+
+struct __attribute__((swift_bridged_typedef)) S {};
+// expected-error@-1 {{'swift_bridged_typedef' attribute only applies to 
typedefs}}
+
+// expected-error@+1 {{'__swift_bridged_typedef__' attribute takes no 
arguments}}
+typedef unsigned char UnsignedChar 
__attribute__((__swift_bridged_typedef__("UnsignedChar")));
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -146,6 +146,7 @@
 // CHECK-NEXT: Section (SubjectMatchRule_function, 
SubjectMatchRule_variable_is_global, SubjectMatchRule_objc_method, 
SubjectMatchRule_objc_property)
 // CHECK-NEXT: SetTypestate (SubjectMatchRule_function_is_member)
 // CHECK-NEXT: SpeculativeLoadHardening (SubjectMatchRule_function, 
SubjectMatchRule_objc_method)
+// CHECK-NEXT: SwiftBridgedTypedef (SubjectMatchRule_type_alias)
 // CHECK-NEXT: SwiftContext (SubjectMatchRule_variable_is_parameter)
 // CHECK-NEXT: SwiftError (SubjectMatchRule_function, 
SubjectMatchRule_objc_method)
 // CHECK-NEXT: SwiftErrorResult (SubjectMatchRule_variable_is_parameter)
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -7533,6 +7533,9 @@
 break;
 
   // Swift attributes.
+  case ParsedAttr::AT_SwiftBridgedTypedef:
+handleSimpleAttribute(S, D, AL);
+break;
   case ParsedAttr::AT_SwiftError:
 handleSwiftError(S, D, AL);
 break;
Index: clang/include/clang/Basic/AttrDocs.td
===
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -3476,6 +3476,27 @@
   }];
 }
 
+def SwiftBridgedTypedefDocs : Documentation {
+  let Category = SwiftDocs;
+  let Heading = "swift_bridged";
+  let Content = [{
+The ``swift_bridged_typedef`` attribute indicates that when the typedef to 
which
+the attribute appertains is imported into Swift, it should refer to the bridged
+Swift type (e.g. Swift's ``String``) rather than the Objective-C type as 
written
+(e.g. ``NSString``).
+
+  .. code-block:: c
+
+@interface NSString;
+typedef NSString *AliasedString __attribute__((__swift_bridged_typedef__));
+
+extern void acceptsAliasedString(AliasedString _Nonnull parameter);
+
+In this case, the function ``acceptsAliasedString`` will be imported into Swift
+as a function which accepts a ``String`` type parameter.
+  }];
+}
+
 def SwiftObjCMembersDocs : Documentation {
   let Category = SwiftDocs;
   let Heading = "swift_objc_members";
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -2130,6 +2130,12 @@
   let ASTNode = 0;
 }
 
+def SwiftBridgedTypedef : Attr {
+  let Spellings = [GNU<"swift_bridged_typedef">];
+  let Subjects = SubjectList<[TypedefName], ErrorDiag>;
+  let Documentation = [SwiftBridgedTypedefDocs];
+}
+
 def SwiftObjCMembers : Attr {
   let Spellings = [GNU<"swift_objc_members">];
   let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;


Index: clang/test/SemaObjC/attr-swift_bridged_typedef.m
===
--- /dev/null
+++ clang/test/SemaObjC/attr-swift_bridged_typedef.m
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -verify -fsyntax-only %s
+
+@interface NSString
+@end
+
+typedef NSString *NSStringAlias __attribute__((__swift_bridged_typedef__));
+
+typedef int IntAlias __attribute__((__swift_bridged_typedef__));
+
+struct __attribute__((swift_bridged_typedef)) S {};
+// expected-error@-1 {{'swift_bridged_typedef' attribute only applies to typedefs}}
+
+// expected-error@+1 {{'__swift_bridged_typedef__' attribute takes no arguments}}
+typedef unsigned char UnsignedChar __attribute__((__swift_bridged_typedef__("UnsignedChar")));
Index: 

[PATCH] D87396: Sema: add support for `__attribute__((__swift_typedef_bridged__))`

2020-09-14 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd updated this revision to Diff 291587.
compnerd added a comment.

Add additional test case


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87396/new/

https://reviews.llvm.org/D87396

Files:
  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
  clang/test/SemaObjC/attr-swift_bridged_typedef.m


Index: clang/test/SemaObjC/attr-swift_bridged_typedef.m
===
--- /dev/null
+++ clang/test/SemaObjC/attr-swift_bridged_typedef.m
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -verify -fsyntax-only %s
+
+@interface NSString
+@end
+
+typedef NSString *NSStringAlias __attribute__((__swift_bridged_typedef__));
+
+typedef int IntAlias __attribute__((__swift_bridged_typedef__));
+
+struct __attribute__((swift_bridged_typedef)) S {};
+// expected-error@-1 {{'swift_bridged_typedef' attribute only applies to 
typedefs}}
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -146,6 +146,7 @@
 // CHECK-NEXT: Section (SubjectMatchRule_function, 
SubjectMatchRule_variable_is_global, SubjectMatchRule_objc_method, 
SubjectMatchRule_objc_property)
 // CHECK-NEXT: SetTypestate (SubjectMatchRule_function_is_member)
 // CHECK-NEXT: SpeculativeLoadHardening (SubjectMatchRule_function, 
SubjectMatchRule_objc_method)
+// CHECK-NEXT: SwiftBridgedTypedef (SubjectMatchRule_type_alias)
 // CHECK-NEXT: SwiftContext (SubjectMatchRule_variable_is_parameter)
 // CHECK-NEXT: SwiftError (SubjectMatchRule_function, 
SubjectMatchRule_objc_method)
 // CHECK-NEXT: SwiftErrorResult (SubjectMatchRule_variable_is_parameter)
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -7533,6 +7533,9 @@
 break;
 
   // Swift attributes.
+  case ParsedAttr::AT_SwiftBridgedTypedef:
+handleSimpleAttribute(S, D, AL);
+break;
   case ParsedAttr::AT_SwiftError:
 handleSwiftError(S, D, AL);
 break;
Index: clang/include/clang/Basic/AttrDocs.td
===
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -3476,6 +3476,27 @@
   }];
 }
 
+def SwiftBridgedTypedefDocs : Documentation {
+  let Category = SwiftDocs;
+  let Heading = "swift_bridged";
+  let Content = [{
+The ``swift_bridged_typedef`` attribute indicates that when the typedef to 
which
+the attribute appertains is imported into Swift, it should refer to the bridged
+Swift type (e.g. Swift's ``String``) rather than the Objective-C type as 
written
+(e.g. ``NSString``).
+
+  .. code-block:: c
+
+@interface NSString;
+typedef NSString *AliasedString __attribute__((__swift_bridged_typedef__));
+
+extern void acceptsAliasedString(AliasedString _Nonnull parameter);
+
+In this case, the function ``acceptsAliasedString`` will be imported into Swift
+as a function which accepts a ``String`` type parameter.
+  }];
+}
+
 def SwiftObjCMembersDocs : Documentation {
   let Category = SwiftDocs;
   let Heading = "swift_objc_members";
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -2130,6 +2130,12 @@
   let ASTNode = 0;
 }
 
+def SwiftBridgedTypedef : Attr {
+  let Spellings = [GNU<"swift_bridged_typedef">];
+  let Subjects = SubjectList<[TypedefName], ErrorDiag>;
+  let Documentation = [SwiftBridgedTypedefDocs];
+}
+
 def SwiftObjCMembers : Attr {
   let Spellings = [GNU<"swift_objc_members">];
   let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;


Index: clang/test/SemaObjC/attr-swift_bridged_typedef.m
===
--- /dev/null
+++ clang/test/SemaObjC/attr-swift_bridged_typedef.m
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -verify -fsyntax-only %s
+
+@interface NSString
+@end
+
+typedef NSString *NSStringAlias __attribute__((__swift_bridged_typedef__));
+
+typedef int IntAlias __attribute__((__swift_bridged_typedef__));
+
+struct __attribute__((swift_bridged_typedef)) S {};
+// expected-error@-1 {{'swift_bridged_typedef' attribute only applies to typedefs}}
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -146,6 +146,7 @@
 // CHECK-NEXT: Section (SubjectMatchRule_function, SubjectMatchRule_variable_is_global, 

[PATCH] D87396: Sema: add support for `__attribute__((__swift_typedef_bridged__))`

2020-09-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:7543
+  case ParsedAttr::AT_SwiftBridgedTypedef:
+handleSimpleAttribute(S, D, AL);
+break;

compnerd wrote:
> aaron.ballman wrote:
> > compnerd wrote:
> > > aaron.ballman wrote:
> > > > Should there be any type checking that the underlying type of the 
> > > > typedef is a sensible one to bridge?
> > > I can't really think of anything that you could check that would be 
> > > valuable.  What types of things were you thinking?
> > I was mostly thinking about builtin types like `int`, but I don't insist.
> Typedefing `int` to something else and importing that with a different name 
> is reasonable I believe.  I'll add a test case.
Okay, perfect, thank you for verifying!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87396/new/

https://reviews.llvm.org/D87396

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87396: Sema: add support for `__attribute__((__swift_typedef_bridged__))`

2020-09-14 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd marked an inline comment as done.
compnerd added inline comments.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:7543
+  case ParsedAttr::AT_SwiftBridgedTypedef:
+handleSimpleAttribute(S, D, AL);
+break;

aaron.ballman wrote:
> compnerd wrote:
> > aaron.ballman wrote:
> > > Should there be any type checking that the underlying type of the typedef 
> > > is a sensible one to bridge?
> > I can't really think of anything that you could check that would be 
> > valuable.  What types of things were you thinking?
> I was mostly thinking about builtin types like `int`, but I don't insist.
Typedefing `int` to something else and importing that with a different name is 
reasonable I believe.  I'll add a test case.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87396/new/

https://reviews.llvm.org/D87396

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87396: Sema: add support for `__attribute__((__swift_typedef_bridged__))`

2020-09-14 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:2123
+  let Spellings = [GNU<"swift_bridged_typedef">];
+  let Subjects = SubjectList<[TypedefName], ErrorDiag, "typedefs">;
+  let Documentation = [SwiftBridgedTypedefDocs];

aaron.ballman wrote:
> compnerd wrote:
> > aaron.ballman wrote:
> > > Does the default diagnostic text generate something bad that caused you 
> > > to add `typedefs` here?
> > I don't remember, I'll double check.
> I noticed on a few other reviews that there was a field there, I wonder if 
> the code originated before we added smarter logic for arbitrary subject lists.
Yes, this code is definitely old.  If there are sites that you notice that 
could be changed to something new,  Im happy to work though those changes.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87396/new/

https://reviews.llvm.org/D87396

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87396: Sema: add support for `__attribute__((__swift_typedef_bridged__))`

2020-09-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:2123
+  let Spellings = [GNU<"swift_bridged_typedef">];
+  let Subjects = SubjectList<[TypedefName], ErrorDiag, "typedefs">;
+  let Documentation = [SwiftBridgedTypedefDocs];

compnerd wrote:
> aaron.ballman wrote:
> > Does the default diagnostic text generate something bad that caused you to 
> > add `typedefs` here?
> I don't remember, I'll double check.
I noticed on a few other reviews that there was a field there, I wonder if the 
code originated before we added smarter logic for arbitrary subject lists.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:7543
+  case ParsedAttr::AT_SwiftBridgedTypedef:
+handleSimpleAttribute(S, D, AL);
+break;

compnerd wrote:
> aaron.ballman wrote:
> > Should there be any type checking that the underlying type of the typedef 
> > is a sensible one to bridge?
> I can't really think of anything that you could check that would be valuable. 
>  What types of things were you thinking?
I was mostly thinking about builtin types like `int`, but I don't insist.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87396/new/

https://reviews.llvm.org/D87396

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87396: Sema: add support for `__attribute__((__swift_typedef_bridged__))`

2020-09-11 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd updated this revision to Diff 291346.
compnerd edited the summary of this revision.
compnerd added a comment.

Address feedback


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87396/new/

https://reviews.llvm.org/D87396

Files:
  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
  clang/test/SemaObjC/attr-swift_bridged_typedef.m


Index: clang/test/SemaObjC/attr-swift_bridged_typedef.m
===
--- /dev/null
+++ clang/test/SemaObjC/attr-swift_bridged_typedef.m
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -verify -fsyntax-only %s
+
+@interface NSString
+@end
+
+typedef NSString *NSStringAlias __attribute__((__swift_bridged_typedef__));
+
+struct __attribute__((swift_bridged_typedef)) S {};
+// expected-error@-1 {{'swift_bridged_typedef' attribute only applies to 
typedefs}}
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -146,6 +146,7 @@
 // CHECK-NEXT: Section (SubjectMatchRule_function, 
SubjectMatchRule_variable_is_global, SubjectMatchRule_objc_method, 
SubjectMatchRule_objc_property)
 // CHECK-NEXT: SetTypestate (SubjectMatchRule_function_is_member)
 // CHECK-NEXT: SpeculativeLoadHardening (SubjectMatchRule_function, 
SubjectMatchRule_objc_method)
+// CHECK-NEXT: SwiftBridgedTypedef (SubjectMatchRule_type_alias)
 // CHECK-NEXT: SwiftContext (SubjectMatchRule_variable_is_parameter)
 // CHECK-NEXT: SwiftError (SubjectMatchRule_function, 
SubjectMatchRule_objc_method)
 // CHECK-NEXT: SwiftErrorResult (SubjectMatchRule_variable_is_parameter)
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -7533,6 +7533,9 @@
 break;
 
   // Swift attributes.
+  case ParsedAttr::AT_SwiftBridgedTypedef:
+handleSimpleAttribute(S, D, AL);
+break;
   case ParsedAttr::AT_SwiftError:
 handleSwiftError(S, D, AL);
 break;
Index: clang/include/clang/Basic/AttrDocs.td
===
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -3476,6 +3476,27 @@
   }];
 }
 
+def SwiftBridgedTypedefDocs : Documentation {
+  let Category = SwiftDocs;
+  let Heading = "swift_bridged";
+  let Content = [{
+The ``swift_bridged_typedef`` attribute indicates that when the typedef to 
which
+the attribute appertains is imported into Swift, it should refer to the bridged
+Swift type (e.g. Swift's ``String``) rather than the Objective-C type as 
written
+(e.g. ``NSString``).
+
+  .. code-block:: c
+
+@interface NSString;
+typedef NSString *AliasedString __attribute__((__swift_bridged_typedef__));
+
+extern void acceptsAliasedString(AliasedString _Nonnull parameter);
+
+In this case, the function ``acceptsAliasedString`` will be imported into Swift
+as a function which accepts a ``String`` type parameter.
+  }];
+}
+
 def SwiftObjCMembersDocs : Documentation {
   let Category = SwiftDocs;
   let Heading = "swift_objc_members";
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -2130,6 +2130,12 @@
   let ASTNode = 0;
 }
 
+def SwiftBridgedTypedef : Attr {
+  let Spellings = [GNU<"swift_bridged_typedef">];
+  let Subjects = SubjectList<[TypedefName], ErrorDiag>;
+  let Documentation = [SwiftBridgedTypedefDocs];
+}
+
 def SwiftObjCMembers : Attr {
   let Spellings = [GNU<"swift_objc_members">];
   let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;


Index: clang/test/SemaObjC/attr-swift_bridged_typedef.m
===
--- /dev/null
+++ clang/test/SemaObjC/attr-swift_bridged_typedef.m
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -verify -fsyntax-only %s
+
+@interface NSString
+@end
+
+typedef NSString *NSStringAlias __attribute__((__swift_bridged_typedef__));
+
+struct __attribute__((swift_bridged_typedef)) S {};
+// expected-error@-1 {{'swift_bridged_typedef' attribute only applies to typedefs}}
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -146,6 +146,7 @@
 // CHECK-NEXT: Section (SubjectMatchRule_function, SubjectMatchRule_variable_is_global, SubjectMatchRule_objc_method, SubjectMatchRule_objc_property)
 // CHECK-NEXT: SetTypestate 

[PATCH] D87396: Sema: add support for `__attribute__((__swift_typedef_bridged__))`

2020-09-11 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:2121
 
+def SwiftBridgedTypedef : Attr {
+  let Spellings = [GNU<"swift_bridged_typedef">];

aaron.ballman wrote:
> Should this be inherited on redeclarations?
I don't see why not.  @rjmccall, @doug.gregor any reason to not permit this to 
be inherited by redeclarations? 



Comment at: clang/include/clang/Basic/Attr.td:2123
+  let Spellings = [GNU<"swift_bridged_typedef">];
+  let Subjects = SubjectList<[TypedefName], ErrorDiag, "typedefs">;
+  let Documentation = [SwiftBridgedTypedefDocs];

aaron.ballman wrote:
> Does the default diagnostic text generate something bad that caused you to 
> add `typedefs` here?
I don't remember, I'll double check.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:7543
+  case ParsedAttr::AT_SwiftBridgedTypedef:
+handleSimpleAttribute(S, D, AL);
+break;

aaron.ballman wrote:
> Should there be any type checking that the underlying type of the typedef is 
> a sensible one to bridge?
I can't really think of anything that you could check that would be valuable.  
What types of things were you thinking?



Comment at: clang/test/SemaObjC/attr-swift_bridged_typedef.m:8
+
+struct __attribute__((swift_bridged_typedef)) S {};
+// expected-error@-1 {{'swift_bridged_typedef' attribute only applies to 
typedefs}}

aaron.ballman wrote:
> Please also add some examples where the attribute has arguments. Also, should 
> this work in Objective-C++ when using a `using` type alias? If so, an example 
> showing that working would also be helpful.
I don't know about the ObjC++11 case with the `using`.  @doug.gregor or 
@rjmccall?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87396/new/

https://reviews.llvm.org/D87396

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87396: Sema: add support for `__attribute__((__swift_typedef_bridged__))`

2020-09-10 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:2121
 
+def SwiftBridgedTypedef : Attr {
+  let Spellings = [GNU<"swift_bridged_typedef">];

Should this be inherited on redeclarations?



Comment at: clang/include/clang/Basic/Attr.td:2123
+  let Spellings = [GNU<"swift_bridged_typedef">];
+  let Subjects = SubjectList<[TypedefName], ErrorDiag, "typedefs">;
+  let Documentation = [SwiftBridgedTypedefDocs];

Does the default diagnostic text generate something bad that caused you to add 
`typedefs` here?



Comment at: clang/include/clang/Basic/AttrDocs.td:3389
+Swift type (e.g. Swift's ``String``) rather than the Objective-C type as 
written
+(e.g. ``NSString``).
+  }];

I think it would be helpful to show the `String` vs `NSString` behavior in a 
short code example of how to use the attribute.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:7543
+  case ParsedAttr::AT_SwiftBridgedTypedef:
+handleSimpleAttribute(S, D, AL);
+break;

Should there be any type checking that the underlying type of the typedef is a 
sensible one to bridge?



Comment at: clang/test/SemaObjC/attr-swift_bridged_typedef.m:8
+
+struct __attribute__((swift_bridged_typedef)) S {};
+// expected-error@-1 {{'swift_bridged_typedef' attribute only applies to 
typedefs}}

Please also add some examples where the attribute has arguments. Also, should 
this work in Objective-C++ when using a `using` type alias? If so, an example 
showing that working would also be helpful.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87396/new/

https://reviews.llvm.org/D87396

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87396: Sema: add support for `__attribute__((__swift_typedef_bridged__))`

2020-09-09 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd created this revision.
compnerd added a reviewer: aaron.ballman.
Herald added a reviewer: jdoerfert.
Herald added a project: clang.
compnerd requested review of this revision.

Extend the semantic attributes that clang processes for Swift to include
`swift_typedef_bridged`.  This attribute enables typedefs to be bridged
into Swift with a bridged name.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87396

Files:
  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
  clang/test/SemaObjC/attr-swift_bridged_typedef.m


Index: clang/test/SemaObjC/attr-swift_bridged_typedef.m
===
--- /dev/null
+++ clang/test/SemaObjC/attr-swift_bridged_typedef.m
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -verify -fsyntax-only %s
+
+@interface NSString
+@end
+
+typedef NSString *NSStringAlias __attribute__((__swift_bridged_typedef__));
+
+struct __attribute__((swift_bridged_typedef)) S {};
+// expected-error@-1 {{'swift_bridged_typedef' attribute only applies to 
typedefs}}
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -146,6 +146,7 @@
 // CHECK-NEXT: Section (SubjectMatchRule_function, 
SubjectMatchRule_variable_is_global, SubjectMatchRule_objc_method, 
SubjectMatchRule_objc_property)
 // CHECK-NEXT: SetTypestate (SubjectMatchRule_function_is_member)
 // CHECK-NEXT: SpeculativeLoadHardening (SubjectMatchRule_function, 
SubjectMatchRule_objc_method)
+// CHECK-NEXT: SwiftBridgedTypedef (SubjectMatchRule_type_alias)
 // CHECK-NEXT: SwiftContext (SubjectMatchRule_variable_is_parameter)
 // CHECK-NEXT: SwiftError (SubjectMatchRule_function, 
SubjectMatchRule_objc_method)
 // CHECK-NEXT: SwiftErrorResult (SubjectMatchRule_variable_is_parameter)
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -7539,6 +7539,9 @@
 break;
 
   // Swift attributes.
+  case ParsedAttr::AT_SwiftBridgedTypedef:
+handleSimpleAttribute(S, D, AL);
+break;
   case ParsedAttr::AT_SwiftError:
 handleSwiftError(S, D, AL);
 break;
Index: clang/include/clang/Basic/AttrDocs.td
===
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -3381,6 +3381,15 @@
   }];
 }
 
+def SwiftBridgedTypedefDocs : Documentation {
+  let Content = [{
+The ``swift_bridged_typedef`` attribute indicates that when the typedef to 
which
+the attribute appertains is imported into Swift, it should refer to the bridged
+Swift type (e.g. Swift's ``String``) rather than the Objective-C type as 
written
+(e.g. ``NSString``).
+  }];
+}
+
 def SwiftObjCMembersDocs : Documentation {
   let Content = [{
 The ``swift_objc_members`` attribute maps to the ``@objcMembers`` Swift
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -2118,6 +2118,12 @@
   let ASTNode = 0;
 }
 
+def SwiftBridgedTypedef : Attr {
+  let Spellings = [GNU<"swift_bridged_typedef">];
+  let Subjects = SubjectList<[TypedefName], ErrorDiag, "typedefs">;
+  let Documentation = [SwiftBridgedTypedefDocs];
+}
+
 def SwiftObjCMembers : Attr {
   let Spellings = [GNU<"swift_objc_members">];
   let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;


Index: clang/test/SemaObjC/attr-swift_bridged_typedef.m
===
--- /dev/null
+++ clang/test/SemaObjC/attr-swift_bridged_typedef.m
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -verify -fsyntax-only %s
+
+@interface NSString
+@end
+
+typedef NSString *NSStringAlias __attribute__((__swift_bridged_typedef__));
+
+struct __attribute__((swift_bridged_typedef)) S {};
+// expected-error@-1 {{'swift_bridged_typedef' attribute only applies to typedefs}}
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -146,6 +146,7 @@
 // CHECK-NEXT: Section (SubjectMatchRule_function, SubjectMatchRule_variable_is_global, SubjectMatchRule_objc_method, SubjectMatchRule_objc_property)
 // CHECK-NEXT: SetTypestate (SubjectMatchRule_function_is_member)
 // CHECK-NEXT: SpeculativeLoadHardening (SubjectMatchRule_function, SubjectMatchRule_objc_method)
+// CHECK-NEXT: SwiftBridgedTypedef (SubjectMatchRule_type_alias)
 // CHECK-NEXT: