[cfe-commits] r154042 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaExprObjC.cpp test/SemaObjC/weak-receiver-warn.m
Fariborz Jahanian
fjahanian at apple.com
Wed Apr 4 13:05:25 PDT 2012
Author: fjahanian
Date: Wed Apr 4 15:05:25 2012
New Revision: 154042
URL: http://llvm.org/viewvc/llvm-project?rev=154042&view=rev
Log:
objc-arc: provide a warning when 'receiver' of a message is 'weak'
in arc mode and opted-in with -Wreceiver-is-weak flag.
// rdar://10225276
Added:
cfe/trunk/test/SemaObjC/weak-receiver-warn.m
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaExprObjC.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=154042&r1=154041&r2=154042&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Apr 4 15:05:25 2012
@@ -652,6 +652,9 @@
InGroup<DiagGroup<"arc-performSelector-leaks">>;
def err_gc_weak_property_strong_type : Error<
"weak attribute declared on a __strong type property in GC mode">;
+def warn_receiver_is_weak : Warning <
+ "weak receiver may be unpredictably null in ARC mode">,
+ InGroup<DiagGroup<"receiver-is-weak">>, DefaultIgnore;
def error_synthesized_ivar_yet_not_supported : Error<
"instance variable synthesis not yet supported"
Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=154042&r1=154041&r2=154042&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Wed Apr 4 15:05:25 2012
@@ -2232,6 +2232,11 @@
}
if (getLangOpts().ObjCAutoRefCount) {
+ if (Receiver &&
+ (Receiver->IgnoreParenImpCasts()->getType().getObjCLifetime()
+ == Qualifiers::OCL_Weak))
+ Diag(Receiver->getLocStart(), diag::warn_receiver_is_weak);
+
// In ARC, annotate delegate init calls.
if (Result->getMethodFamily() == OMF_init &&
(SuperLoc.isValid() || isSelfExpr(Receiver))) {
Added: cfe/trunk/test/SemaObjC/weak-receiver-warn.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/weak-receiver-warn.m?rev=154042&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/weak-receiver-warn.m (added)
+++ cfe/trunk/test/SemaObjC/weak-receiver-warn.m Wed Apr 4 15:05:25 2012
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -fobjc-runtime-has-weak -fobjc-arc -fblocks -Wreceiver-is-weak -verify %s
+// rdar://10225276
+
+ at interface Test0
+- (void) setBlock: (void(^)(void)) block;
+- (void) addBlock: (void(^)(void)) block;
+- (void) actNow;
+ at end
+
+void test0(Test0 *x) {
+ __weak Test0 *weakx = x;
+ [x addBlock: ^{ [weakx actNow]; }]; // expected-warning {{weak receiver may be unpredictably null in ARC mode}}
+ [x setBlock: ^{ [weakx actNow]; }]; // expected-warning {{weak receiver may be unpredictably null in ARC mode}}
+ x.block = ^{ [weakx actNow]; }; // expected-warning {{weak receiver may be unpredictably null in ARC mode}}
+
+ [weakx addBlock: ^{ [x actNow]; }]; // expected-warning {{weak receiver may be unpredictably null in ARC mode}}
+ [weakx setBlock: ^{ [x actNow]; }]; // expected-warning {{weak receiver may be unpredictably null in ARC mode}}
+ weakx.block = ^{ [x actNow]; };
+}
More information about the cfe-commits
mailing list