]> granicus.if.org Git - clang/commitdiff
Look for declaration of CFBridgingRetain/CFBridgingRetain before
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 1 Feb 2012 22:56:20 +0000 (22:56 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 1 Feb 2012 22:56:20 +0000 (22:56 +0000)
changing the diagnostic. Also use correct spelling for both.

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

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaExprObjC.cpp
test/ARCMT/checking.m
test/ARCMT/no-canceling-bridge-to-bridge-cast.m
test/ARCMT/nonobjc-to-objc-cast-2.m
test/SemaObjC/arc-bridged-cast.m
test/SemaObjC/arc-cf.m
test/SemaObjC/arc-type-conversion.m
test/SemaObjC/arc-unbridged-cast.m
test/SemaObjC/arc.m
test/SemaObjCXX/arc-unbridged-cast.mm

index 52de6ca26ef1084f78d5e6a5b25f30a3bdb2b7a1..ff3b1d6e31d80a582ac5318f8c204766ff121628 100644 (file)
@@ -3318,9 +3318,11 @@ def err_arc_cast_requires_bridge : Error<
 def note_arc_bridge : Note<
   "use __bridge to convert directly (no change in ownership)">;
 def note_arc_bridge_transfer : Note<
-  "use CFBridgeRelease call to transfer ownership of a +1 %0 into ARC">;
+  "use %select{__bridge_transfer|CFBridgingRelease call}1 to transfer "
+  "ownership of a +1 %0 into ARC">;
 def note_arc_bridge_retained : Note<
-  "use CFBridgeRetain call to make an ARC object available as a +1 %0">;
+  "use %select{__bridge_retained|CFBridgingRetain call}1 to make an "
+  "ARC object available as a +1 %0">;
 
 } // ARC Casting category
 
index 483e7eab23230b6492364bc1da6d0567e970894e..82e8171d66614442fd8e22771c2f30c2eb8a8f2c 100644 (file)
@@ -1902,6 +1902,13 @@ namespace {
   };
 }
 
