From ee3d99f6be597364fedad2006c71e62e0baaed6b Mon Sep 17 00:00:00 2001 From: Jordan Rose Date: Thu, 28 Jun 2012 16:39:28 +0000 Subject: [PATCH] Warn on weak properties declared in protocols as well. Previously this caused a crash, since protocols are not interfaces. llvm-svn: 159357 --- clang/lib/Sema/SemaExprObjC.cpp | 6 ++++-- clang/test/SemaObjC/weak-receiver-warn.m | 12 ++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp index 598ad0b27ae3..a3fe7d3bbefe 100644 --- a/clang/lib/Sema/SemaExprObjC.cpp +++ b/clang/lib/Sema/SemaExprObjC.cpp @@ -1379,10 +1379,12 @@ static void DiagnoseARCUseOfWeakReceiver(Sema &S, Expr *Receiver) { ObjCMethodDecl *Method = ME->getMethodDecl(); if (Method && Method->isSynthesized()) { Selector Sel = Method->getSelector(); - if (Sel.getNumArgs() == 0) + if (Sel.getNumArgs() == 0) { + const DeclContext *Container = Method->getDeclContext(); PDecl = - S.LookupPropertyDecl(Method->getClassInterface(), + S.LookupPropertyDecl(cast(Container), Sel.getIdentifierInfoForSlot(0)); + } if (PDecl) T = PDecl->getType(); } diff --git a/clang/test/SemaObjC/weak-receiver-warn.m b/clang/test/SemaObjC/weak-receiver-warn.m index 56d9bc10f979..e6f8eaba8c50 100644 --- a/clang/test/SemaObjC/weak-receiver-warn.m +++ b/clang/test/SemaObjC/weak-receiver-warn.m @@ -66,3 +66,15 @@ void test0(Test0 *x) { } @end + + +// Weak properties on protocols can be synthesized by an adopting class. +@protocol MyProtocol +@property (weak) id object; // expected-note 2 {{property declared here}} +@end + +void testProtocol(id input) { + [[input object] Meth]; // expected-warning {{weak property may be unpredictably null in ARC mode}} + [input.object Meth]; // expected-warning {{weak property may be unpredictably null in ARC mode}} +} +