summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaExprObjC.cpp
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2012-04-19 21:44:57 +0000
committerFariborz Jahanian <fjahanian@apple.com>2012-04-19 21:44:57 +0000
commitfce89c609da6961fe4b7277b40d6459405ff8737 (patch)
tree10ee90f33f19a9e8b0a9b8bd122feb65dc087f96 /clang/lib/Sema/SemaExprObjC.cpp
parentc9cb71a0b3032b5607aa7e67dbb5712c6accb03f (diff)
downloadbcm5719-llvm-fce89c609da6961fe4b7277b40d6459405ff8737.tar.gz
bcm5719-llvm-fce89c609da6961fe4b7277b40d6459405ff8737.zip
objective-c arc: Issue warning under -Wreceiver-is-weak
if receiver is a 'weak' property, by type or by attribute. // rdar://10225276 llvm-svn: 155159
Diffstat (limited to 'clang/lib/Sema/SemaExprObjC.cpp')
-rw-r--r--clang/lib/Sema/SemaExprObjC.cpp37
1 files changed, 31 insertions, 6 deletions
diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp
index 41fd112c718..c187a8deb76 100644
--- a/clang/lib/Sema/SemaExprObjC.cpp
+++ b/clang/lib/Sema/SemaExprObjC.cpp
@@ -1323,6 +1323,32 @@ ObjCMethodDecl *Sema::LookupMethodInQualifiedType(Selector Sel,
return 0;
}
+void
+Sema::DiagnoseARCUseOfWeakReceiver(NamedDecl *PDecl,
+ QualType T, SourceLocation Loc) {
+ if (!getLangOpts().ObjCAutoRefCount)
+ 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;
+ }
+ 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);
+ }
+}
+
/// HandleExprPropertyRefExpr - Handle foo.bar where foo is a pointer to an
/// objective C interface. This is a property reference expression.
ExprResult Sema::
@@ -1354,7 +1380,6 @@ HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT,
// Check whether we can reference this property.
if (DiagnoseUseOfDecl(PD, MemberLoc))
return ExprError();
-
if (Super)
return Owned(new (Context) ObjCPropertyRefExpr(PD, Context.PseudoObjectTy,
VK_LValue, OK_ObjCProperty,
@@ -1372,7 +1397,7 @@ HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT,
// Check whether we can reference this property.
if (DiagnoseUseOfDecl(PD, MemberLoc))
return ExprError();
-
+
if (Super)
return Owned(new (Context) ObjCPropertyRefExpr(PD,
Context.PseudoObjectTy,
@@ -2379,10 +2404,10 @@ ExprResult Sema::BuildInstanceMessage(Expr *Receiver,
}
if (getLangOpts().ObjCAutoRefCount) {
- if (Receiver &&
- (Receiver->IgnoreParenImpCasts()->getType().getObjCLifetime()
- == Qualifiers::OCL_Weak))
- Diag(Receiver->getLocStart(), diag::warn_receiver_is_weak);
+ if (Receiver)
+ DiagnoseARCUseOfWeakReceiver(0 /* PDecl */,
+ Receiver->IgnoreParenImpCasts()->getType(),
+ Receiver->getLocStart());
// In ARC, annotate delegate init calls.
if (Result->getMethodFamily() == OMF_init &&
OpenPOWER on IntegriCloud