+static bool
+KnownName(Sema &S, const char *name) {
+  LookupResult R(S, &S.Context.Idents.get(name), SourceLocation(),
+                 Sema::LookupOrdinaryName);
+  return S.LookupName(R, S.TUScope, false);
+}
+
 static void
 diagnoseObjCARCConversion(Sema &S, SourceRange castRange,
                           QualType castType, ARCConversionTypeClass castACTC,
@@ -1937,6 +1944,7 @@ diagnoseObjCARCConversion(Sema &S, SourceRange castRange,
 
   // Bridge from an ARC type to a CF type.
   if (castACTC == ACTC_retainable && isAnyRetainable(exprACTC)) {
+
     S.Diag(loc, diag::err_arc_cast_requires_bridge)
       << unsigned(CCK == Sema::CCK_ImplicitConversion) // cast|implicit
       << 2 // of C pointer type
@@ -1945,20 +1953,22 @@ diagnoseObjCARCConversion(Sema &S, SourceRange castRange,
       << castType
       << castRange
       << castExpr->getSourceRange();
-
+    bool br = KnownName(S, "CFBridgingRelease");
     S.Diag(noteLoc, diag::note_arc_bridge)
       << (CCK != Sema::CCK_CStyleCast ? FixItHint() :
             FixItHint::CreateInsertion(afterLParen, "__bridge "));
     S.Diag(noteLoc, diag::note_arc_bridge_transfer)
-      << castExprType
+      << castExprType << br 
       << (CCK != Sema::CCK_CStyleCast ? FixItHint() :
-            FixItHint::CreateInsertion(afterLParen, "CFBridgeRelease "));
+          FixItHint::CreateInsertion(afterLParen, 
+                                br ? "CFBridgingRelease " : "__bridge_transfer "));
 
     return;
   }
     
   // Bridge from a CF type to an ARC type.
   if (exprACTC == ACTC_retainable && isAnyRetainable(castACTC)) {
+    bool br = KnownName(S, "CFBridgingRetain");
     S.Diag(loc, diag::err_arc_cast_requires_bridge)
       << unsigned(CCK == Sema::CCK_ImplicitConversion) // cast|implicit
       << unsigned(castExprType->isBlockPointerType()) // of ObjC|block type
@@ -1972,9 +1982,10 @@ diagnoseObjCARCConversion(Sema &S, SourceRange castRange,
       << (CCK != Sema::CCK_CStyleCast ? FixItHint() :
             FixItHint::CreateInsertion(afterLParen, "__bridge "));
     S.Diag(noteLoc, diag::note_arc_bridge_retained)
-      << castType
+      << castType << br
       << (CCK != Sema::CCK_CStyleCast ? FixItHint() :
-            FixItHint::CreateInsertion(afterLParen, "CFBridgeRetain "));
+          FixItHint::CreateInsertion(afterLParen, 
+                              br ? "CFBridgingRetain " : "__bridge_retained"));
 
     return;
   }
@@ -2205,7 +2216,8 @@ ExprResult Sema::BuildObjCBridgedCast(SourceLocation LParenLoc,
     case OBC_Bridge:
       break;
       
-    case OBC_BridgeRetained:
+    case OBC_BridgeRetained: {
+      bool br = KnownName(*this, "CFBridgingRelease");
       Diag(BridgeKeywordLoc, diag::err_arc_bridge_cast_wrong_kind)
         << 2
         << FromType
@@ -2216,12 +2228,14 @@ ExprResult Sema::BuildObjCBridgedCast(SourceLocation LParenLoc,
       Diag(BridgeKeywordLoc, diag::note_arc_bridge)
         << FixItHint::CreateReplacement(BridgeKeywordLoc, "__bridge");
       Diag(BridgeKeywordLoc, diag::note_arc_bridge_transfer)
-        << FromType
+        << FromType << br
         << FixItHint::CreateReplacement(BridgeKeywordLoc, 
-                                        "CFBridgeRelease ");
+                                        br ? "CFBridgingRelease " 
+                                           : "__bridge_transfer ");
 
       Kind = OBC_Bridge;
       break;
+    }
       
     case OBC_BridgeTransfer:
       // We must consume the Objective-C object produced by the cast.
@@ -2245,7 +2259,8 @@ ExprResult Sema::BuildObjCBridgedCast(SourceLocation LParenLoc,
                                          SubExpr, 0, VK_RValue);
       break;
       
-    case OBC_BridgeTransfer:
+    case OBC_BridgeTransfer: {
+      bool br = KnownName(*this, "CFBridgingRetain");
       Diag(BridgeKeywordLoc, diag::err_arc_bridge_cast_wrong_kind)
         << (FromType->isBlockPointerType()? 1 : 0)
         << FromType
@@ -2257,12 +2272,14 @@ ExprResult Sema::BuildObjCBridgedCast(SourceLocation LParenLoc,
       Diag(BridgeKeywordLoc, diag::note_arc_bridge)
         << FixItHint::CreateReplacement(BridgeKeywordLoc, "__bridge ");
       Diag(BridgeKeywordLoc, diag::note_arc_bridge_retained)
-        << T
-        << FixItHint::CreateReplacement(BridgeKeywordLoc, "CFBridgeRetain ");
+        << T << br
+        << FixItHint::CreateReplacement(BridgeKeywordLoc, 
+                          br ? "CFBridgingRetain " : "__bridge_retained");
         
       Kind = OBC_Bridge;
       break;
     }
+    }
   } else {
     Diag(LParenLoc, diag::err_arc_bridge_cast_incompatible)
       << FromType << T << Kind
index c9b4bf13c89687c05a25917c4368f80a47312a5a..0682fd1dde3a2bb4f5276fd3f489571728b779ea 100644 (file)
@@ -7,6 +7,10 @@
 #define NS_AUTOMATED_REFCOUNT_UNAVAILABLE
 #endif
 
+typedef const void * CFTypeRef;
+CFTypeRef CFBridgingRetain(id X);
+id CFBridgingRelease(CFTypeRef);
+
 typedef int BOOL;
 typedef unsigned NSUInteger;
 
@@ -95,7 +99,7 @@ void test1(A *a, BOOL b, struct UnsafeS *unsafeS) {
   CFStringRef cfstr;
   NSString *str = (NSString *)cfstr; // expected-error {{cast of C pointer type 'CFStringRef' (aka 'const struct __CFString *') to Objective-C pointer type 'NSString *' requires a bridged cast}} \
   // expected-note {{use __bridge to convert directly (no change in ownership)}} \
-  // expected-note {{use CFBridgeRelease call to transfer ownership of a +1 'CFStringRef' (aka 'const struct __CFString *') into ARC}} \
+  // expected-note {{use CFBridgingRelease call to transfer ownership of a +1 'CFStringRef' (aka 'const struct __CFString *') into ARC}} \
   str = (NSString *)kUTTypePlainText;
   str = b ? kUTTypeRTF : kUTTypePlainText;
   str = (NSString *)(b ? kUTTypeRTF : kUTTypePlainText);
@@ -153,10 +157,10 @@ void * cvt(id arg)
   (void)(void*)voidp_val;
   (void)(void**)arg; // expected-error {{disallowed}}
   cvt((void*)arg); // expected-error 2 {{requires a bridged cast}} \
-                   // expected-note 2 {{use __bridge to}} expected-note {{use CFBridgeRelease call}} expected-note {{use CFBridgeRetain call}}
+                   // expected-note 2 {{use __bridge to}} expected-note {{use CFBridgingRelease call}} expected-note {{use CFBridgingRetain call}}
   cvt(0);
   (void)(__strong id**)(0);
-  return arg; // expected-error {{requires a bridged cast}} expected-note {{use __bridge}} expected-note {{use CFBridgeRetain call}}
+  return arg; // expected-error {{requires a bridged cast}} expected-note {{use __bridge}} expected-note {{use CFBridgingRetain call}}
 }
 
 
index fefa3aea63501b106c5732feb66954250df3a201..81841fbf1e8980fdf0aa7f7a10353f475b398833 100644 (file)
@@ -2,6 +2,8 @@
 // DISABLE: mingw32
 // rdar://10387088
 typedef const void * CFTypeRef;
+CFTypeRef CFBridgingRetain(id X);
+id CFBridgingRelease(CFTypeRef);
 
 extern 
 CFTypeRef CFRetain(CFTypeRef cf);
@@ -23,15 +25,15 @@ CFTypeRef CFRetain(CFTypeRef cf);
 
   result = (id) CFRetain([NSString stringWithFormat:@"PBXLoopMode"]); // expected-error {{cast of C pointer type 'CFTypeRef' (aka 'const void *') to Objective-C pointer type 'id' requires a bridged cast}} \
                                                                      // expected-note {{use __bridge to convert directly (no change in ownership)}} \
-                                                                     // expected-note {{use CFBridgeRelease call to transfer ownership of a +1 'CFTypeRef' (aka 'const void *') into ARC}}
+                                                                     // expected-note {{use CFBridgingRelease call to transfer ownership of a +1 'CFTypeRef' (aka 'const void *') into ARC}}
 
   result = (id) CFRetain((id)((objc_format))); // expected-error {{cast of C pointer type 'CFTypeRef' (aka 'const void *') to Objective-C pointer type 'id' requires a bridged cast}} \
                                               // expected-note {{use __bridge to convert directly (no change in ownership)}} \
-                                              // expected-note {{use CFBridgeRelease call to transfer ownership of a +1 'CFTypeRef' (aka 'const void *') into ARC}}
+                                              // expected-note {{use CFBridgingRelease call to transfer ownership of a +1 'CFTypeRef' (aka 'const void *') into ARC}}
 
   result = (id) CFRetain((id)((cf_format))); // expected-error {{cast of C pointer type 'CFTypeRef' (aka 'const void *') to Objective-C pointer type 'id' requires a bridged cast}} \
                                             // expected-note {{use __bridge to convert directly (no change in ownership)}} \
-                                             // expected-note {{use CFBridgeRelease call to transfer ownership of a +1 'CFTypeRef' (aka 'const void *') into ARC}}
+                                             // expected-note {{use CFBridgingRelease call to transfer ownership of a +1 'CFTypeRef' (aka 'const void *') into ARC}}
 
   result = (id) CFRetain((CFTypeRef)((objc_format)));
 
index 52d635b531bdbe8a200429b2603d34488f34b243..1ec0089f08e8189771555e99e05e265057619add 100644 (file)
@@ -9,13 +9,16 @@
 @end
 
 typedef const struct __CFString * CFStringRef;
+typedef const void * CFTypeRef;
+CFTypeRef CFBridgingRetain(id X);
+id CFBridgingRelease(CFTypeRef);
 
 void f(BOOL b) {
   CFStringRef cfstr;
   NSString *str = (NSString *)cfstr; // expected-error {{cast of C pointer type 'CFStringRef' (aka 'const struct __CFString *') to Objective-C pointer type 'NSString *' requires a bridged cast}} \
     // expected-note{{use __bridge to convert directly (no change in ownership)}} \
-    // expected-note{{use CFBridgeRelease call to transfer ownership of a +1 'CFStringRef' (aka 'const struct __CFString *') into ARC}}
-  void *vp = str;  // expected-error {{requires a bridged cast}} expected-note {{use CFBridgeRetain call}} expected-note {{use __bridge}}
+    // expected-note{{use CFBridgingRelease call to transfer ownership of a +1 'CFStringRef' (aka 'const struct __CFString *') into ARC}}
+  void *vp = str;  // expected-error {{requires a bridged cast}} expected-note {{use CFBridgingRetain call}} expected-note {{use __bridge}}
 }
 
 void f2(NSString *s) {
@@ -23,7 +26,7 @@ void f2(NSString *s) {
   ref = [(CFStringRef)[s string] retain]; // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef' (aka 'const struct __CFString *') requires a bridged cast}} \
     // expected-error {{bad receiver type 'CFStringRef' (aka 'const struct __CFString *')}} \
     // expected-note{{use __bridge to convert directly (no change in ownership)}} \
-    // expected-note{{use CFBridgeRetain call to make an ARC object available as a +1 'CFStringRef' (aka 'const struct __CFString *')}}
+    // expected-note{{use CFBridgingRetain call to make an ARC object available as a +1 'CFStringRef' (aka 'const struct __CFString *')}}
 }
 
 CFStringRef f3() {
index 84ccf05e09563ddbbfdaa86c3a40cbc194bb652b..56efe81d608b0d1a84f96157d456343d4c7e2487 100644 (file)
@@ -1,6 +1,8 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -fblocks -verify %s
 
 typedef const void *CFTypeRef;
+CFTypeRef CFBridgingRetain(id X);
+id CFBridgingRelease(CFTypeRef);
 typedef const struct __CFString *CFStringRef;
 
 @interface NSString
@@ -35,8 +37,8 @@ void to_cf(id obj) {
 void fixits() {
   id obj1 = (id)CFCreateSomething(); // expected-error{{cast of C pointer type 'CFTypeRef' (aka 'const void *') to Objective-C pointer type 'id' requires a bridged cast}} \
   // expected-note{{use __bridge to convert directly (no change in ownership)}} \
-  // expected-note{{use CFBridgeRelease call to transfer ownership of a +1 'CFTypeRef' (aka 'const void *') into ARC}}
+  // expected-note{{use CFBridgingRelease call to transfer ownership of a +1 'CFTypeRef' (aka 'const void *') into ARC}}
   CFTypeRef cf1 = (CFTypeRef)CreateSomething(); // expected-error{{cast of Objective-C pointer type 'id' to C pointer type 'CFTypeRef' (aka 'const void *') requires a bridged cast}} \
   // expected-note{{use __bridge to convert directly (no change in ownership)}} \
-  // expected-note{{use CFBridgeRetain call to make an ARC object available as a +1 'CFTypeRef' (aka 'const void *')}}
+  // expected-note{{use CFBridgingRetain call to make an ARC object available as a +1 'CFTypeRef' (aka 'const void *')}}
 }
index 20c00344131359ffc282761166dab993b5b67ac9..69662ea6107832889e1b2c0e7e9eeee2f7b89cf7 100644 (file)
@@ -5,14 +5,16 @@ char _global[-1]; // expected-error {{declared as an array with a negative size}
 #endif
 
 typedef const void *CFTypeRef;
+CFTypeRef CFBridgingRetain(id X);
+id CFBridgingRelease(CFTypeRef);
 typedef const struct __CFString *CFStringRef;
 
 extern CFStringRef CFMakeString0(void);
 extern CFStringRef CFCreateString0(void);
 void test0() {
   id x;
-  x = (id) CFMakeString0(); // expected-error {{requires a bridged cast}} expected-note {{__bridge to convert directly}} expected-note {{CFBridgeRelease call to transfer}}
-  x = (id) CFCreateString0(); // expected-error {{requires a bridged cast}} expected-note {{__bridge to convert directly}} expected-note {{CFBridgeRelease call to transfer}}
+  x = (id) CFMakeString0(); // expected-error {{requires a bridged cast}} expected-note {{__bridge to convert directly}} expected-note {{CFBridgingRelease call to transfer}}
+  x = (id) CFCreateString0(); // expected-error {{requires a bridged cast}} expected-note {{__bridge to convert directly}} expected-note {{CFBridgingRelease call to transfer}}
 }
 
 extern CFStringRef CFMakeString1(void) __attribute__((cf_returns_not_retained));
@@ -20,7 +22,7 @@ extern CFStringRef CFCreateString1(void) __attribute__((cf_returns_retained));
 void test1() {
   id x;
   x = (id) CFMakeString1();
-  x = (id) CFCreateString1(); // expected-error {{requires a bridged cast}} expected-note {{__bridge to convert directly}} expected-note {{CFBridgeRelease call to transfer}}
+  x = (id) CFCreateString1(); // expected-error {{requires a bridged cast}} expected-note {{__bridge to convert directly}} expected-note {{CFBridgingRelease call to transfer}}
 }
 
 #define CF_AUDIT_BEGIN _Pragma("clang arc_cf_code_audited begin")
@@ -38,6 +40,6 @@ void test2() {
   id x;
   x = (id) CFMakeString2();
   x = (id) CFCreateString2();
-  x = (id) CFMakeString3(); // expected-error {{requires a bridged cast}} expected-note {{__bridge to convert directly}} expected-note {{CFBridgeRelease call to transfer}}
-  x = (id) CFCreateString3(); // expected-error {{requires a bridged cast}} expected-note {{__bridge to convert directly}} expected-note {{CFBridgeRelease call to transfer}}
+  x = (id) CFMakeString3(); // expected-error {{requires a bridged cast}} expected-note {{__bridge to convert directly}} expected-note {{CFBridgingRelease call to transfer}}
+  x = (id) CFCreateString3(); // expected-error {{requires a bridged cast}} expected-note {{__bridge to convert directly}} expected-note {{CFBridgingRelease call to transfer}}
 }
index 943ccea1fa973857ab9c0f2e8e74416412beb1bd..8d8ff984fe9a48460ec842b7d14818122ad18e6c 100644 (file)
@@ -1,5 +1,9 @@
 // RUN: %clang_cc1 -fsyntax-only -fobjc-arc -fobjc-runtime-has-weak -verify -fblocks %s
 
+typedef const void * CFTypeRef;
+CFTypeRef CFBridgingRetain(id X);
+id CFBridgingRelease(CFTypeRef);
+
 void * cvt(id arg)
 {
   void* voidp_val;
@@ -14,13 +18,13 @@ void * cvt(id arg)
   cvt((void*)arg); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'void *' requires a bridged cast}} \
                    // expected-error {{implicit conversion of C pointer type 'void *' to Objective-C pointer type 'id' requires a bridged cast}} \
                    // expected-note 2 {{use __bridge to convert directly (no change in ownership)}} \
-                   // expected-note {{use CFBridgeRetain call to make an ARC object available as a +1 'void *'}} \
-                   // expected-note {{use CFBridgeRelease call to transfer ownership of a +1 'void *' into ARC}}
+                   // expected-note {{use CFBridgingRetain call to make an ARC object available as a +1 'void *'}} \
+                   // expected-note {{use CFBridgingRelease call to transfer ownership of a +1 'void *' into ARC}}
   cvt(0);
   (void)(__strong id**)(0);
   return arg; // expected-error {{implicit conversion of Objective-C pointer type 'id' to C pointer type 'void *' requires a bridged cast}} \
                    // expected-note {{use __bridge to convert directly (no change in ownership)}} \
-                   // expected-note {{use CFBridgeRetain call to make an ARC object available as a +1 'void *'}}
+                   // expected-note {{use CFBridgingRetain call to make an ARC object available as a +1 'void *'}}
 }
 
 void to_void(__strong id *sip, __weak id *wip,
index 1b8f4f9b52ddb2af0e5c2d33bb59777165bfd702..7d5a6b007b386e0c5466f8adde9b8df844735ee7 100644 (file)
@@ -1,6 +1,10 @@
 // // RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -verify %s
 
 typedef const struct __CFString * CFStringRef;
+typedef const void * CFTypeRef;
+CFTypeRef CFBridgingRetain(id X);
+id CFBridgingRelease(CFTypeRef);
+
 
 @interface Object
 @property CFStringRef property;
@@ -35,15 +39,15 @@ void test1(int cond) {
   x = (id) (cond ? (void*) 0 : auditedString());
   x = (id) (cond ? (CFStringRef) @"help" : auditedString());
 
-  x = (id) unauditedString(); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgeRelease call to}}
-  x = (id) (cond ? unauditedString() : (void*) 0); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgeRelease call to}}
-  x = (id) (cond ? (void*) 0 : unauditedString()); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgeRelease call to}}
-  x = (id) (cond ? (CFStringRef) @"help" : unauditedString()); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgeRelease call to}}
+  x = (id) unauditedString(); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}}
+  x = (id) (cond ? unauditedString() : (void*) 0); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}}
+  x = (id) (cond ? (void*) 0 : unauditedString()); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}}
+  x = (id) (cond ? (CFStringRef) @"help" : unauditedString()); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}}
 
