ObjectiveC ARC. warn in presense of __bridge casting to

or from a toll free bridge cast. // rdar://15454846

llvm-svn: 195278
This commit is contained in:
Fariborz Jahanian 2013-11-20 22:55:41 +00:00
parent b80f94b41c
commit 1f92b7f7c4
2 changed files with 22 additions and 3 deletions

View File

@ -3617,6 +3617,15 @@ ExprResult Sema::ActOnObjCBridgedCast(Scope *S,
Expr *SubExpr) {
TypeSourceInfo *TSInfo = 0;
QualType T = GetTypeFromParser(Type, &TSInfo);
if (Kind == OBC_Bridge) {
// warn in presense of __bridge casting to or from a toll free bridge cast.
ARCConversionTypeClass exprACTC = classifyTypeForARCConversion(SubExpr->getType());
ARCConversionTypeClass castACTC = classifyTypeForARCConversion(T);
if (castACTC == ACTC_retainable && exprACTC == ACTC_coreFoundation)
(void)CheckObjCBridgeNSCast(*this, T, SubExpr);
else if (castACTC == ACTC_coreFoundation && exprACTC == ACTC_retainable)
(void)CheckObjCBridgeCFCast(*this, T, SubExpr);
}
if (!TSInfo)
TSInfo = Context.getTrivialTypeSourceInfo(T, LParenLoc);
return BuildObjCBridgedCast(LParenLoc, Kind, BridgeKeywordLoc, TSInfo,

View File

@ -1,7 +1,7 @@
// RUN: %clang_cc1 -fsyntax-only -fobjc-arc -verify -Wno-objc-root-class %s
// rdar://15454846
typedef struct __attribute__ ((objc_bridge(NSError))) __CFErrorRef * CFErrorRef; // expected-note 5 {{declared here}}
typedef struct __attribute__ ((objc_bridge(NSError))) __CFErrorRef * CFErrorRef; // expected-note 7 {{declared here}}
typedef struct __attribute__ ((objc_bridge(MyError))) __CFMyErrorRef * CFMyErrorRef; // expected-note 3 {{declared here}}
@ -45,7 +45,7 @@ id Test1(CFTestingRef cf) {
typedef CFErrorRef CFErrorRef1;
typedef CFErrorRef1 CFErrorRef2; // expected-note {{declared here}}
typedef CFErrorRef1 CFErrorRef2; // expected-note 2 {{declared here}}
@protocol P1 @end
@protocol P2 @end
@ -53,7 +53,7 @@ typedef CFErrorRef1 CFErrorRef2; // expected-note {{declared here}}
@protocol P4 @end
@protocol P5 @end
@interface NSError<P1, P2, P3> @end // expected-note 5 {{declared here}}
@interface NSError<P1, P2, P3> @end // expected-note 7 {{declared here}}
@interface MyError : NSError // expected-note 3 {{declared here}}
@end
@ -127,3 +127,13 @@ void Test8(CFMyPersonalErrorRef cf) {
(void)(id<P1, P2, P3, P4, P5>)cf; // expected-warning {{'CFMyPersonalErrorRef' (aka 'struct __CFMyPersonalErrorRef *') bridges to MyPersonalError, not 'id<P1,P2,P3,P4,P5>'}}
}
void Test9(CFErrorRef2 cf, NSError *ns, NSString *str, Class c, CFUColor2Ref cf2) {
(void)(__bridge NSString *)cf; // expected-warning {{'CFErrorRef2' (aka 'struct __CFErrorRef *') bridges to NSError, not 'NSString'}}
(void)(__bridge NSError *)cf; // okay
(void)(__bridge MyError*)cf; // okay,
(void)(__bridge NSUColor *)cf2; // okay
(void)(__bridge CFErrorRef)ns; // okay
(void)(__bridge CFErrorRef)str; // expected-warning {{'NSString' cannot bridge to 'CFErrorRef' (aka 'struct __CFErrorRef *')}}
(void)(__bridge Class)cf; // expected-warning {{'CFErrorRef2' (aka 'struct __CFErrorRef *') bridges to NSError, not 'Class'}}
(void)(__bridge CFErrorRef)c; // expected-warning {{'__unsafe_unretained Class' cannot bridge to 'CFErrorRef' (aka 'struct __CFErrorRef *')}}
}