From 8f27871ff0eb5b01896e457d3928c7a683e50153 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Fri, 22 Nov 2013 00:02:22 +0000 Subject: [PATCH] ObjectiveC migrator. Improve on definition, use and testing of objc_bridgmutable attribute per Aaron Ballman's comments. // rdar://15498044 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@195396 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/Attr.td | 4 ++-- lib/Sema/SemaDeclAttr.cpp | 8 ++------ test/SemaObjC/objcbridge-attribute-arc.m | 2 +- test/SemaObjC/objcbridge-attribute.m | 2 +- test/SemaObjC/objcbridgemutable-attribute.m | 14 +++++++++++++- test/SemaObjCXX/objcbridge-attribute-arc.mm | 2 +- test/SemaObjCXX/objcbridge-attribute.mm | 2 +- 7 files changed, 21 insertions(+), 13 deletions(-) diff --git a/include/clang/Basic/Attr.td b/include/clang/Basic/Attr.td index 416da74362..33115c664e 100644 --- a/include/clang/Basic/Attr.td +++ b/include/clang/Basic/Attr.td @@ -548,13 +548,13 @@ def NSBridged : InheritableAttr { def ObjCBridge : InheritableAttr { let Spellings = [GNU<"objc_bridge">]; let Subjects = [Record]; - let Args = [IdentifierArgument<"BridgedType", 1>]; + let Args = [IdentifierArgument<"BridgedType">]; } def ObjCBridgeMutable : InheritableAttr { let Spellings = [GNU<"objc_bridge_mutable">]; let Subjects = [Record]; - let Args = [IdentifierArgument<"BridgedType", 1>]; + let Args = [IdentifierArgument<"BridgedType">]; } def NSReturnsRetained : InheritableAttr { diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 8b3d738c60..1f6e40164c 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -4348,9 +4348,7 @@ static void handleObjCBridgeAttr(Sema &S, Scope *Sc, Decl *D, return; } - IdentifierLoc *Parm = 0; - if (Attr.getNumArgs() == 1) - Parm = Attr.isArgIdent(0) ? Attr.getArgAsIdent(0) : 0; + IdentifierLoc * Parm = Attr.isArgIdent(0) ? Attr.getArgAsIdent(0) : 0; if (!Parm) { S.Diag(D->getLocStart(), diag::err_objc_attr_not_id) << Attr.getName() << 0; @@ -4372,9 +4370,7 @@ static void handleObjCBridgeMutableAttr(Sema &S, Scope *Sc, Decl *D, return; } - IdentifierLoc *Parm = 0; - if (Attr.getNumArgs() == 1) - Parm = Attr.isArgIdent(0) ? Attr.getArgAsIdent(0) : 0; + IdentifierLoc * Parm = Attr.isArgIdent(0) ? Attr.getArgAsIdent(0) : 0; if (!Parm) { S.Diag(D->getLocStart(), diag::err_objc_attr_not_id) << Attr.getName() << 0; diff --git a/test/SemaObjC/objcbridge-attribute-arc.m b/test/SemaObjC/objcbridge-attribute-arc.m index 9b67523a50..b2830ff82d 100644 --- a/test/SemaObjC/objcbridge-attribute-arc.m +++ b/test/SemaObjC/objcbridge-attribute-arc.m @@ -7,7 +7,7 @@ typedef struct __attribute__ ((objc_bridge(MyError))) __CFMyErrorRef * CFMyError typedef struct __attribute__((objc_bridge(12))) __CFMyColor *CFMyColorRef; // expected-error {{parameter of 'objc_bridge' attribute must be a single name of an Objective-C class}} -typedef struct __attribute__ ((objc_bridge)) __CFArray *CFArrayRef; // expected-error {{parameter of 'objc_bridge' attribute must be a single name of an Objective-C class}} +typedef struct __attribute__ ((objc_bridge)) __CFArray *CFArrayRef; // expected-error {{'objc_bridge' attribute takes one argument}} typedef void * __attribute__ ((objc_bridge(NSURL))) CFURLRef; // expected-error {{'objc_bridge' attribute only applies to struct or union}} diff --git a/test/SemaObjC/objcbridge-attribute.m b/test/SemaObjC/objcbridge-attribute.m index 8be4b2d5f0..36b3d604c7 100644 --- a/test/SemaObjC/objcbridge-attribute.m +++ b/test/SemaObjC/objcbridge-attribute.m @@ -7,7 +7,7 @@ typedef struct __attribute__ ((objc_bridge(MyError))) __CFMyErrorRef * CFMyError typedef struct __attribute__((objc_bridge(12))) __CFMyColor *CFMyColorRef; // expected-error {{parameter of 'objc_bridge' attribute must be a single name of an Objective-C class}} -typedef struct __attribute__ ((objc_bridge)) __CFArray *CFArrayRef; // expected-error {{parameter of 'objc_bridge' attribute must be a single name of an Objective-C class}} +typedef struct __attribute__ ((objc_bridge)) __CFArray *CFArrayRef; // expected-error {{'objc_bridge' attribute takes one argument}} typedef void * __attribute__ ((objc_bridge(NSURL))) CFURLRef; // expected-error {{'objc_bridge' attribute only applies to struct or union}} diff --git a/test/SemaObjC/objcbridgemutable-attribute.m b/test/SemaObjC/objcbridgemutable-attribute.m index 52989f960c..4ec8de0b54 100644 --- a/test/SemaObjC/objcbridgemutable-attribute.m +++ b/test/SemaObjC/objcbridgemutable-attribute.m @@ -3,17 +3,29 @@ typedef struct __attribute__((objc_bridge_mutable(NSMutableDictionary))) __CFDictionary * CFMutableDictionaryRef; // expected-note {{declared here}} +typedef struct __attribute__((objc_bridge_mutable(12))) __CFDictionaryB1 * CFMutableDictionaryB1Ref; // expected-error {{parameter of 'objc_bridge_mutable' attribute must be a single name of an Objective-C class}} + +typedef struct __attribute__((objc_bridge_mutable(P))) __CFDictionaryB2 * CFMutableDictionaryB2Ref; // expected-note {{declared here}} + +typedef struct __attribute__((objc_bridge_mutable(NSMutableDictionary, Unknown))) __CFDictionaryB3 * CFMutableDictionaryB3Ref; // expected-error {{use of undeclared identifier 'Unknown'}} + +typedef struct __attribute__((objc_bridge_mutable)) __CFDictionaryB4 * CFMutableDictionaryB4Ref; // expected-error {{'objc_bridge_mutable' attribute takes one argument}} + @interface NSDictionary @end @interface NSMutableDictionary : NSDictionary @end -void Test(NSMutableDictionary *md, NSDictionary *nd, CFMutableDictionaryRef mcf) { +@protocol P @end + +void Test(NSMutableDictionary *md, NSDictionary *nd, CFMutableDictionaryRef mcf, CFMutableDictionaryB2Ref bmcf) { (void) (CFMutableDictionaryRef)md; (void) (CFMutableDictionaryRef)nd; // expected-warning {{'NSDictionary' cannot bridge to 'CFMutableDictionaryRef' (aka 'struct __CFDictionary *')}} (void) (NSDictionary *)mcf; // expected-warning {{'CFMutableDictionaryRef' (aka 'struct __CFDictionary *') bridges to NSMutableDictionary, not 'NSDictionary'}} (void) (NSMutableDictionary *)mcf; // ok; + (void) (NSMutableDictionary *)bmcf; // expected-error {{CF object of type 'CFMutableDictionaryB2Ref' (aka 'struct __CFDictionaryB2 *') is bridged to 'P', which is not an Objective-C class}} + } diff --git a/test/SemaObjCXX/objcbridge-attribute-arc.mm b/test/SemaObjCXX/objcbridge-attribute-arc.mm index fa67dfb72d..39cba2a842 100644 --- a/test/SemaObjCXX/objcbridge-attribute-arc.mm +++ b/test/SemaObjCXX/objcbridge-attribute-arc.mm @@ -7,7 +7,7 @@ typedef struct __attribute__ ((objc_bridge(MyError))) __CFMyErrorRef * CFMyError typedef struct __attribute__((objc_bridge(12))) __CFMyColor *CFMyColorRef; // expected-error {{parameter of 'objc_bridge' attribute must be a single name of an Objective-C class}} -typedef struct __attribute__ ((objc_bridge)) __CFArray *CFArrayRef; // expected-error {{parameter of 'objc_bridge' attribute must be a single name of an Objective-C class}} +typedef struct __attribute__ ((objc_bridge)) __CFArray *CFArrayRef; // expected-error {{'objc_bridge' attribute takes one argument}} typedef void * __attribute__ ((objc_bridge(NSURL))) CFURLRef; // expected-error {{'objc_bridge' attribute only applies to struct, union or class}} diff --git a/test/SemaObjCXX/objcbridge-attribute.mm b/test/SemaObjCXX/objcbridge-attribute.mm index 3e23cdbba4..d7a9c65da8 100644 --- a/test/SemaObjCXX/objcbridge-attribute.mm +++ b/test/SemaObjCXX/objcbridge-attribute.mm @@ -7,7 +7,7 @@ typedef struct __attribute__ ((objc_bridge(MyError))) __CFMyErrorRef * CFMyError typedef struct __attribute__((objc_bridge(12))) __CFMyColor *CFMyColorRef; // expected-error {{parameter of 'objc_bridge' attribute must be a single name of an Objective-C class}} -typedef struct __attribute__ ((objc_bridge)) __CFArray *CFArrayRef; // expected-error {{parameter of 'objc_bridge' attribute must be a single name of an Objective-C class}} +typedef struct __attribute__ ((objc_bridge)) __CFArray *CFArrayRef; // expected-error {{'objc_bridge' attribute takes one argument}} typedef void * __attribute__ ((objc_bridge(NSURL))) CFURLRef; // expected-error {{'objc_bridge' attribute only applies to struct, union or class}} -- 2.40.0