[cfe-commits] r129576 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/SemaObjC/self-declared-in-block.m

Fariborz Jahanian fjahanian at apple.com
Fri Apr 15 10:04:42 PDT 2011


Author: fjahanian
Date: Fri Apr 15 12:04:42 2011
New Revision: 129576

URL: http://llvm.org/viewvc/llvm-project?rev=129576&view=rev
Log:
Allow shadowin of 'self' in objc methods in
cases where stand-alone ivar can be looked up
in shadowed object. To fix gcc compatibility
breakage. // rdar://9284603

Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/SemaObjC/self-declared-in-block.m

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=129576&r1=129575&r2=129576&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Apr 15 12:04:42 2011
@@ -2089,11 +2089,21 @@
       if (const DeclRefExpr *DE = dyn_cast<DeclRefExpr>(base)) {
         const NamedDecl *ND = DE->getDecl();
         if (!isa<ImplicitParamDecl>(ND)) {
+          // relax the rule such that it is allowed to have a shadow 'self'
+          // where stand-alone ivar can be found in this 'self' object. 
+          // This is to match gcc's behavior.
+          ObjCInterfaceDecl *selfIFace = 0;
+          if (const ObjCObjectPointerType *OPT =
+              base->getType()->getAsObjCInterfacePointerType())
+            selfIFace = OPT->getInterfaceDecl();
+          if (!selfIFace || 
+              !selfIFace->lookupInstanceVariable(IV->getIdentifier())) {
             Diag(Loc, diag::error_implicit_ivar_access)
             << IV->getDeclName();
             Diag(ND->getLocation(), diag::note_declared_at);
             return ExprError();
           }
+        }
       }
       return Owned(new (Context)
                    ObjCIvarRefExpr(IV, IV->getType(), Loc,

Modified: cfe/trunk/test/SemaObjC/self-declared-in-block.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/self-declared-in-block.m?rev=129576&r1=129575&r2=129576&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/self-declared-in-block.m (original)
+++ cfe/trunk/test/SemaObjC/self-declared-in-block.m Fri Apr 15 12:04:42 2011
@@ -16,3 +16,36 @@
 
 @end
 
+
+// rdar://9284603
+ at interface ShadowSelf
+{
+    int _anIvar;
+}
+ at end
+
+ at interface C {
+  int _cIvar;
+}
+ at end
+
+ at implementation ShadowSelf 
+- (void)doSomething {
+    __typeof(self) newSelf = self;
+    {
+        __typeof(self) self = newSelf;
+        (void)_anIvar;
+    }
+    {
+      C* self;	// expected-note {{declared here}}
+      (void) _anIvar; // expected-error {{instance variable '_anIvar' cannot be accessed because 'self' has been redeclared}}
+    }
+}
+- (void)doAThing {
+    ^{
+        id self;	// expected-note {{declared here}}
+	(void)_anIvar; // expected-error {{instance variable '_anIvar' cannot be accessed because 'self' has been redeclared}}
+    }();
+}
+ at end
+





More information about the cfe-commits mailing list