[cfe-commits] r159357 - in /cfe/trunk: lib/Sema/SemaExprObjC.cpp test/SemaObjC/weak-receiver-warn.m
Jordan Rose
jordan_rose at apple.com
Thu Jun 28 09:39:28 PDT 2012
Author: jrose
Date: Thu Jun 28 11:39:28 2012
New Revision: 159357
URL: http://llvm.org/viewvc/llvm-project?rev=159357&view=rev
Log:
Warn on weak properties declared in protocols as well.
Previously this caused a crash, since protocols are not interfaces.
Modified:
cfe/trunk/lib/Sema/SemaExprObjC.cpp
cfe/trunk/test/SemaObjC/weak-receiver-warn.m
Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=159357&r1=159356&r2=159357&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Thu Jun 28 11:39:28 2012
@@ -1379,10 +1379,12 @@
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<ObjCContainerDecl>(Container),
Sel.getIdentifierInfoForSlot(0));
+ }
if (PDecl)
T = PDecl->getType();
}
Modified: cfe/trunk/test/SemaObjC/weak-receiver-warn.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/weak-receiver-warn.m?rev=159357&r1=159356&r2=159357&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/weak-receiver-warn.m (original)
+++ cfe/trunk/test/SemaObjC/weak-receiver-warn.m Thu Jun 28 11:39:28 2012
@@ -66,3 +66,15 @@
}
@end
+
+
+// Weak properties on protocols can be synthesized by an adopting class.
+ at protocol MyProtocol
+ at property (weak) id object; // expected-note 2 {{property declared here}}
+ at end
+
+void testProtocol(id <MyProtocol> 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}}
+}
+
More information about the cfe-commits
mailing list