]> granicus.if.org Git - clang/commitdiff
[arcmt] When handling unbridged casts, handle the body of BlockDecl separately becaus...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 9 Aug 2013 20:20:25 +0000 (20:20 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 9 Aug 2013 20:20:25 +0000 (20:20 +0000)
Stmt parent nodes inside a BlockDecl.

Fixes rdar://14686900

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188101 91177308-0d34-0410-b5e6-96231b3b80d8

lib/ARCMigrate/TransUnbridgedCasts.cpp
test/ARCMT/checking.m

index a5752f815736f69f1ed166f7e287b1bb393515a0..7b360c640cfda3e3f3e16573ab8736aef8e69029 100644 (file)
@@ -77,6 +77,13 @@ public:
     TraverseStmt(body);
   }
 
+  bool TraverseBlockDecl(BlockDecl *D) {
+    // ParentMap does not enter into a BlockDecl to record its stmts, so use a
+    // new UnbridgedCastRewriter to handle the block.
+    UnbridgedCastRewriter(Pass).transformBody(D->getBody(), D);
+    return true;
+  }
+
   bool VisitCastExpr(CastExpr *E) {
     if (E->getCastKind() != CK_CPointerToObjCPointerCast &&
         E->getCastKind() != CK_BitCast &&
index b06f4a731dc781f9c4a299f98c27d515adc48b01..a550633171d1e52fafa4ba6b929e94aae04209ce 100644 (file)
@@ -333,7 +333,9 @@ void rdar9504750(id p) {
 }
 @end
 
-@interface Test10 : NSObject
+@interface Test10 : NSObject {
+  CFStringRef cfstr;
+}
 @property (retain) id prop;
 -(void)foo;
 @end
@@ -342,3 +344,13 @@ void test(Test10 *x) {
   x.prop = ^{ [x foo]; }; // expected-warning {{likely to lead to a retain cycle}} \
                           // expected-note {{retained by the captured object}}
 }
+
+@implementation Test10
+-(void)foo {
+  ^{
+    NSString *str = (NSString *)cfstr; // expected-error {{cast of C pointer type 'CFStringRef' (aka 'const struct __CFString *') to Objective-C pointer type 'NSString *' requires a bridged cast}} \
+    // expected-note {{use __bridge to convert directly (no change in ownership)}} \
+    // expected-note {{use CFBridgingRelease call to transfer ownership of a +1 'CFStringRef' (aka 'const struct __CFString *') into ARC}}
+  };
+}
+@end