Objective-C ARC. Under ARC, addition of 'bridge' attribute
on CF type is not sufficient and bridge casting is still required for proper ownership semantics. // rdar://16650445 llvm-svn: 206910
This commit is contained in:
parent
749323fadb
commit
953d18a988
|
@ -2551,6 +2551,8 @@ def warn_objc_invalid_bridge : Warning<
|
|||
"%0 bridges to %1, not %2">, InGroup<ObjCBridge>;
|
||||
def warn_objc_invalid_bridge_to_cf : Warning<
|
||||
"%0 cannot bridge to %1">, InGroup<ObjCBridge>;
|
||||
def err_objc_invalid_bridge : Error<
|
||||
"under ARC %0 bridges to %1, but it still requires an explicit bridge cast">;
|
||||
|
||||
// objc_bridge_related attribute diagnostics.
|
||||
def err_objc_bridged_related_invalid_class : Error<
|
||||
|
|
|
@ -3289,7 +3289,8 @@ diagnoseObjCARCConversion(Sema &S, SourceRange castRange,
|
|||
}
|
||||
|
||||
template <typename TB>
|
||||
static bool CheckObjCBridgeNSCast(Sema &S, QualType castType, Expr *castExpr) {
|
||||
static bool CheckObjCBridgeNSCast(Sema &S, QualType castType, Expr *castExpr,
|
||||
bool TollFreeBridgeCast) {
|
||||
QualType T = castExpr->getType();
|
||||
while (const TypedefType *TD = dyn_cast<TypedefType>(T.getTypePtr())) {
|
||||
TypedefNameDecl *TDNDecl = TD->getDecl();
|
||||
|
@ -3308,8 +3309,15 @@ static bool CheckObjCBridgeNSCast(Sema &S, QualType castType, Expr *castExpr) {
|
|||
ObjCInterfaceDecl *CastClass
|
||||
= InterfacePointerType->getObjectType()->getInterface();
|
||||
if ((CastClass == ExprClass) ||
|
||||
(CastClass && ExprClass->isSuperClassOf(CastClass)))
|
||||
(CastClass && ExprClass->isSuperClassOf(CastClass))) {
|
||||
if (!TollFreeBridgeCast && S.getLangOpts().ObjCAutoRefCount) {
|
||||
// bridge attribute is ok. However, under ARC, cast still requires
|
||||
// an explicit cast and should not compile under ARC.
|
||||
S.Diag(castExpr->getLocStart(), diag::err_objc_invalid_bridge)
|
||||
<< T << Target->getName();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
S.Diag(castExpr->getLocStart(), diag::warn_objc_invalid_bridge)
|
||||
<< T << Target->getName() << castType->getPointeeType();
|
||||
return true;
|
||||
|
@ -3402,8 +3410,8 @@ void Sema::CheckTollFreeBridgeCast(QualType castType, Expr *castExpr) {
|
|||
ARCConversionTypeClass exprACTC = classifyTypeForARCConversion(castExpr->getType());
|
||||
ARCConversionTypeClass castACTC = classifyTypeForARCConversion(castType);
|
||||
if (castACTC == ACTC_retainable && exprACTC == ACTC_coreFoundation) {
|
||||
(void)CheckObjCBridgeNSCast<ObjCBridgeAttr>(*this, castType, castExpr);
|
||||
(void)CheckObjCBridgeNSCast<ObjCBridgeMutableAttr>(*this, castType, castExpr);
|
||||
(void)CheckObjCBridgeNSCast<ObjCBridgeAttr>(*this, castType, castExpr, true);
|
||||
(void)CheckObjCBridgeNSCast<ObjCBridgeMutableAttr>(*this, castType, castExpr, true);
|
||||
}
|
||||
else if (castACTC == ACTC_coreFoundation && exprACTC == ACTC_retainable) {
|
||||
(void)CheckObjCBridgeCFCast<ObjCBridgeAttr>(*this, castType, castExpr);
|
||||
|
@ -3624,8 +3632,8 @@ Sema::CheckObjCARCConversion(SourceRange castRange, QualType castType,
|
|||
|
||||
if (castACTC == ACTC_retainable && exprACTC == ACTC_coreFoundation &&
|
||||
(CCK == CCK_CStyleCast || CCK == CCK_FunctionalCast))
|
||||
if (CheckObjCBridgeNSCast<ObjCBridgeAttr>(*this, castType, castExpr) ||
|
||||
CheckObjCBridgeNSCast<ObjCBridgeMutableAttr>(*this, castType, castExpr))
|
||||
if (CheckObjCBridgeNSCast<ObjCBridgeAttr>(*this, castType, castExpr, false) ||
|
||||
CheckObjCBridgeNSCast<ObjCBridgeMutableAttr>(*this, castType, castExpr, false))
|
||||
return ACR_okay;
|
||||
|
||||
if (castACTC == ACTC_coreFoundation && exprACTC == ACTC_retainable &&
|
||||
|
|
|
@ -64,9 +64,9 @@ typedef CFErrorRef1 CFErrorRef2; // expected-note 2 {{declared here}}
|
|||
|
||||
void Test2(CFErrorRef2 cf, NSError *ns, NSString *str, Class c, CFUColor2Ref cf2) {
|
||||
(void)(NSString *)cf; // expected-warning {{'CFErrorRef2' (aka 'struct __CFErrorRef *') bridges to NSError, not 'NSString'}}
|
||||
(void)(NSError *)cf; // okay
|
||||
(void)(MyError*)cf; // okay,
|
||||
(void)(NSUColor *)cf2; // okay
|
||||
(void)(NSError *)cf; // expected-error {{under ARC 'CFErrorRef2' (aka 'struct __CFErrorRef *') bridges to NSError, but it still requires an explicit bridge cast}}
|
||||
(void)(MyError*)cf; // expected-error {{under ARC 'CFErrorRef2' (aka 'struct __CFErrorRef *') bridges to NSError, but it still requires an explicit bridge cast}}
|
||||
(void)(NSUColor *)cf2; // expected-error {{under ARC 'CFUColor2Ref' (aka 'union __CFUPrimeColor *') bridges to NSUColor, but it still requires an explicit bridge cast}}
|
||||
(void)(CFErrorRef)ns; // okay
|
||||
(void)(CFErrorRef)str; // expected-warning {{'NSString' cannot bridge to 'CFErrorRef' (aka 'struct __CFErrorRef *')}}
|
||||
(void)(Class)cf; // expected-warning {{'CFErrorRef2' (aka 'struct __CFErrorRef *') bridges to NSError, not 'Class'}}
|
||||
|
|
|
@ -64,9 +64,9 @@ typedef CFErrorRef1 CFErrorRef2; // expected-note 2 {{declared here}}
|
|||
|
||||
void Test2(CFErrorRef2 cf, NSError *ns, NSString *str, Class c, CFUColor2Ref cf2) {
|
||||
(void)(NSString *)cf; // expected-warning {{'CFErrorRef2' (aka '__CFErrorRef *') bridges to NSError, not 'NSString'}}
|
||||
(void)(NSError *)cf; // okay
|
||||
(void)(MyError*)cf; // okay,
|
||||
(void)(NSUColor *)cf2; // okay
|
||||
(void)(NSError *)cf; // expected-error {{under ARC 'CFErrorRef2' (aka '__CFErrorRef *') bridges to NSError, but it still requires an explicit bridge cast}}
|
||||
(void)(MyError*)cf; // expected-error {{under ARC 'CFErrorRef2' (aka '__CFErrorRef *') bridges to NSError, but it still requires an explicit bridge cast}},
|
||||
(void)(NSUColor *)cf2; // expected-error {{under ARC 'CFUColor2Ref' (aka '__CFUPrimeColor *') bridges to NSUColor, but it still requires an explicit bridge cast}}
|
||||
(void)(CFErrorRef)ns; // okay
|
||||
(void)(CFErrorRef)str; // expected-warning {{'NSString' cannot bridge to 'CFErrorRef' (aka '__CFErrorRef *')}}
|
||||
(void)(Class)cf; // expected-warning {{'CFErrorRef2' (aka '__CFErrorRef *') bridges to NSError, not 'Class'}}
|
||||
|
|
Loading…
Reference in New Issue