From: Fariborz Jahanian Date: Wed, 20 Nov 2013 22:55:41 +0000 (+0000) Subject: ObjectiveC ARC. warn in presense of __bridge casting to X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bed7bb87d5e9bbd3eae6f0610078c46311d2e67d;p=clang ObjectiveC ARC. warn in presense of __bridge casting to or from a toll free bridge cast. // rdar://15454846 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@195278 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index 6a0c09a4db..65f584f657 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -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, diff --git a/test/SemaObjC/objcbridge-attribute.m b/test/SemaObjC/objcbridge-attribute.m index 24b7289f8d..67e09e5fb1 100644 --- a/test/SemaObjC/objcbridge-attribute.m +++ b/test/SemaObjC/objcbridge-attribute.m @@ -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 @end // expected-note 5 {{declared here}} +@interface NSError @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)cf; // expected-warning {{'CFMyPersonalErrorRef' (aka 'struct __CFMyPersonalErrorRef *') bridges to MyPersonalError, not 'id'}} } +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 *')}} +}