diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Sema/SemaExprObjC.cpp | 59 | ||||
-rw-r--r-- | lib/Sema/SemaPseudoObject.cpp | 4 |
2 files changed, 37 insertions, 26 deletions
diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index c187a8deb7..12f5dc7288 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -1323,30 +1323,48 @@ ObjCMethodDecl *Sema::LookupMethodInQualifiedType(Selector Sel, return 0; } -void -Sema::DiagnoseARCUseOfWeakReceiver(NamedDecl *PDecl, - QualType T, SourceLocation Loc) { - if (!getLangOpts().ObjCAutoRefCount) +static void DiagnoseARCUseOfWeakReceiver(Sema &S, Expr *Receiver) { + if (!Receiver) return; - if (T.getObjCLifetime() == Qualifiers::OCL_Weak) { - Diag(Loc, diag::warn_receiver_is_weak) - << (!PDecl ? 0 : (isa<ObjCPropertyDecl>(PDecl) ? 1 : 2)); - if (PDecl) { - if (isa<ObjCPropertyDecl>(PDecl)) - Diag(PDecl->getLocation(), diag::note_property_declare); - else - Diag(PDecl->getLocation(), diag::note_method_declared_at) << PDecl; + Expr *RExpr = Receiver->IgnoreParenImpCasts(); + SourceLocation Loc = RExpr->getLocStart(); + QualType T = RExpr->getType(); + ObjCPropertyDecl *PDecl = 0; + ObjCMethodDecl *GDecl = 0; + if (PseudoObjectExpr *POE = dyn_cast<PseudoObjectExpr>(RExpr)) { + RExpr = POE->getSyntacticForm(); + if (ObjCPropertyRefExpr *PRE = dyn_cast<ObjCPropertyRefExpr>(RExpr)) { + if (PRE->isImplicitProperty()) { + GDecl = PRE->getImplicitPropertyGetter(); + if (GDecl) { + T = GDecl->getResultType(); + } + } + else { + PDecl = PRE->getExplicitProperty(); + if (PDecl) { + T = PDecl->getType(); + } + } } + } + + if (T.getObjCLifetime() == Qualifiers::OCL_Weak) { + S.Diag(Loc, diag::warn_receiver_is_weak) + << ((!PDecl && !GDecl) ? 0 : (PDecl ? 1 : 2)); + if (PDecl) + S.Diag(PDecl->getLocation(), diag::note_property_declare); + else if (GDecl) + S.Diag(GDecl->getLocation(), diag::note_method_declared_at) << GDecl; return; } - if (PDecl) - if (ObjCPropertyDecl *Prop = dyn_cast<ObjCPropertyDecl>(PDecl)) - if (Prop->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_weak) { - Diag(Loc, diag::warn_receiver_is_weak) << 1; - Diag(Prop->getLocation(), diag::note_property_declare); - } + if (PDecl && + (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_weak)) { + S.Diag(Loc, diag::warn_receiver_is_weak) << 1; + S.Diag(PDecl->getLocation(), diag::note_property_declare); + } } /// HandleExprPropertyRefExpr - Handle foo.bar where foo is a pointer to an @@ -2404,10 +2422,7 @@ ExprResult Sema::BuildInstanceMessage(Expr *Receiver, } if (getLangOpts().ObjCAutoRefCount) { - if (Receiver) - DiagnoseARCUseOfWeakReceiver(0 /* PDecl */, - Receiver->IgnoreParenImpCasts()->getType(), - Receiver->getLocStart()); + DiagnoseARCUseOfWeakReceiver(*this, Receiver); // In ARC, annotate delegate init calls. if (Result->getMethodFamily() == OMF_init && diff --git a/lib/Sema/SemaPseudoObject.cpp b/lib/Sema/SemaPseudoObject.cpp index 078b0e4bc4..0e6632964a 100644 --- a/lib/Sema/SemaPseudoObject.cpp +++ b/lib/Sema/SemaPseudoObject.cpp @@ -478,8 +478,6 @@ bool ObjCPropertyOpBuilder::findGetter() { if (RefExpr->isImplicitProperty()) { if ((Getter = RefExpr->getImplicitPropertyGetter())) { GetterSelector = Getter->getSelector(); - S.DiagnoseARCUseOfWeakReceiver(Getter, Getter->getResultType(), - RefExpr->getLocation()); return true; } else { @@ -499,8 +497,6 @@ bool ObjCPropertyOpBuilder::findGetter() { } ObjCPropertyDecl *prop = RefExpr->getExplicitProperty(); - S.DiagnoseARCUseOfWeakReceiver(prop, prop->getType(), - RefExpr->getLocation()); Getter = LookupMethodInReceiverType(S, prop->getGetterName(), RefExpr); return (Getter != 0); } |