From: Fariborz Jahanian Date: Thu, 14 Nov 2013 00:43:05 +0000 (+0000) Subject: ObjectiveC ARC. objc_bridge attribute should be applied to X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7f82297e3f0d2bd9c8aab4fe4eded17572b0fce0;p=clang ObjectiveC ARC. objc_bridge attribute should be applied to 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 --- diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 46a85c59b5..30ddd4d51d 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -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; } diff --git a/test/SemaObjC/objcbridge-attribute.m b/test/SemaObjC/objcbridge-attribute.m index 797f00be54..33c0e3f27a 100644 --- a/test/SemaObjC/objcbridge-attribute.m +++ b/test/SemaObjC/objcbridge-attribute.m @@ -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 {