]> granicus.if.org Git - clang/commitdiff
[arcmt] In GC, clear redundant __strong's.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sun, 6 Nov 2011 18:58:17 +0000 (18:58 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sun, 6 Nov 2011 18:58:17 +0000 (18:58 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143886 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 60573a44e8a0991f56c3bd10688fac14f9e91d81..a85cad4d44acb877e0c52cf4ed10028c7e0ce814 100644 (file)
@@ -101,7 +101,7 @@ public:
     MigrationContext::GCAttrOccurrence &Attr = MigrateCtx.GCAttrs.back();
 
     Attr.Kind = Kind;
-    Attr.Loc = Loc;
+    Attr.Loc = SM.getImmediateExpansionRange(Loc).first;
     Attr.ModifiedType = TL.getModifiedLoc().getType();
     Attr.Dcl = D;
     Attr.FullyMigratable = FullyMigratable;
@@ -163,18 +163,43 @@ public:
 
 } // anonymous namespace
 
+static void clearRedundantStrongs(MigrationContext &MigrateCtx) {
+  TransformActions &TA = MigrateCtx.Pass.TA;
+
+  for (unsigned i = 0, e = MigrateCtx.GCAttrs.size(); i != e; ++i) {
+    MigrationContext::GCAttrOccurrence &Attr = MigrateCtx.GCAttrs[i];
+    if (Attr.Kind == MigrationContext::GCAttrOccurrence::Strong &&
+        Attr.FullyMigratable && Attr.Dcl) {
+      TypeSourceInfo *TInfo = 0;
+      if (DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(Attr.Dcl))
+        TInfo = DD->getTypeSourceInfo();
+      else if (ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(Attr.Dcl))
+        TInfo = PD->getTypeSourceInfo();
+      if (!TInfo)
+        continue;
+
+      if (TInfo->getType().getObjCLifetime() == Qualifiers::OCL_Strong) {
+        Transaction Trans(TA);
+        TA.remove(Attr.Loc);
+      }
+    }
+  }
+}
+
 void GCAttrsTraverser::traverseTU(MigrationContext &MigrateCtx) {
   GCAttrsCollector(MigrateCtx).TraverseDecl(
                                   MigrateCtx.Pass.Ctx.getTranslationUnitDecl());
-#if 0
+  clearRedundantStrongs(MigrateCtx);
+}
+
+void MigrationContext::dumpGCAttrs() {
   llvm::errs() << "\n################\n";
-  for (unsigned i = 0, e = MigrateCtx.GCAttrs.size(); i != e; ++i) {
-    MigrationContext::GCAttrOccurrence &Attr = MigrateCtx.GCAttrs[i];
+  for (unsigned i = 0, e = GCAttrs.size(); i != e; ++i) {
+    GCAttrOccurrence &Attr = GCAttrs[i];
     llvm::errs() << "KIND: "
-        << (Attr.Kind == MigrationContext::GCAttrOccurrence::Strong ? "strong"
-                                                                    : "weak");
+        << (Attr.Kind == GCAttrOccurrence::Strong ? "strong" : "weak");
     llvm::errs() << "\nLOC: ";
-    Attr.Loc.dump(MigrateCtx.Pass.Ctx.getSourceManager());
+    Attr.Loc.dump(Pass.Ctx.getSourceManager());
     llvm::errs() << "\nTYPE: ";
     Attr.ModifiedType.dump();
     if (Attr.Dcl) {
@@ -187,5 +212,4 @@ void GCAttrsTraverser::traverseTU(MigrationContext &MigrateCtx) {
     llvm::errs() << "\n----------------\n";
   }
   llvm::errs() << "\n################\n";
-#endif
 }
index 540426b81a2b0a98344cdfc5faf51be2e3f0929e..3f1e737e23e0437720cdcfbdc514a12c04070996 100644 (file)
@@ -111,6 +111,8 @@ public:
   bool isGCOwnedNonObjC(QualType T);
 
   void traverse(TranslationUnitDecl *TU);
+
+  void dumpGCAttrs();
 };
 
 class PropertyRewriteTraverser : public ASTTraverser {
diff --git a/test/ARCMT/GC.h b/test/ARCMT/GC.h
new file mode 100644 (file)
index 0000000..6202e47
--- /dev/null
@@ -0,0 +1,5 @@
+
+@interface ExtInterface {
+  __strong ExtInterface *myivar;
+}
+@end
index cfd22dee09d9e7ec9d9fefd357ee01e5930ff39a..470ec64ab9bd1223e8aa758433fda0eaf4b1ed36 100644 (file)
@@ -5,12 +5,15 @@
 // RUN: diff %t %s.result
 
 #include "Common.h"
+#include "GC.h"
 
 void test1(CFTypeRef *cft) {
   id x = NSMakeCollectable(cft);
 }
 
-@interface I1
+@interface I1 {
+  __strong I1 *myivar;
+}
 @end
 
 @implementation I1
index a492f02970b2c75dc6d911b8c69f95b7cf5b2b96..0be8efdcec001e302f2ffde82e265dcd2d355030 100644 (file)
@@ -5,12 +5,15 @@
 // RUN: diff %t %s.result
 
 #include "Common.h"
+#include "GC.h"
 
 void test1(CFTypeRef *cft) {
   id x = CFBridgingRelease(cft);
 }
 
-@interface I1
+@interface I1 {
+   I1 *myivar;
+}
 @end
 
 @implementation I1