-  x = (id) auditedCreateString(); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgeRelease call to}}
-  x = (id) (cond ? auditedCreateString() : (void*) 0); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgeRelease call to}}
-  x = (id) (cond ? (void*) 0 : auditedCreateString()); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgeRelease call to}}
-  x = (id) (cond ? (CFStringRef) @"help" : auditedCreateString()); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgeRelease call to}}
+  x = (id) auditedCreateString(); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}}
+  x = (id) (cond ? auditedCreateString() : (void*) 0); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}}
+  x = (id) (cond ? (void*) 0 : auditedCreateString()); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}}
+  x = (id) (cond ? (CFStringRef) @"help" : auditedCreateString()); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}}
 
   x = (id) [object property];
   x = (id) (cond ? [object property] : (void*) 0);
@@ -80,7 +84,7 @@ void test1(int cond) {
 void testCFTaker(CFTaker *taker, id string) {
   [taker takeOrdinary: (CFStringRef) string];
   [taker takeVariadic: 1, (CFStringRef) string];
-  [taker takeConsumed: (CFStringRef) string]; // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgeRetain call to}}
+  [taker takeConsumed: (CFStringRef) string]; // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}}
 }
 
 void takeCFOrdinaryUnaudited(CFStringRef arg);
@@ -93,27 +97,27 @@ void takeCFConsumedAudited(CFStringRef __attribute__((cf_consumed)) arg);
 #pragma clang arc_cf_code_audited end
 
 void testTakerFunctions(id string) {
-  takeCFOrdinaryUnaudited((CFStringRef) string); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgeRetain call to}}
-  takeCFVariadicUnaudited(1, (CFStringRef) string); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgeRetain call to}}
-  takeCFConsumedUnaudited((CFStringRef) string); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgeRetain call to}}
+  takeCFOrdinaryUnaudited((CFStringRef) string); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}}
+  takeCFVariadicUnaudited(1, (CFStringRef) string); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}}
+  takeCFConsumedUnaudited((CFStringRef) string); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}}
 
   void (*taker)(CFStringRef) = 0;
