]> granicus.if.org Git - clang/commitdiff
ObjectiveC ARC. objc_bridge attribute should be applied to
authorFariborz Jahanian <fjahanian@apple.com>
Thu, 14 Nov 2013 00:43:05 +0000 (00:43 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Thu, 14 Nov 2013 00:43:05 +0000 (00:43 +0000)
toll-free bridging cf types only. // rdar//15454846 wip.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194640 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclAttr.cpp
test/SemaObjC/objcbridge-attribute.m

index 46a85c59b521819a0c87786d9eeb398556d9f18e..30ddd4d51d6366cf657e883969c1e1aa930b92ad 100644 (file)
@@ -207,10 +207,9 @@ static inline bool isCFStringType(QualType T, ASTContext &Ctx) {
   return RD->getIdentifier() == &Ctx.Idents.get("__CFString");
 }
 
-static inline bool isCFRefType(TypedefNameDecl *TD, ASTContext &Ctx) {
+static inline bool isTollFreeBridgeCFRefType(TypedefNameDecl *TD, ASTContext &Ctx) {
   StringRef TDName = TD->getIdentifier()->getName();
-  return ((TDName.startswith("CF") || TDName.startswith("CG")) &&
-          (TDName.rfind("Ref") != StringRef::npos));
+  return (TDName.startswith("CF") && TDName.endswith("Ref"));
 }
 
 static unsigned getNumAttributeArgs(const AttributeList &Attr) {
@@ -4414,7 +4413,7 @@ static void handleObjCBridgeAttr(Sema &S, Scope *Sc, Decl *D,
       return;
     }
     // Check for T being a CFType goes here.
-    if (!isCFRefType(TD, S.Context)) {
+    if (!isTollFreeBridgeCFRefType(TD, S.Context)) {
       S.Diag(TD->getLocStart(), diag::err_objc_bridge_not_cftype);
       return;
     }
index 797f00be546ffa1fb2a7f54e8adb19c51b768b1f..33c0e3f27af24bb120778a5048ea4eaf07be72b3 100644 (file)
@@ -1,25 +1,25 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s
 // rdar://15454846
 
-typedef struct CGColor * __attribute__ ((objc_bridge(NSError))) CGColorRef;
+typedef struct __CFColor * __attribute__ ((objc_bridge(NSError))) CFColorRef;
 
-typedef struct CGColor * __attribute__((objc_bridge(12))) CFMyColorRef; // expected-error {{parameter of 'objc_bridge' attribute must be a single name of an Objective-C class}}
+typedef struct __CFMyColor  * __attribute__((objc_bridge(12))) CFMyColorRef; // expected-error {{parameter of 'objc_bridge' attribute must be a single name of an Objective-C class}}
 
-typedef struct S1 *  __attribute__ ((objc_bridge)) CGColorRef1; // expected-error {{parameter of 'objc_bridge' attribute must be a single name of an Objective-C class}}
+typedef struct __CFArray *  __attribute__ ((objc_bridge)) CFArrayRef; // expected-error {{parameter of 'objc_bridge' attribute must be a single name of an Objective-C class}}
 
-typedef void *  __attribute__ ((objc_bridge(NSString))) CGColorRef2
+typedef void *  __attribute__ ((objc_bridge(NSString))) CFRef
 
 typedef void * CFTypeRef __attribute__ ((objc_bridge(NSError)));
 
-typedef struct CGColor * __attribute__((objc_bridge(NSString, NSError))) CGColorRefNoNSObject;// expected-error {{use of undeclared identifier 'NSError'}}
+typedef struct __CFLocale * __attribute__((objc_bridge(NSString, NSError))) CFLocaleRef;// expected-error {{use of undeclared identifier 'NSError'}}
 
-typedef struct CGColor __attribute__((objc_bridge(NSError))) CGColorRefNoNSObject2; // expected-error {{'objc_bridge' attribute must be applied to a pointer type}}
+typedef struct __CFData __attribute__((objc_bridge(NSError))) CFDataRef; // expected-error {{'objc_bridge' attribute must be applied to a pointer type}}
 
-typedef struct __attribute__((objc_bridge(NSError))) CFColor * CFColorRefNoNSObject; // expected-error {{'objc_bridge' attribute must be put on a typedef only}}
+typedef struct __attribute__((objc_bridge(NSError))) __CFDictionary * CFDictionaryRef; // expected-error {{'objc_bridge' attribute must be put on a typedef only}}
 
-typedef struct __attribute__((objc_bridge(NSError))) CFColor * CFColorRefNoNSObject1;
+typedef struct __CFObject * CFObjectRef __attribute__((objc_bridge(NSError)));
 
-typedef union CFUColor * __attribute__((objc_bridge(NSError))) CFColorRefNoNSObject2; // expected-error {{'objc_bridge' attribute only applies to structs}}
+typedef union __CFUColor * __attribute__((objc_bridge(NSError))) CFUColorRef; // expected-error {{'objc_bridge' attribute only applies to structs}}
 
 @interface I
 {