From 2f72ec9fc4d3c127b5c77e13346eb640deae396a Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Sat, 21 Jan 2012 00:43:53 +0000 Subject: [PATCH] arg migrator: change all "assign" of object properties to "strong" when migrating from GC. // rdar://10532449 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148607 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/ARCMigrate/TransProperties.cpp | 20 +++++++++++--------- test/ARCMT/GC-no-arc-runtime.m.result | 8 ++++---- test/ARCMT/GC.m | 11 +++++++++++ test/ARCMT/GC.m.result | 19 +++++++++++++++---- 4 files changed, 41 insertions(+), 17 deletions(-) diff --git a/lib/ARCMigrate/TransProperties.cpp b/lib/ARCMigrate/TransProperties.cpp index b36acbb205..7eb2a9bfc7 100644 --- a/lib/ARCMigrate/TransProperties.cpp +++ b/lib/ARCMigrate/TransProperties.cpp @@ -201,10 +201,8 @@ private: bool HasIvarAssignedAPlusOneObject = hasIvarAssignedAPlusOneObject(props); if (propAttrs & ObjCPropertyDecl::OBJC_PR_assign) { - if (HasIvarAssignedAPlusOneObject || - (Pass.isGCMigration() && !hasGCWeak(props, atLoc))) { + if (HasIvarAssignedAPlusOneObject) return doPropAction(PropAction_AssignRemoved, props, atLoc); - } return doPropAction(PropAction_AssignRewritten, props, atLoc); } @@ -231,19 +229,23 @@ private: void rewriteAssign(PropsTy &props, SourceLocation atLoc) const { bool canUseWeak = canApplyWeak(Pass.Ctx, getPropertyType(props), /*AllowOnUnknownClass=*/Pass.isGCMigration()); + const char *toWhich = + (Pass.isGCMigration() && !hasGCWeak(props, atLoc)) ? "strong" : + (canUseWeak ? "weak" : "unsafe_unretained"); - bool rewroteAttr = rewriteAttribute("assign", - canUseWeak ? "weak" : "unsafe_unretained", - atLoc); + bool rewroteAttr = rewriteAttribute("assign", toWhich, atLoc); if (!rewroteAttr) canUseWeak = false; for (PropsTy::iterator I = props.begin(), E = props.end(); I != E; ++I) { if (isUserDeclared(I->IvarD)) { if (I->IvarD && - I->IvarD->getType().getObjCLifetime() != Qualifiers::OCL_Weak) - Pass.TA.insert(I->IvarD->getLocation(), - canUseWeak ? "__weak " : "__unsafe_unretained "); + I->IvarD->getType().getObjCLifetime() != Qualifiers::OCL_Weak) { + const char *toWhich = + (Pass.isGCMigration() && !hasGCWeak(props, atLoc)) ? "__strong " : + (canUseWeak ? "__weak " : "__unsafe_unretained "); + Pass.TA.insert(I->IvarD->getLocation(), toWhich); + } } if (I->ImplD) Pass.TA.clearDiagnostic(diag::err_arc_assign_property_ownership, diff --git a/test/ARCMT/GC-no-arc-runtime.m.result b/test/ARCMT/GC-no-arc-runtime.m.result index 983af62c4a..983a5b1742 100644 --- a/test/ARCMT/GC-no-arc-runtime.m.result +++ b/test/ARCMT/GC-no-arc-runtime.m.result @@ -52,12 +52,12 @@ __attribute__((objc_arc_weak_reference_unavailable)) @end @interface I4Impl { - I4Impl *pds2; + I4Impl *__strong pds2; } @property (unsafe_unretained) I4Impl * pw1, * pw2; -@property I4Impl * ps; -@property I4Impl * pds; -@property I4Impl * pds2; +@property (strong) I4Impl * ps; +@property (strong) I4Impl * pds; +@property (strong) I4Impl * pds2; @end @implementation I4Impl diff --git a/test/ARCMT/GC.m b/test/ARCMT/GC.m index d309dabf68..f241e43008 100644 --- a/test/ARCMT/GC.m +++ b/test/ARCMT/GC.m @@ -79,3 +79,14 @@ __attribute__((objc_arc_weak_reference_unavailable)) id x = NSMakeCollectable(cft); } @end + +// rdar://10532449 +@interface rdar10532449 +@property (assign) id assign_prop; +@property (assign, readonly) id __strong strong_readonly_prop; +@property (assign) id __weak weak_prop; +@end + +@implementation rdar10532449 +@synthesize assign_prop, strong_readonly_prop, weak_prop; +@end diff --git a/test/ARCMT/GC.m.result b/test/ARCMT/GC.m.result index 2cf6b8e244..f9e954af5a 100644 --- a/test/ARCMT/GC.m.result +++ b/test/ARCMT/GC.m.result @@ -52,15 +52,15 @@ __attribute__((objc_arc_weak_reference_unavailable)) @end @interface I4Impl { - I4Impl *pds2; + I4Impl *__strong pds2; I4Impl *pds3; __weak I4Impl *pw3; __weak I4Impl *pw4; } @property (weak) I4Impl * pw1, * pw2; -@property I4Impl * ps; -@property I4Impl * pds; -@property I4Impl * pds2; +@property (strong) I4Impl * ps; +@property (strong) I4Impl * pds; +@property (strong) I4Impl * pds2; @property (readwrite) I4Impl * pds3; @property (readonly) I4Impl * pds4; @property (weak, readonly) I4Impl *pw3; @@ -74,3 +74,14 @@ __attribute__((objc_arc_weak_reference_unavailable)) id x = CFBridgingRelease(cft); } @end + +// rdar://10532449 +@interface rdar10532449 +@property (strong) id assign_prop; +@property (strong, readonly) id strong_readonly_prop; +@property (weak) id weak_prop; +@end + +@implementation rdar10532449 +@synthesize assign_prop, strong_readonly_prop, weak_prop; +@end -- 2.40.0