-  taker((CFStringRef) string); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgeRetain call to}}
+  taker((CFStringRef) string); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}}
 
   takeCFOrdinaryAudited((CFStringRef) string);
   takeCFVariadicAudited(1, (CFStringRef) string);
-  takeCFConsumedAudited((CFStringRef) string); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgeRetain call to}}
+  takeCFConsumedAudited((CFStringRef) string); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}}
 }
 
 void testTakerFunctions_parens(id string) {
-  takeCFOrdinaryUnaudited(((CFStringRef) string)); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgeRetain call to}}
-  takeCFVariadicUnaudited(1, ((CFStringRef) string)); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgeRetain call to}}
-  takeCFConsumedUnaudited(((CFStringRef) string)); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgeRetain call to}}
+  takeCFOrdinaryUnaudited(((CFStringRef) string)); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}}
+  takeCFVariadicUnaudited(1, ((CFStringRef) string)); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}}
+  takeCFConsumedUnaudited(((CFStringRef) string)); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}}
 
   void (*taker)(CFStringRef) = 0;
-  taker(((CFStringRef) string)); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgeRetain call to}}
+  taker(((CFStringRef) string)); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}}
 
   takeCFOrdinaryAudited(((CFStringRef) string));
   takeCFVariadicAudited(1, ((CFStringRef) string));
-  takeCFConsumedAudited(((CFStringRef) string)); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgeRetain call to}}
+  takeCFConsumedAudited(((CFStringRef) string)); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}}
 }
