From: Fariborz Jahanian Date: Wed, 1 Feb 2012 22:56:20 +0000 (+0000) Subject: Look for declaration of CFBridgingRetain/CFBridgingRetain before X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=52b6236427e7b608eadaac2bf8f5a24dd16a1130;p=clang Look for declaration of CFBridgingRetain/CFBridgingRetain before 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 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 52de6ca26e..ff3b1d6e31 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -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 diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index 483e7eab23..82e8171d66 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -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 diff --git a/test/ARCMT/checking.m b/test/ARCMT/checking.m index c9b4bf13c8..0682fd1dde 100644 --- a/test/ARCMT/checking.m +++ b/test/ARCMT/checking.m @@ -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}} } diff --git a/test/ARCMT/no-canceling-bridge-to-bridge-cast.m b/test/ARCMT/no-canceling-bridge-to-bridge-cast.m index fefa3aea63..81841fbf1e 100644 --- a/test/ARCMT/no-canceling-bridge-to-bridge-cast.m +++ b/test/ARCMT/no-canceling-bridge-to-bridge-cast.m @@ -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))); diff --git a/test/ARCMT/nonobjc-to-objc-cast-2.m b/test/ARCMT/nonobjc-to-objc-cast-2.m index 52d635b531..1ec0089f08 100644 --- a/test/ARCMT/nonobjc-to-objc-cast-2.m +++ b/test/ARCMT/nonobjc-to-objc-cast-2.m @@ -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() { diff --git a/test/SemaObjC/arc-bridged-cast.m b/test/SemaObjC/arc-bridged-cast.m index 84ccf05e09..56efe81d60 100644 --- a/test/SemaObjC/arc-bridged-cast.m +++ b/test/SemaObjC/arc-bridged-cast.m @@ -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 *')}} } diff --git a/test/SemaObjC/arc-cf.m b/test/SemaObjC/arc-cf.m index 20c0034413..69662ea610 100644 --- a/test/SemaObjC/arc-cf.m +++ b/test/SemaObjC/arc-cf.m @@ -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}} } diff --git a/test/SemaObjC/arc-type-conversion.m b/test/SemaObjC/arc-type-conversion.m index 943ccea1fa..8d8ff984fe 100644 --- a/test/SemaObjC/arc-type-conversion.m +++ b/test/SemaObjC/arc-type-conversion.m @@ -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, diff --git a/test/SemaObjC/arc-unbridged-cast.m b/test/SemaObjC/arc-unbridged-cast.m index 1b8f4f9b52..7d5a6b007b 100644 --- a/test/SemaObjC/arc-unbridged-cast.m +++ b/test/SemaObjC/arc-unbridged-cast.m @@ -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}} } diff --git a/test/SemaObjC/arc.m b/test/SemaObjC/arc.m index a6248eb4a5..7a9655037e 100644 --- a/test/SemaObjC/arc.m +++ b/test/SemaObjC/arc.m @@ -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 diff --git a/test/SemaObjCXX/arc-unbridged-cast.mm b/test/SemaObjCXX/arc-unbridged-cast.mm index 6a943cf15a..0b3ba07eef 100644 --- a/test/SemaObjCXX/arc-unbridged-cast.mm +++ b/test/SemaObjCXX/arc-unbridged-cast.mm @@ -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}} }