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
diff --git a/lib/ARCMigrate/TransProperties.cpp b/lib/ARCMigrate/TransProperties.cpp
index b36acbb..7eb2a9b 100644
--- a/lib/ARCMigrate/TransProperties.cpp
+++ b/lib/ARCMigrate/TransProperties.cpp
@@ -201,10 +201,8 @@
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 @@
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 983af62..983a5b1 100644
--- a/test/ARCMT/GC-no-arc-runtime.m.result
+++ b/test/ARCMT/GC-no-arc-runtime.m.result
@@ -52,12 +52,12 @@
@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 d309dab..f241e43 100644
--- a/test/ARCMT/GC.m
+++ b/test/ARCMT/GC.m
@@ -79,3 +79,14 @@
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 2cf6b8e..f9e954a 100644
--- a/test/ARCMT/GC.m.result
+++ b/test/ARCMT/GC.m.result
@@ -52,15 +52,15 @@
@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 @@
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