[cfe-commits] r67755 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/SemaObjC/ivar-access-package.m

Steve Naroff snaroff at apple.com
Thu Mar 26 09:01:09 PDT 2009


Author: snaroff
Date: Thu Mar 26 11:01:08 2009
New Revision: 67755

URL: http://llvm.org/viewvc/llvm-project?rev=67755&view=rev
Log:
Fix <rdar://problem/6697053> instance variable is protected.

Treat @package the same as @public. The documentation for @package says it is analogous to private_extern for variables/functions. Fully implementing this requires some kind of linker support (so access is denied to code outside the classes executable image). I don't believe GCC fully implements this semantic. Will discuss with Fariborz offline.

Added:
    cfe/trunk/test/SemaObjC/ivar-access-package.m
Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=67755&r1=67754&r2=67755&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Mar 26 11:01:08 2009
@@ -1876,7 +1876,8 @@
       // Check whether we can reference this field.
       if (DiagnoseUseOfDecl(IV, MemberLoc))
         return ExprError();
-      if (IV->getAccessControl() != ObjCIvarDecl::Public) {
+      if (IV->getAccessControl() != ObjCIvarDecl::Public &&
+          IV->getAccessControl() != ObjCIvarDecl::Package) {
         ObjCInterfaceDecl *ClassOfMethodDecl = 0;
         if (ObjCMethodDecl *MD = getCurMethodDecl())
           ClassOfMethodDecl =  MD->getClassInterface();

Added: cfe/trunk/test/SemaObjC/ivar-access-package.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/ivar-access-package.m?rev=67755&view=auto

==============================================================================
--- cfe/trunk/test/SemaObjC/ivar-access-package.m (added)
+++ cfe/trunk/test/SemaObjC/ivar-access-package.m Thu Mar 26 11:01:08 2009
@@ -0,0 +1,45 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+
+typedef unsigned char BOOL;
+
+ at interface NSObject {
+  id isa;
+}
++new;
++alloc;
+-init;
+-autorelease;
+ at end
+
+ at interface NSAutoreleasePool : NSObject
+- drain;
+ at end
+ 
+ at interface A : NSObject {
+ at package
+    id object;
+}
+ at end
+
+ at interface B : NSObject
+- (BOOL)containsSelf:(A*)a;
+ at end
+
+ at implementation A
+ at end
+
+ at implementation B
+- (BOOL)containsSelf:(A*)a {
+    return a->object == self;
+}
+ at end
+
+int main (int argc, const char * argv[]) {
+    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+    A *a = [[A new] autorelease];
+    B *b = [[B new] autorelease];
+    NSLog(@"%s", [b containsSelf:a] ? "YES" : "NO");
+    [pool drain];
+    return 0;
+}
+





More information about the cfe-commits mailing list