index a6248eb4a578ef5473425ebac866b8ee8ee35891..7a9655037ebffc370a05d3a956756ef23105cb9f 100644 (file)
@@ -1,6 +1,9 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -fblocks -verify %s
 
 typedef unsigned long NSUInteger;
+typedef const void * CFTypeRef;
+CFTypeRef CFBridgingRetain(id X);
+id CFBridgingRelease(CFTypeRef);
 
 void test0(void (*fn)(int), int val) {
   fn(val);
@@ -263,8 +266,8 @@ void test11(id op, void *vp) {
   b = (vp == nil);
   b = (nil == vp);
 
-  b = (vp == op); // expected-error {{implicit conversion of Objective-C pointer type 'id' to C pointer type 'void *' requires a bridged cast}} expected-note {{use __bridge}} expected-note {{use CFBridgeRetain call}}
-  b = (op == vp); // expected-error {{implicit conversion of C pointer type 'void *' to Objective-C pointer type 'id' requires a bridged cast}} expected-note {{use __bridge}} expected-note {{use CFBridgeRelease call}}
+  b = (vp == op); // expected-error {{implicit conversion of Objective-C pointer type 'id' to C pointer type 'void *' requires a bridged cast}} expected-note {{use __bridge}} expected-note {{use CFBridgingRetain call}}
+  b = (op == vp); // expected-error {{implicit conversion of C pointer type 'void *' to Objective-C pointer type 'id' requires a bridged cast}} expected-note {{use __bridge}} expected-note {{use CFBridgingRelease call}}
 }
 
 void test12(id collection) {
@@ -404,10 +407,10 @@ void test19(void) {
   id x;
   x = (id) test19a; // expected-error {{bridged cast}} \
   // expected-note{{use __bridge to convert directly (no change in ownership)}} \
-  // expected-note{{use CFBridgeRelease call to transfer ownership of a +1 'struct Test19 *' into ARC}}
+  // expected-note{{use CFBridgingRelease call to transfer ownership of a +1 'struct Test19 *' into ARC}}
   x = (id) test19b; // expected-error {{bridged cast}} \
   // expected-note{{use __bridge to convert directly (no change in ownership)}} \
-  // expected-note{{use CFBridgeRelease call to transfer ownership of a +1 'struct Test19 *' into ARC}}
+  // expected-note{{use CFBridgingRelease call to transfer ownership of a +1 'struct Test19 *' into ARC}}
 }
 
 // rdar://problem/8951453
index 6a943cf15ad73acfe384c6879db05bf0ad2fd6fd..0b3ba07eef3e48d0ec838f658fdf1537d7756aeb 100644 (file)
@@ -1,6 +1,10 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -verify %s
 
 typedef const struct __CFString * CFStringRef;
+typedef const void * CFTypeRef;
+extern "C" CFTypeRef CFBridgingRetain(id X);
+extern "C" id CFBridgingRelease(CFTypeRef);
+
 
 @interface Object
 @property CFStringRef property;
@@ -35,15 +39,15 @@ void test1(int cond) {
   x = (id) (cond ? (void*) 0 : auditedString());
   x = (id) (cond ? (CFStringRef) @"help" : auditedString());
 
-  x = (id) unauditedString(); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgeRelease call to}}
-  x = (id) (cond ? unauditedString() : (void*) 0); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgeRelease call to}}
-  x = (id) (cond ? (void*) 0 : unauditedString()); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgeRelease call to}}
-  x = (id) (cond ? (CFStringRef) @"help" : unauditedString()); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgeRelease call to}}
+  x = (id) unauditedString(); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}}
+  x = (id) (cond ? unauditedString() : (void*) 0); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}}
+  x = (id) (cond ? (void*) 0 : unauditedString()); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}}
+  x = (id) (cond ? (CFStringRef) @"help" : unauditedString()); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}}
 
