Awesome! One last comment…this now handles ACC* possibilities ACC_plusOne, ACC_plusZero, and ACC_invalid, but not ACC_bottom, in which it doesn't matter which cast we use. We might as well just use __bridge, since it's not standard convention to CFRelease strings created with CFSTR.
On Jul 27, 2012, at 16:55 , Fariborz Jahanian <[email protected]> wrote: > Author: fjahanian > Date: Fri Jul 27 18:55:46 2012 > New Revision: 160902 > > URL: http://llvm.org/viewvc/llvm-project?rev=160902&view=rev > Log: > objc-arc: change per Jordy's comments. > // rdar://11923822 > > Modified: > cfe/trunk/lib/Sema/SemaExprObjC.cpp > cfe/trunk/test/SemaObjC/arc-bridged-cast.m > cfe/trunk/test/SemaObjC/arc-cf.m > > Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=160902&r1=160901&r2=160902&view=diff > ============================================================================== > --- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original) > +++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Fri Jul 27 18:55:46 2012 > @@ -2670,21 +2670,22 @@ > // now we're not going to permit implicit handling of +1 results, > // because it's a bit frightening. > if (fn->hasAttr<CFReturnsRetainedAttr>()) > - return ACC_invalid; // ACC_plusOne if we start accepting this > + return Diagnose ? ACC_plusOne > + : ACC_invalid; // ACC_plusOne if we start accepting > this > > // Recognize this specific builtin function, which is used by CFSTR. > unsigned builtinID = fn->getBuiltinID(); > if (builtinID == Builtin::BI__builtin___CFStringMakeConstantString) > return ACC_bottom; > > + // Otherwise, don't do anything implicit with an unaudited function. > + if (!fn->hasAttr<CFAuditedTransferAttr>()) > + return ACC_invalid; > + > // Otherwise, it's +0 unless it follows the create convention. > if (ento::coreFoundation::followsCreateRule(fn)) > return Diagnose ? ACC_plusOne > : ACC_invalid; // ACC_plusOne if we start accepting > this > - > - // Otherwise, don't do anything implicit with an unaudited function. > - if (!fn->hasAttr<CFAuditedTransferAttr>()) > - return ACC_invalid; > > return ACC_plusZero; > } > @@ -2859,15 +2860,15 @@ > << castRange > << castExpr->getSourceRange(); > bool br = S.isKnownName("CFBridgingRelease"); > - bool fCreateRule = > - ARCCastChecker(S.Context, exprACTC, castACTC, true).Visit(castExpr) > - == ACC_plusOne; > - if (!fCreateRule) > + ACCResult CreateRule = > + ARCCastChecker(S.Context, exprACTC, castACTC, true).Visit(castExpr); > + if (CreateRule != ACC_plusOne) > { > DiagnosticBuilder DiagB = S.Diag(noteLoc, diag::note_arc_bridge); > addFixitForObjCARCConversion(S, DiagB, CCK, afterLParen, > castType, castExpr, "__bridge ", 0); > } > + if (CreateRule != ACC_plusZero) > { > DiagnosticBuilder DiagB = S.Diag(br ? castExpr->getExprLoc() : noteLoc, > diag::note_arc_bridge_transfer) > @@ -2891,15 +2892,15 @@ > << castType > << castRange > << castExpr->getSourceRange(); > - bool fCreateRule = > - ARCCastChecker(S.Context, exprACTC, castACTC, true).Visit(castExpr) > - == ACC_plusOne; > - if (!fCreateRule) > + ACCResult CreateRule = > + ARCCastChecker(S.Context, exprACTC, castACTC, true).Visit(castExpr); > + if (CreateRule != ACC_plusOne) > { > DiagnosticBuilder DiagB = S.Diag(noteLoc, diag::note_arc_bridge); > addFixitForObjCARCConversion(S, DiagB, CCK, afterLParen, > castType, castExpr, "__bridge ", 0); > } > + if (CreateRule != ACC_plusZero) > { > DiagnosticBuilder DiagB = S.Diag(br ? castExpr->getExprLoc() : noteLoc, > diag::note_arc_bridge_retained) > > Modified: cfe/trunk/test/SemaObjC/arc-bridged-cast.m > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/arc-bridged-cast.m?rev=160902&r1=160901&r2=160902&view=diff > ============================================================================== > --- cfe/trunk/test/SemaObjC/arc-bridged-cast.m (original) > +++ cfe/trunk/test/SemaObjC/arc-bridged-cast.m Fri Jul 27 18:55:46 2012 > @@ -38,7 +38,7 @@ > > CFTypeRef 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 CFBridgingRelease call to transfer ownership of a +1 > 'CFTypeRef' (aka 'const void *') into ARC}} > + // expected-note{{use __bridge to convert directly (no change in > ownership)}} expected-note{{use CFBridgingRelease call to transfer ownership > of a +1 'CFTypeRef' (aka 'const void *') into ARC}} > // CHECK: fix-it:"{{.*}}":{40:17-40:17}:"CFBridgingRelease(" > // CHECK: fix-it:"{{.*}}":{40:36-40:36}:")" > > > Modified: cfe/trunk/test/SemaObjC/arc-cf.m > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/arc-cf.m?rev=160902&r1=160901&r2=160902&view=diff > ============================================================================== > --- cfe/trunk/test/SemaObjC/arc-cf.m (original) > +++ cfe/trunk/test/SemaObjC/arc-cf.m Fri Jul 27 18:55:46 2012 > @@ -10,7 +10,9 @@ > typedef const struct __CFString *CFStringRef; > > extern CFStringRef CFMakeString0(void); > +#pragma clang arc_cf_code_audited begin > extern CFStringRef CFCreateString0(void); > +#pragma clang arc_cf_code_audited end > void test0() { > id x; > x = (id) CFMakeString0(); // expected-error {{requires a bridged cast}} > expected-note {{__bridge to convert directly}} expected-note > {{CFBridgingRelease call to transfer}} > @@ -22,7 +24,7 @@ > void test1() { > id x; > x = (id) CFMakeString1(); > - x = (id) CFCreateString1(); // expected-error {{requires a bridged cast}} > expected-note {{__bridge to convert directly}} expected-note > {{CFBridgingRelease call to transfer}} > + x = (id) CFCreateString1(); // expected-error {{requires a bridged cast}} > expected-note {{CFBridgingRelease call to transfer}} > } > > #define CF_AUDIT_BEGIN _Pragma("clang arc_cf_code_audited begin") > @@ -40,6 +42,6 @@ > 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 > {{CFBridgingRelease call to transfer}} > + x = (id) CFMakeString3(); // expected-error {{requires a bridged cast}} > expected-note {{CFBridgingRelease call to transfer}} > x = (id) CFCreateString3(); // expected-error {{requires a bridged cast}} > expected-note {{CFBridgingRelease call to transfer}} > } > > > _______________________________________________ > cfe-commits mailing list > [email protected] > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
