diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-11-06 18:58:17 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-11-06 18:58:17 +0000 |
commit | 17ac3197941b9f135424dfe3900577a04407c5c2 (patch) | |
tree | 2789016e833d6ca1f50a2cd3694be4eb11758a78 | |
parent | dbbdec994f5a96b5c25aaa679cd86ecabf545f7b (diff) |
[arcmt] In GC, clear redundant __strong's.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143886 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/ARCMigrate/TransGCAttrs.cpp | 40 | ||||
-rw-r--r-- | lib/ARCMigrate/Transforms.h | 2 | ||||
-rw-r--r-- | test/ARCMT/GC.h | 5 | ||||
-rw-r--r-- | test/ARCMT/GC.m | 5 | ||||
-rw-r--r-- | test/ARCMT/GC.m.result | 5 |
5 files changed, 47 insertions, 10 deletions
diff --git a/lib/ARCMigrate/TransGCAttrs.cpp b/lib/ARCMigrate/TransGCAttrs.cpp index 60573a44e8..a85cad4d44 100644 --- a/lib/ARCMigrate/TransGCAttrs.cpp +++ b/lib/ARCMigrate/TransGCAttrs.cpp @@ -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 } diff --git a/lib/ARCMigrate/Transforms.h b/lib/ARCMigrate/Transforms.h index 540426b81a..3f1e737e23 100644 --- a/lib/ARCMigrate/Transforms.h +++ b/lib/ARCMigrate/Transforms.h @@ -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 index 0000000000..6202e478c3 --- /dev/null +++ b/test/ARCMT/GC.h @@ -0,0 +1,5 @@ + +@interface ExtInterface { + __strong ExtInterface *myivar; +} +@end diff --git a/test/ARCMT/GC.m b/test/ARCMT/GC.m index cfd22dee09..470ec64ab9 100644 --- a/test/ARCMT/GC.m +++ b/test/ARCMT/GC.m @@ -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 diff --git a/test/ARCMT/GC.m.result b/test/ARCMT/GC.m.result index a492f02970..0be8efdcec 100644 --- a/test/ARCMT/GC.m.result +++ b/test/ARCMT/GC.m.result @@ -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 |