aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2012-01-10 19:28:26 +0000
committerFariborz Jahanian <fjahanian@apple.com>2012-01-10 19:28:26 +0000
commit6e6f93a1f16d9804db79390382e9d1f6322cdbfd (patch)
treeece807a1404d85dba7fb3b90dcded8bf8ffcd55d
parent02577fffafce0d88c7ad71502bb9e9bb628b2c0c (diff)
objc-arc: fixes a crash when trying to find out retaining cycle
ownership of property sent to 'super'. // rdar://10640891 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147868 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaChecking.cpp16
-rw-r--r--test/SemaObjC/arc-property-lifetime.m24
2 files changed, 36 insertions, 4 deletions
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp
index 73ff49a338..dc9ce076ea 100644
--- a/lib/Sema/SemaChecking.cpp
+++ b/lib/Sema/SemaChecking.cpp
@@ -4458,7 +4458,7 @@ static bool considerVariable(VarDecl *var, Expr *ref, RetainCycleOwner &owner) {
return true;
}
-static bool findRetainCycleOwner(Expr *e, RetainCycleOwner &owner) {
+static bool findRetainCycleOwner(Sema &S, Expr *e, RetainCycleOwner &owner) {
while (true) {
e = e->IgnoreParens();
if (CastExpr *cast = dyn_cast<CastExpr>(e)) {
@@ -4481,7 +4481,7 @@ static bool findRetainCycleOwner(Expr *e, RetainCycleOwner &owner) {
return false;
// Try to find a retain cycle in the base.
- if (!findRetainCycleOwner(ref->getBase(), owner))
+ if (!findRetainCycleOwner(S, ref->getBase(), owner))
return false;
if (ref->isFreeIvar()) owner.setLocsFrom(ref);
@@ -4524,6 +4524,14 @@ static bool findRetainCycleOwner(Expr *e, RetainCycleOwner &owner) {
return false;
owner.Indirect = true;
+ if (pre->isSuperReceiver()) {
+ owner.Variable = S.getCurMethodDecl()->getSelfDecl();
+ if (!owner.Variable)
+ return false;
+ owner.Loc = pre->getLocation();
+ owner.Range = pre->getSourceRange();
+ return true;
+ }
e = const_cast<Expr*>(cast<OpaqueValueExpr>(pre->getBase())
->getSourceExpr());
continue;
@@ -4626,7 +4634,7 @@ void Sema::checkRetainCycles(ObjCMessageExpr *msg) {
// Try to find a variable that the receiver is strongly owned by.
RetainCycleOwner owner;
if (msg->getReceiverKind() == ObjCMessageExpr::Instance) {
- if (!findRetainCycleOwner(msg->getInstanceReceiver(), owner))
+ if (!findRetainCycleOwner(*this, msg->getInstanceReceiver(), owner))
return;
} else {
assert(msg->getReceiverKind() == ObjCMessageExpr::SuperInstance);
@@ -4644,7 +4652,7 @@ void Sema::checkRetainCycles(ObjCMessageExpr *msg) {
/// Check a property assign to see if it's likely to cause a retain cycle.
void Sema::checkRetainCycles(Expr *receiver, Expr *argument) {
RetainCycleOwner owner;
- if (!findRetainCycleOwner(receiver, owner))
+ if (!findRetainCycleOwner(*this, receiver, owner))
return;
if (Expr *capturer = findCapturingExpr(*this, argument, owner))
diff --git a/test/SemaObjC/arc-property-lifetime.m b/test/SemaObjC/arc-property-lifetime.m
index 9cc3ada15f..2c27a518dd 100644
--- a/test/SemaObjC/arc-property-lifetime.m
+++ b/test/SemaObjC/arc-property-lifetime.m
@@ -125,3 +125,27 @@
@synthesize controllerClass = _controllerClass;
@synthesize controllerId = _controllerId;
@end
+
+// rdar://10630891
+@interface UIView @end
+@class UIColor;
+
+@interface UIView(UIViewRendering)
+@property(nonatomic,copy) UIColor *backgroundColor;
+@end
+
+@interface UILabel : UIView
+@end
+
+@interface MyView
+@property (strong) UILabel *label;
+@end
+
+@interface MyView2 : MyView @end
+
+@implementation MyView2
+- (void)foo {
+ super.label.backgroundColor = 0;
+}
+@end
+