[cfe-commits] r142909 - in /cfe/trunk: lib/AST/DeclObjC.cpp test/SemaObjC/arc.m

Ted Kremenek kremenek at apple.com
Mon Oct 24 21:52:20 PDT 2011


Author: kremenek
Date: Mon Oct 24 23:52:20 2011
New Revision: 142909

URL: http://llvm.org/viewvc/llvm-project?rev=142909&view=rev
Log:
Relax restriction of assigning to 'self' in ARC when a method is attributed with ns_consumes_self.  Fixes <rdar://problem/10274056>.

Modified:
    cfe/trunk/lib/AST/DeclObjC.cpp
    cfe/trunk/test/SemaObjC/arc.m

Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=142909&r1=142908&r2=142909&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Mon Oct 24 23:52:20 2011
@@ -577,13 +577,13 @@
     selfIsConsumed = hasAttr<NSConsumesSelfAttr>();
 
     // 'self' is always __strong.  It's actually pseudo-strong except
-    // in init methods, though.
+    // in init methods (or methods labeled ns_consumes_self), though.
     Qualifiers qs;
     qs.setObjCLifetime(Qualifiers::OCL_Strong);
     selfTy = Context.getQualifiedType(selfTy, qs);
 
     // In addition, 'self' is const unless this is an init method.
-    if (getMethodFamily() != OMF_init) {
+    if (getMethodFamily() != OMF_init && !selfIsConsumed) {
       selfTy = selfTy.withConst();
       selfIsPseudoStrong = true;
     }

Modified: cfe/trunk/test/SemaObjC/arc.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/arc.m?rev=142909&r1=142908&r2=142909&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/arc.m (original)
+++ cfe/trunk/test/SemaObjC/arc.m Mon Oct 24 23:52:20 2011
@@ -294,6 +294,16 @@
 }
 @end
 
+// <rdar://problem/10274056>
+ at interface Test13_B
+- (id) consumesSelf __attribute__((ns_consumes_self));
+ at end
+ at implementation Test13_B
+- (id) consumesSelf {
+  self = 0; // no-warning
+}
+ at end
+
 // rdar://problem/9172151
 @class Test14A, Test14B;
 void test14() {





More information about the cfe-commits mailing list