From: Argyrios Kyrtzidis Date: Sun, 6 Nov 2011 18:58:23 +0000 (+0000) Subject: [arcmt] In GC, error for __strong/__weak on non-objc pointers. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=280b4ada965f89607684446e826d830f0b8a7864;p=clang [arcmt] In GC, error for __strong/__weak on non-objc pointers. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143887 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/ARCMigrate/TransGCAttrs.cpp b/lib/ARCMigrate/TransGCAttrs.cpp index a85cad4d44..79dc0538b6 100644 --- a/lib/ARCMigrate/TransGCAttrs.cpp +++ b/lib/ARCMigrate/TransGCAttrs.cpp @@ -186,10 +186,28 @@ static void clearRedundantStrongs(MigrationContext &MigrateCtx) { } } +static void errorForGCAttrsOnNonObjC(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.FullyMigratable && Attr.Dcl) { + if (Attr.ModifiedType.isNull()) + continue; + if (!Attr.ModifiedType->isObjCRetainableType()) { + TA.reportError("GC managed memory will become unmanaged in ARC", + Attr.Loc); + } + } + } +} + void GCAttrsTraverser::traverseTU(MigrationContext &MigrateCtx) { GCAttrsCollector(MigrateCtx).TraverseDecl( MigrateCtx.Pass.Ctx.getTranslationUnitDecl()); + clearRedundantStrongs(MigrateCtx); + errorForGCAttrsOnNonObjC(MigrateCtx); } void MigrationContext::dumpGCAttrs() { diff --git a/test/ARCMT/GC-check.m b/test/ARCMT/GC-check.m index f71787ce02..9864354228 100644 --- a/test/ARCMT/GC-check.m +++ b/test/ARCMT/GC-check.m @@ -12,3 +12,8 @@ void test1(CFTypeRef *cft) { // expected-error {{unavailable}} NSAllocateCollectable(100, 0); // expected-error {{call returns pointer to GC managed memory; it will become unmanaged in ARC}} } + +@interface I1 { + __strong void *gcVar; // expected-error {{GC managed memory will become unmanaged in ARC}} +} +@end; diff --git a/test/ARCMT/GC.h b/test/ARCMT/GC.h index 6202e478c3..4301baf272 100644 --- a/test/ARCMT/GC.h +++ b/test/ARCMT/GC.h @@ -1,5 +1,6 @@ @interface ExtInterface { __strong ExtInterface *myivar; + __strong void *gcVar; } @end