-  x = (id) auditedCreateString(); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgeRelease call to}}
-  x = (id) (cond ? auditedCreateString() : (void*) 0); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgeRelease call to}}
-  x = (id) (cond ? (void*) 0 : auditedCreateString()); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgeRelease call to}}
-  x = (id) (cond ? (CFStringRef) @"help" : auditedCreateString()); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgeRelease call to}}
+  x = (id) auditedCreateString(); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}}
+  x = (id) (cond ? auditedCreateString() : (void*) 0); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}}
+  x = (id) (cond ? (void*) 0 : auditedCreateString()); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}}
+  x = (id) (cond ? (CFStringRef) @"help" : auditedCreateString()); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}}
 
   x = (id) [object property];
   x = (id) (cond ? [object property] : (void*) 0);
@@ -80,7 +84,7 @@ void test1(int cond) {
 void testCFTaker(CFTaker *taker, id string) {
   [taker takeOrdinary: (CFStringRef) string];
   [taker takeVariadic: 1, (CFStringRef) string];
-  [taker takeConsumed: (CFStringRef) string]; // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgeRetain call to}}
+  [taker takeConsumed: (CFStringRef) string]; // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}}
 }
 
 void takeCFOrdinaryUnaudited(CFStringRef arg);
@@ -93,14 +97,14 @@ void takeCFConsumedAudited(CFStringRef __attribute__((cf_consumed)) arg);
 #pragma clang arc_cf_code_audited end
 
 void testTakerFunctions(id string) {
-  takeCFOrdinaryUnaudited((CFStringRef) string); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgeRetain call to}}
-  takeCFVariadicUnaudited(1, (CFStringRef) string); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgeRetain call to}}
-  takeCFConsumedUnaudited((CFStringRef) string); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgeRetain call to}}
+  takeCFOrdinaryUnaudited((CFStringRef) string); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}}
+  takeCFVariadicUnaudited(1, (CFStringRef) string); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}}
+  takeCFConsumedUnaudited((CFStringRef) string); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}}
 
   void (*taker)(CFStringRef) = 0;
-  taker((CFStringRef) string); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgeRetain call to}}
+  taker((CFStringRef) string); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}}
 
   takeCFOrdinaryAudited((CFStringRef) string);
   takeCFVariadicAudited(1, (CFStringRef) string);
-  takeCFConsumedAudited((CFStringRef) string); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgeRetain call to}}
+  takeCFConsumedAudited((CFStringRef) string); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}}
 }