]> granicus.if.org Git - clang/commitdiff
[arcmt] Don't add __weak if there is already a GC __weak and make sure to clear
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 28 Nov 2011 00:23:12 +0000 (00:23 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 28 Nov 2011 00:23:12 +0000 (00:23 +0000)
__weak from a readonly property.

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

lib/ARCMigrate/TransGCAttrs.cpp
lib/ARCMigrate/TransProperties.cpp
test/ARCMT/GC.m
test/ARCMT/GC.m.result

index dc223750483d43340da010726ed448d7a4c3535f..607e5a0f3d9983e2edb36a4bf1a396ba073afe52 100644 (file)
@@ -326,7 +326,8 @@ static void checkAllProps(MigrationContext &MigrateCtx,
   for (unsigned i = 0, e = AllProps.size(); i != e; ++i) {
     ObjCPropertyDecl *PD = AllProps[i];
     if (PD->getPropertyAttributesAsWritten() &
-          ObjCPropertyDecl::OBJC_PR_assign) {
+          (ObjCPropertyDecl::OBJC_PR_assign |
+           ObjCPropertyDecl::OBJC_PR_readonly)) {
       SourceLocation AtLoc = PD->getAtLoc();
       if (AtLoc.isInvalid())
         continue;
index 0686dd3c2e34e01308cb4bac9848ff07a4b12478..8136b31d81246210877b3c1379303702ef12c200 100644 (file)
@@ -237,9 +237,12 @@ private:
       canUseWeak = false;
 
     for (PropsTy::iterator I = props.begin(), E = props.end(); I != E; ++I) {
-      if (isUserDeclared(I->IvarD))
-        Pass.TA.insert(I->IvarD->getLocation(),
-                       canUseWeak ? "__weak " : "__unsafe_unretained ");
+      if (isUserDeclared(I->IvarD)) {
+        if (I->IvarD &&
+            I->IvarD->getType().getObjCLifetime() != Qualifiers::OCL_Weak)
+          Pass.TA.insert(I->IvarD->getLocation(),
+                         canUseWeak ? "__weak " : "__unsafe_unretained ");
+      }
       if (I->ImplD)
         Pass.TA.clearDiagnostic(diag::err_arc_assign_property_ownership,
                                 I->ImplD->getLocation());
@@ -257,9 +260,12 @@ private:
       canUseWeak = false;
 
     for (PropsTy::iterator I = props.begin(), E = props.end(); I != E; ++I) {
-      if (isUserDeclared(I->IvarD))
-        Pass.TA.insert(I->IvarD->getLocation(),
-                       canUseWeak ? "__weak " : "__unsafe_unretained ");
+      if (isUserDeclared(I->IvarD)) {
+        if (I->IvarD &&
+            I->IvarD->getType().getObjCLifetime() != Qualifiers::OCL_Weak)
+          Pass.TA.insert(I->IvarD->getLocation(),
+                         canUseWeak ? "__weak " : "__unsafe_unretained ");
+      }
       if (I->ImplD) {
         Pass.TA.clearDiagnostic(diag::err_arc_assign_property_ownership,
                                 I->ImplD->getLocation());
index 35e9bcf9ce18ae63015fd5e8b92acb26a46d2217..86e8b9b9630a651ba78965651017c56db8325c47 100644 (file)
@@ -58,6 +58,8 @@ __attribute__((objc_arc_weak_reference_unavailable))
 @interface I4Impl {
   I4Impl *pds2;
   I4Impl *pds3;
+  __weak I4Impl *pw3;
+  __weak I4Impl *pw4;
 }
 @property (assign) I4Impl *__weak pw1, *__weak pw2;
 @property (assign) I4Impl *__strong ps;
@@ -65,10 +67,12 @@ __attribute__((objc_arc_weak_reference_unavailable))
 @property (assign) I4Impl * pds2;
 @property (readwrite) I4Impl * pds3;
 @property (readonly) I4Impl * pds4;
+@property (readonly) __weak I4Impl *pw3;
+@property (assign) __weak I4Impl *pw4;
 @end
 
 @implementation I4Impl
-@synthesize pw1, pw2, ps, pds, pds2, pds3, pds4;
+@synthesize pw1, pw2, pw3, pw4, ps, pds, pds2, pds3, pds4;
 
 -(void)test1:(CFTypeRef *)cft {
   id x = NSMakeCollectable(cft);
index 540c2a2932f725670375c853fccfd1f16aba956a..b5222dd27a626aaa7bd8f45bec50e281e9e46168 100644 (file)
@@ -53,6 +53,8 @@ __attribute__((objc_arc_weak_reference_unavailable))
 @interface I4Impl {
   I4Impl *pds2;
   I4Impl *pds3;
+  __weak I4Impl *pw3;
+  __weak I4Impl *pw4;
 }
 @property (weak) I4Impl * pw1, * pw2;
 @property  I4Impl * ps;
@@ -60,10 +62,12 @@ __attribute__((objc_arc_weak_reference_unavailable))
 @property  I4Impl * pds2;
 @property (readwrite) I4Impl * pds3;
 @property (readonly) I4Impl * pds4;
+@property (weak, readonly)  I4Impl *pw3;
+@property (weak)  I4Impl *pw4;
 @end
 
 @implementation I4Impl
-@synthesize pw1, pw2, ps, pds, pds2, pds3, pds4;
+@synthesize pw1, pw2, pw3, pw4, ps, pds, pds2, pds3, pds4;
 
 -(void)test1:(CFTypeRef *)cft {
   id x = CFBridgingRelease(cft);