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

Commit 94a9016

Browse files
committed
[arcmt] When checking whether properties needs to be strong or not, take into account
that assigning result of -retain means it should be strong. rdar://9931757. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@137252 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 8a4bfaa commit 94a9016

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

lib/ARCMigrate/TransProperties.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,11 @@ class PropertiesRewriter {
330330
if (RE->getDecl() != Ivar)
331331
return true;
332332

333+
if (ObjCMessageExpr *
334+
ME = dyn_cast<ObjCMessageExpr>(E->getRHS()->IgnoreParenCasts()))
335+
if (ME->getMethodFamily() == OMF_retain)
336+
return false;
337+
333338
ImplicitCastExpr *implCE = dyn_cast<ImplicitCastExpr>(E->getRHS());
334339
while (implCE && implCE->getCastKind() == CK_BitCast)
335340
implCE = dyn_cast<ImplicitCastExpr>(implCE->getSubExpr());

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,20 @@ @interface Foo : NSObject {
3232
@property Forw *not_safe3;
3333
@property (readonly) Foo *assign_plus1;
3434
@property (readonly) Foo *assign_plus2;
35+
@property (readonly) Foo *assign_plus3;
3536

3637
@property (assign) Foo *no_user_ivar1;
3738
@property (readonly) Foo *no_user_ivar2;
38-
39-
-(void)test;
4039
@end
4140

4241
@implementation Foo
4342
@synthesize x,w,q1,q2,oo,bcw,not_safe1,not_safe2,not_safe3;
4443
@synthesize no_user_ivar1, no_user_ivar2;
45-
@synthesize assign_plus1, assign_plus2;
44+
@synthesize assign_plus1, assign_plus2, assign_plus3;
4645

47-
-(void)test {
46+
-(void)test:(Foo *)parm {
4847
assign_plus1 = [[Foo alloc] init];
4948
assign_plus2 = [Foo new];
49+
assign_plus3 = [parm retain];
5050
}
5151
@end

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,20 @@ typedef _NSCachedAttributedString *BadClassForWeak;
3232
@property (unsafe_unretained) Forw *not_safe3;
3333
@property (readonly) Foo *assign_plus1;
3434
@property (strong, readonly) Foo *assign_plus2;
35+
@property (strong, readonly) Foo *assign_plus3;
3536

3637
@property (weak) Foo *no_user_ivar1;
3738
@property (weak, readonly) Foo *no_user_ivar2;
38-
39-
-(void)test;
4039
@end
4140

4241
@implementation Foo
4342
@synthesize x,w,q1,q2,oo,bcw,not_safe1,not_safe2,not_safe3;
4443
@synthesize no_user_ivar1, no_user_ivar2;
45-
@synthesize assign_plus1, assign_plus2;
44+
@synthesize assign_plus1, assign_plus2, assign_plus3;
4645

47-
-(void)test {
46+
-(void)test:(Foo *)parm {
4847
assign_plus1 = [[Foo alloc] init];
4948
assign_plus2 = [Foo new];
49+
assign_plus3 = parm;
5050
}
5151
@end

0 commit comments

Comments
 (0)