r195278 - ObjectiveC ARC. warn in presense of __bridge casting to
Fariborz Jahanian
fjahanian at apple.com
Wed Nov 20 14:55:41 PST 2013
Author: fjahanian
Date: Wed Nov 20 16:55:41 2013
New Revision: 195278
URL: http://llvm.org/viewvc/llvm-project?rev=195278&view=rev
Log:
ObjectiveC ARC. warn in presense of __bridge casting to
or from a toll free bridge cast. // rdar://15454846
Modified:
cfe/trunk/lib/Sema/SemaExprObjC.cpp
cfe/trunk/test/SemaObjC/objcbridge-attribute.m
Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=195278&r1=195277&r2=195278&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Wed Nov 20 16:55:41 2013
@@ -3617,6 +3617,15 @@ ExprResult Sema::ActOnObjCBridgedCast(Sc
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,
Modified: cfe/trunk/test/SemaObjC/objcbridge-attribute.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/objcbridge-attribute.m?rev=195278&r1=195277&r2=195278&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/objcbridge-attribute.m (original)
+++ cfe/trunk/test/SemaObjC/objcbridge-attribute.m Wed Nov 20 16:55:41 2013
@@ -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; // expe
@protocol P4 @end
@protocol P5 @end
- at interface NSError<P1, P2, P3> @end // expected-note 5 {{declared here}}
+ at 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 *')}}
+}
More information about the cfe-commits
mailing list