]> granicus.if.org Git - clang/commitdiff
[arcmt] When we already removed a __weak, don't try to change it to __unsafe_unretained
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 8 Nov 2011 02:02:38 +0000 (02:02 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 8 Nov 2011 02:02:38 +0000 (02:02 +0000)
later on, or we will end up with a redundant '__unsafe_unretained'.

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

lib/ARCMigrate/TransGCAttrs.cpp
lib/ARCMigrate/Transforms.h
test/ARCMT/GC-no-arc-runtime.m [new file with mode: 0644]
test/ARCMT/GC-no-arc-runtime.m.result [new file with mode: 0644]

index 8f3926fbbcae1aa559e77484d5bb49a0abf13906..dc223750483d43340da010726ed448d7a4c3535f 100644 (file)
@@ -200,6 +200,7 @@ static void clearRedundantStrongs(MigrationContext &MigrateCtx) {
       if (TInfo->getType().getObjCLifetime() == Qualifiers::OCL_Strong) {
         Transaction Trans(TA);
         TA.remove(Attr.Loc);
+        MigrateCtx.RemovedAttrSet.insert(Attr.Loc.getRawEncoding());
       }
     }
   }
@@ -233,7 +234,8 @@ static void checkWeakGCAttrs(MigrationContext &MigrateCtx) {
       if (!canApplyWeak(MigrateCtx.Pass.Ctx, Attr.ModifiedType,
                         /*AllowOnUnknownClass=*/true)) {
         Transaction Trans(TA);
-        TA.replaceText(Attr.Loc, "__weak", "__unsafe_unretained");
+        if (!MigrateCtx.RemovedAttrSet.count(Attr.Loc.getRawEncoding()))
+          TA.replaceText(Attr.Loc, "__weak", "__unsafe_unretained");
         TA.clearDiagnostic(diag::err_arc_weak_no_runtime,
                            diag::err_arc_unsupported_weak_class,
                            Attr.Loc);
@@ -312,6 +314,7 @@ static void checkAllAtProps(MigrationContext &MigrateCtx,
     TA.clearDiagnostic(diag::err_objc_property_attr_mutually_exclusive, AtLoc);
     TA.clearDiagnostic(diag::err_arc_inconsistent_property_ownership,
                        ATLs[i].second->getLocation());
+    MigrateCtx.RemovedAttrSet.insert(Loc.getRawEncoding());
   }
 }
 
@@ -347,8 +350,8 @@ void GCAttrsTraverser::traverseTU(MigrationContext &MigrateCtx) {
 
   clearRedundantStrongs(MigrateCtx);
   errorForGCAttrsOnNonObjC(MigrateCtx);
-  checkWeakGCAttrs(MigrateCtx);
   checkAllProps(MigrateCtx, AllProps);
+  checkWeakGCAttrs(MigrateCtx);
 }
 
 void MigrationContext::dumpGCAttrs() {
index 49fd0f726dbe821647b29a24bec6ac3026ec431d..8c09a4757c57e2aac6f254861e5f7215e9ad5909 100644 (file)
@@ -95,6 +95,7 @@ public:
   };
   std::vector<GCAttrOccurrence> GCAttrs;
   llvm::DenseSet<unsigned> AttrSet;
+  llvm::DenseSet<unsigned> RemovedAttrSet;
 
   /// \brief Set of raw '@' locations for 'assign' properties group that contain
   /// GC __weak.
diff --git a/test/ARCMT/GC-no-arc-runtime.m b/test/ARCMT/GC-no-arc-runtime.m
new file mode 100644 (file)
index 0000000..2a43f18
--- /dev/null
@@ -0,0 +1,73 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.6 -fsyntax-only -fobjc-runtime-has-weak -fobjc-arc -x objective-c %s.result
+// RUN: arcmt-test --args -triple x86_64-apple-macosx10.6 -fsyntax-only -fobjc-gc-only -x objective-c %s > %t
+// RUN: diff %t %s.result
+// RUN: arcmt-test --args -triple x86_64-apple-macosx10.6 -fsyntax-only -fobjc-gc-only -x objective-c++ %s > %t
+// RUN: diff %t %s.result
+
+#include "Common.h"
+#include "GC.h"
+
+void test1(CFTypeRef *cft) {
+  id x = NSMakeCollectable(cft);
+}
+
+@interface I1 {
+  __strong I1 *myivar;
+}
+@end
+
+@implementation I1
+-(void)dealloc {
+  // dealloc
+  test1(0);
+}
+
+-(void)finalize {
+  // finalize
+  test1(0);
+}
+@end
+
+@interface I2
+@property (retain) id prop;
+@end
+
+@implementation I2
+@synthesize prop;
+
+-(void)finalize {
+  self.prop = 0;
+  // finalize
+  test1(0);
+}
+@end
+
+__attribute__((objc_arc_weak_reference_unavailable))
+@interface QQ {
+  __weak id s;
+  __weak QQ *q;
+}
+@end
+
+@interface I3
+@property (assign) I3 *__weak pw1, *__weak pw2;
+@property (assign) I3 *__strong ps;
+@property (assign) I3 * pds;
+@end
+
+@interface I4Impl {
+  I4Impl *pds2;
+}
+@property (assign) I4Impl *__weak pw1, *__weak pw2;
+@property (assign) I4Impl *__strong ps;
+@property (assign) I4Impl * pds;
+@property (assign) I4Impl * pds2;
+@end
+
+@implementation I4Impl
+@synthesize pw1, pw2, ps, pds, pds2;
+
+-(void)test1:(CFTypeRef *)cft {
+  id x = NSMakeCollectable(cft);
+}
+@end
diff --git a/test/ARCMT/GC-no-arc-runtime.m.result b/test/ARCMT/GC-no-arc-runtime.m.result
new file mode 100644 (file)
index 0000000..567f804
--- /dev/null
@@ -0,0 +1,68 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.6 -fsyntax-only -fobjc-runtime-has-weak -fobjc-arc -x objective-c %s.result
+// RUN: arcmt-test --args -triple x86_64-apple-macosx10.6 -fsyntax-only -fobjc-gc-only -x objective-c %s > %t
+// RUN: diff %t %s.result
+// RUN: arcmt-test --args -triple x86_64-apple-macosx10.6 -fsyntax-only -fobjc-gc-only -x objective-c++ %s > %t
+// RUN: diff %t %s.result
+
+#include "Common.h"
+#include "GC.h"
+
+void test1(CFTypeRef *cft) {
+  id x = CFBridgingRelease(cft);
+}
+
+@interface I1 {
+   I1 *myivar;
+}
+@end
+
+@implementation I1
+-(void)dealloc {
+  // dealloc
+  test1(0);
+}
+
+@end
+
+@interface I2
+@property  id prop;
+@end
+
+@implementation I2
+@synthesize prop;
+
+-(void)dealloc {
+  // finalize
+  test1(0);
+}
+@end
+
+__attribute__((objc_arc_weak_reference_unavailable))
+@interface QQ {
+  __unsafe_unretained id s;
+  __unsafe_unretained QQ *q;
+}
+@end
+
+@interface I3
+@property (unsafe_unretained) I3 * pw1, * pw2;
+@property (strong) I3 * ps;
+@property (assign) I3 * pds;
+@end
+
+@interface I4Impl {
+  I4Impl *pds2;
+}
+@property (unsafe_unretained) I4Impl * pw1, * pw2;
+@property  I4Impl * ps;
+@property  I4Impl * pds;
+@property  I4Impl * pds2;
+@end
+
+@implementation I4Impl
+@synthesize pw1, pw2, ps, pds, pds2;
+
+-(void)test1:(CFTypeRef *)cft {
+  id x = CFBridgingRelease(cft);
+}
+@end