[cfe-commits] r64391 - /cfe/trunk/lib/CodeGen/CGObjCMac.cpp

Fariborz Jahanian fjahanian at apple.com
Thu Feb 12 10:51:24 PST 2009


Author: fjahanian
Date: Thu Feb 12 12:51:23 2009
New Revision: 64391

URL: http://llvm.org/viewvc/llvm-project?rev=64391&view=rev
Log:
Fix a bug whereby, an ivar used to synthesize a property belongs
to a base class (nonfragile abi ir gen bug).

Modified:
    cfe/trunk/lib/CodeGen/CGObjCMac.cpp

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Thu Feb 12 12:51:23 2009
@@ -677,7 +677,7 @@
   /// the given ivar.
   ///
   llvm::GlobalVariable * ObjCIvarOffsetVariable(std::string &Name, 
-                              const NamedDecl *IDName,
+                              const ObjCInterfaceDecl *ID,
                               const ObjCIvarDecl *Ivar);
   
   /// EmitSelector - Return a Value*, of type ObjCTypes.SelectorPtrTy,
@@ -1600,6 +1600,26 @@
   return count;
 }
 
+/// getInterfaceDeclForIvar - Get the interface declaration node where
+/// this ivar is declared in.
+/// FIXME. Ideally, this info should be in the ivar node. But currently 
+/// it is not and prevailing wisdom is that ASTs should not have more
+/// info than is absolutely needed, even though this info reflects the
+/// source language. 
+///
+static const ObjCInterfaceDecl *getInterfaceDeclForIvar(
+                                  const ObjCInterfaceDecl *OI,
+                                  const ObjCIvarDecl *IVD) {
+  if (!OI)
+    return 0;
+  assert(isa<ObjCInterfaceDecl>(OI) && "OI is not an interface");
+  for (ObjCInterfaceDecl::ivar_iterator I = OI->ivar_begin(),
+       E = OI->ivar_end(); I != E; ++I)
+    if ((*I)->getIdentifier() == IVD->getIdentifier())
+      return OI;
+  return getInterfaceDeclForIvar(OI->getSuperClass(), IVD);
+}
+
 /*
   struct objc_ivar {
     char *ivar_name;
@@ -3921,9 +3941,10 @@
 ///
 llvm::GlobalVariable * CGObjCNonFragileABIMac::ObjCIvarOffsetVariable(
                               std::string &Name, 
-                              const NamedDecl *IDName,
+                              const ObjCInterfaceDecl *ID,
                               const ObjCIvarDecl *Ivar) {
-  Name += "\01_OBJC_IVAR_$_" + IDName->getNameAsString() + '.'
+  Name += "\01_OBJC_IVAR_$_" + 
+          getInterfaceDeclForIvar(ID, Ivar)->getNameAsString() + '.'
           + Ivar->getNameAsString();
   llvm::GlobalVariable *IvarOffsetGV = 
     CGM.getModule().getGlobalVariable(Name);
@@ -4298,7 +4319,7 @@
                                              unsigned CVRQualifiers) {
   assert(ObjectTy->isObjCInterfaceType() && 
          "CGObjCNonFragileABIMac::EmitObjCValueForIvar");
-  NamedDecl *ID = ObjectTy->getAsObjCInterfaceType()->getDecl();
+  ObjCInterfaceDecl *ID = ObjectTy->getAsObjCInterfaceType()->getDecl();
   std::string ExternalName;
   llvm::GlobalVariable *IvarOffsetGV =
     ObjCIvarOffsetVariable(ExternalName, ID, Ivar);





More information about the cfe-commits mailing list