From 7cfd7fe020144afe61ffe4de6c43c10340c415a7 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Tue, 8 Nov 2011 02:02:38 +0000 Subject: [PATCH] [arcmt] When we already removed a __weak, don't try to change it to __unsafe_unretained 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 | 7 ++- lib/ARCMigrate/Transforms.h | 1 + test/ARCMT/GC-no-arc-runtime.m | 73 +++++++++++++++++++++++++++ test/ARCMT/GC-no-arc-runtime.m.result | 68 +++++++++++++++++++++++++ 4 files changed, 147 insertions(+), 2 deletions(-) create mode 100644 test/ARCMT/GC-no-arc-runtime.m create mode 100644 test/ARCMT/GC-no-arc-runtime.m.result diff --git a/lib/ARCMigrate/TransGCAttrs.cpp b/lib/ARCMigrate/TransGCAttrs.cpp index 8f3926fbbc..dc22375048 100644 --- a/lib/ARCMigrate/TransGCAttrs.cpp +++ b/lib/ARCMigrate/TransGCAttrs.cpp @@ -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() { diff --git a/lib/ARCMigrate/Transforms.h b/lib/ARCMigrate/Transforms.h index 49fd0f726d..8c09a4757c 100644 --- a/lib/ARCMigrate/Transforms.h +++ b/lib/ARCMigrate/Transforms.h @@ -95,6 +95,7 @@ public: }; std::vector GCAttrs; llvm::DenseSet AttrSet; + llvm::DenseSet 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 index 0000000000..2a43f18004 --- /dev/null +++ b/test/ARCMT/GC-no-arc-runtime.m @@ -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 index 0000000000..567f804698 --- /dev/null +++ b/test/ARCMT/GC-no-arc-runtime.m.result @@ -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 -- 2.40.0