Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 8b08eb3

Browse files
committed
[arcmt] Take into account that all properties are strong-by-default now and fix the test.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144146 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent a5493f8 commit 8b08eb3

File tree

3 files changed

+13
-50
lines changed

3 files changed

+13
-50
lines changed

lib/ARCMigrate/TransProperties.cpp

+7-42
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,9 @@ class PropertiesRewriter {
5050

5151
enum PropActionKind {
5252
PropAction_None,
53-
PropAction_RetainToStrong,
5453
PropAction_RetainRemoved,
5554
PropAction_AssignRemoved,
5655
PropAction_AssignRewritten,
57-
PropAction_MaybeAddStrong,
5856
PropAction_MaybeAddWeakOrUnsafe
5957
};
6058

@@ -163,18 +161,13 @@ class PropertiesRewriter {
163161
switch (kind) {
164162
case PropAction_None:
165163
return;
166-
case PropAction_RetainToStrong:
167-
rewriteAttribute("retain", "strong", atLoc);
168-
return;
169164
case PropAction_RetainRemoved:
170165
removeAttribute("retain", atLoc);
171166
return;
172167
case PropAction_AssignRemoved:
173168
return removeAssignForDefaultStrong(props, atLoc);
174169
case PropAction_AssignRewritten:
175170
return rewriteAssign(props, atLoc);
176-
case PropAction_MaybeAddStrong:
177-
return maybeAddStrongAttr(props, atLoc);
178171
case PropAction_MaybeAddWeakOrUnsafe:
179172
return maybeAddWeakOrUnsafeUnretainedAttr(props, atLoc);
180173
}
@@ -199,11 +192,8 @@ class PropertiesRewriter {
199192
return;
200193

201194
if (propAttrs & ObjCPropertyDecl::OBJC_PR_retain) {
202-
if (propAttrs & ObjCPropertyDecl::OBJC_PR_readonly)
203-
return doPropAction(PropAction_RetainToStrong, props, atLoc);
204-
else
205-
// strong is the default.
206-
return doPropAction(PropAction_RetainRemoved, props, atLoc);
195+
// strong is the default.
196+
return doPropAction(PropAction_RetainRemoved, props, atLoc);
207197
}
208198

209199
bool HasIvarAssignedAPlusOneObject = hasIvarAssignedAPlusOneObject(props);
@@ -258,17 +248,13 @@ class PropertiesRewriter {
258248

259249
void maybeAddWeakOrUnsafeUnretainedAttr(PropsTy &props,
260250
SourceLocation atLoc) const {
261-
ObjCPropertyDecl::PropertyAttributeKind propAttrs = getPropertyAttrs(props);
262-
263251
bool canUseWeak = canApplyWeak(Pass.Ctx, getPropertyType(props),
264252
/*AllowOnUnknownClass=*/Pass.isGCMigration());
265-
if (!(propAttrs & ObjCPropertyDecl::OBJC_PR_readonly) ||
266-
!hasAllIvarsBacked(props)) {
267-
bool addedAttr = addAttribute(canUseWeak ? "weak" : "unsafe_unretained",
268-
atLoc);
269-
if (!addedAttr)
270-
canUseWeak = false;
271-
}
253+
254+
bool addedAttr = addAttribute(canUseWeak ? "weak" : "unsafe_unretained",
255+
atLoc);
256+
if (!addedAttr)
257+
canUseWeak = false;
272258

273259
for (PropsTy::iterator I = props.begin(), E = props.end(); I != E; ++I) {
274260
if (isUserDeclared(I->IvarD))
@@ -284,27 +270,6 @@ class PropertiesRewriter {
284270
}
285271
}
286272

287-
void maybeAddStrongAttr(PropsTy &props, SourceLocation atLoc) const {
288-
ObjCPropertyDecl::PropertyAttributeKind propAttrs = getPropertyAttrs(props);
289-
290-
if (!(propAttrs & ObjCPropertyDecl::OBJC_PR_readonly))
291-
return; // 'strong' by default.
292-
293-
if (!hasAllIvarsBacked(props)) {
294-
addAttribute("strong", atLoc);
295-
}
296-
297-
for (PropsTy::iterator I = props.begin(), E = props.end(); I != E; ++I) {
298-
if (I->ImplD) {
299-
Pass.TA.clearDiagnostic(diag::err_arc_assign_property_ownership,
300-
I->ImplD->getLocation());
301-
Pass.TA.clearDiagnostic(
302-
diag::err_arc_objc_property_default_assign_on_object,
303-
I->ImplD->getLocation());
304-
}
305-
}
306-
}
307-
308273
bool removeAttribute(StringRef fromAttr, SourceLocation atLoc) const {
309274
return rewriteAttribute(fromAttr, StringRef(), atLoc);
310275
}

test/ARCMT/assign-prop-with-arc-runtime.m

+2-3
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,15 @@ @interface WeakOptOut
1414
@class Forw;
1515

1616
@interface Foo : NSObject {
17-
Foo *w, *q1, *q2;
18-
__weak Foo *x;
17+
Foo *x, *w, *q1, *q2;
1918
WeakOptOut *oo;
2019
BadClassForWeak bcw;
2120
id not_safe1;
2221
NSObject *not_safe2;
2322
Forw *not_safe3;
2423
Foo *assign_plus1;
2524
}
26-
@property (readonly) __weak Foo *x;
25+
@property (readonly) Foo *x;
2726
@property (assign) Foo *w;
2827
@property Foo *q1, *q2;
2928
@property (assign) WeakOptOut *oo;

test/ARCMT/assign-prop-with-arc-runtime.m.result

+4-5
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,15 @@ typedef _NSCachedAttributedString *BadClassForWeak;
1414
@class Forw;
1515

1616
@interface Foo : NSObject {
17-
Foo *__weak w, *__weak q1, *__weak q2;
18-
__weak Foo *x;
17+
Foo *__weak x, *__weak w, *__weak q1, *__weak q2;
1918
WeakOptOut *__unsafe_unretained oo;
2019
BadClassForWeak __unsafe_unretained bcw;
2120
id __unsafe_unretained not_safe1;
2221
NSObject *__unsafe_unretained not_safe2;
2322
Forw *__unsafe_unretained not_safe3;
2423
Foo *assign_plus1;
2524
}
26-
@property (readonly) __weak Foo *x;
25+
@property (weak, readonly) Foo *x;
2726
@property (weak) Foo *w;
2827
@property (weak) Foo *q1, *q2;
2928
@property (unsafe_unretained) WeakOptOut *oo;
@@ -58,12 +57,12 @@ typedef _NSCachedAttributedString *BadClassForWeak;
5857
@end
5958

6059
@interface TestExt
61-
@property (strong,readonly) TestExt *x1;
60+
@property (readonly) TestExt *x1;
6261
@property (weak, readonly) TestExt *x2;
6362
@end
6463

6564
@interface TestExt()
66-
@property (strong,readwrite) TestExt *x1;
65+
@property (readwrite) TestExt *x1;
6766
@property (weak, readwrite) TestExt *x2;
6867
@end
6968

0 commit comments

Comments
 (0)