[cfe-commits] r70822 - in /cfe/trunk: lib/AST/ASTContext.cpp lib/CodeGen/CGObjCMac.cpp test/CodeGenObjC/ivar-layout-64.m

Daniel Dunbar daniel at zuster.org
Sun May 3 21:10:56 PDT 2009


Author: ddunbar
Date: Sun May  3 23:10:48 2009
New Revision: 70822

URL: http://llvm.org/viewvc/llvm-project?rev=70822&view=rev
Log:
Don't allow clients to traverse into superclass synthesized properties
via CollectObjCIvars.
 - In places where we need them, we should have the implementation and
   access the properties through it.

This is a fairly substantial functionality change: 
 1. @encode no longer encodes synthesized ivars, ever.

 2. The ivar layout bitmap no longer encodes information for
    synthesized ivars in superclasses. Well, actually I had already
    broken that, but it is intentional now.

We are now differing substantially from llvm-gcc and gcc
here. However, in my opinion this fundamentally *must* work if
non-fragile classes are to work. Without this change, the result of
@encode and the ivar layout depend on the order that the
implementation is seen in a file (if it is in the same file with its
superclass). Since both scenarios should work the same, our behavior
is now consistent with gcc behavior as if an implementation is never
seen following an implementation of its superclass.

Note that #2 is only a functionality change when (A) an
implementation appears in the same translation unit with the
implementation of its superclass, and (B) the superclass has
synthesized ivars. My belief is that this situation does not occur in
practice.

I am not yet sure of the role/semantics of @encode when synthesized
ivars are present... it's use is fairly unsound in a non-fragile world.

Modified:
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/lib/CodeGen/CGObjCMac.cpp
    cfe/trunk/test/CodeGenObjC/ivar-layout-64.m

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=70822&r1=70821&r2=70822&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Sun May  3 23:10:48 2009
@@ -667,15 +667,6 @@
     if (!IVDecl->isInvalidDecl())
       Fields.push_back(cast<FieldDecl>(IVDecl));
   }
-  // Look into properties.
-  //
-  // FIXME: This needs to go away, synthesized ivars shouldn't be
-  // accessible from the interface decl.
-  for (ObjCInterfaceDecl::prop_iterator I = OI->prop_begin(*Ctx),
-       E = OI->prop_end(*Ctx); I != E; ++I) {
-    if (ObjCIvarDecl *IV = (*I)->getPropertyIvarDecl())
-      Fields.push_back(cast<FieldDecl>(IV));
-  }
 }
 
 void ASTContext::CollectObjCIvars(const ObjCInterfaceDecl *OI,

Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=70822&r1=70821&r2=70822&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Sun May  3 23:10:48 2009
@@ -3095,6 +3095,14 @@
   llvm::SmallVector<FieldDecl*, 32> RecFields;
   const ObjCInterfaceDecl *OI = OMD->getClassInterface();
   CGM.getContext().CollectObjCIvars(OI, RecFields);
+
+  // Add this implementations synthesized ivars.
+  for (ObjCInterfaceDecl::prop_iterator I = OI->prop_begin(CGM.getContext()),
+         E = OI->prop_end(CGM.getContext()); I != E; ++I) {
+    if (ObjCIvarDecl *IV = (*I)->getPropertyIvarDecl())
+      RecFields.push_back(cast<FieldDecl>(IV));
+  }
+
   if (RecFields.empty())
     return llvm::Constant::getNullValue(PtrTy);
   

Modified: cfe/trunk/test/CodeGenObjC/ivar-layout-64.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/ivar-layout-64.m?rev=70822&r1=70821&r2=70822&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenObjC/ivar-layout-64.m (original)
+++ cfe/trunk/test/CodeGenObjC/ivar-layout-64.m Sun May  3 23:10:48 2009
@@ -11,6 +11,7 @@
 llvm-gcc -m64 -fobjc-gc -emit-llvm -S -o - ivar-layout-64.m | \
   grep 'OBJC_CLASS_NAME.* =.*global' | \
   sed -e 's#, section.*# ...#' | \
+  sed -e 's#_[0-9]*"#_NNN#' | \
   sort
 
 */
@@ -32,14 +33,34 @@
 }
 @end
 
+ at interface C : A
+ at property int p3;
+ at end
+
+ at implementation C
+ at synthesize p3 = _p3;
+ at end
+
 @interface A()
 @property int p0;
 @property (assign) __strong id p1;
 @property (assign) __weak id p2;
 @end
 
+// FIXME: Check layout for this class, once it is clear what the right
+// answer is.
 @implementation A
- at synthesize p0;
- at synthesize p1;
- at synthesize p2;
+ at synthesize p0 = _p0;
+ at synthesize p1 = _p1;
+ at synthesize p2 = _p2;
+ at end
+
+ at interface D : A
+ at property int p3;
+ at end
+
+// FIXME: Check layout for this class, once it is clear what the right
+// answer is.
+ at implementation D
+ at synthesize p3 = _p3;
 @end





More information about the cfe-commits mailing list