[cfe-commits] r87017 - in /cfe/trunk: lib/CodeGen/CGObjCMac.cpp test/CodeGenObjC/super-message-fragileabi.m

Fariborz Jahanian fjahanian at apple.com
Thu Nov 12 12:14:25 PST 2009


Author: fjahanian
Date: Thu Nov 12 14:14:24 2009
New Revision: 87017

URL: http://llvm.org/viewvc/llvm-project?rev=87017&view=rev
Log:
Fix a code gen bug in i386-apple-darwin (objc fragile abi), sending
message to 'super'. Fixes radar 7205866.


Added:
    cfe/trunk/test/CodeGenObjC/super-message-fragileabi.m
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=87017&r1=87016&r2=87017&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Thu Nov 12 14:14:24 2009
@@ -991,6 +991,9 @@
   /// for the given class.
   llvm::Value *EmitClassRef(CGBuilderTy &Builder,
                             const ObjCInterfaceDecl *ID);
+  
+  /// EmitSuperClassRef - Emits reference to class's main metadata class.
+  llvm::Value *EmitSuperClassRef(const ObjCInterfaceDecl *ID);
 
   CodeGen::RValue EmitMessageSend(CodeGen::CodeGenFunction &CGF,
                                   QualType ResultType,
@@ -1486,7 +1489,9 @@
       Target = Super;
     }
   } else {
-    Target = EmitClassRef(CGF.Builder, Class->getSuperClass());
+    llvm::Value *ClassPtr = EmitSuperClassRef(Class);
+    ClassPtr = CGF.Builder.CreateStructGEP(ClassPtr, 1);
+    Target = CGF.Builder.CreateLoad(ClassPtr);
   }
   // FIXME: We shouldn't need to do this cast, rectify the ASTContext and
   // ObjCTypes types.
@@ -2051,11 +2056,22 @@
   Values[11] = EmitClassExtension(ID);
   llvm::Constant *Init = llvm::ConstantStruct::get(ObjCTypes.ClassTy,
                                                    Values);
-
-  llvm::GlobalVariable *GV =
-    CreateMetadataVar("\01L_OBJC_CLASS_" + ClassName, Init,
-                      "__OBJC,__class,regular,no_dead_strip",
-                      4, true);
+  std::string Name("\01L_OBJC_CLASS_");
+  Name += ClassName;
+  const char *Section = "__OBJC,__class,regular,no_dead_strip";
+  // Check for a forward reference.
+  llvm::GlobalVariable *GV = CGM.getModule().getGlobalVariable(Name);
+  if (GV) {
+    assert(GV->getType()->getElementType() == ObjCTypes.ClassTy &&
+           "Forward metaclass reference has incorrect type.");
+    GV->setLinkage(llvm::GlobalValue::InternalLinkage);
+    GV->setInitializer(Init);
+    GV->setSection(Section);
+    GV->setAlignment(4);
+    CGM.AddUsedGlobal(GV);
+  } 
+  else
+    GV = CreateMetadataVar(Name, Init, Section, 4, true);
   DefinedClasses.push_back(GV);
 }
 
@@ -2154,6 +2170,22 @@
   }
 }
 
+llvm::Value *CGObjCMac::EmitSuperClassRef(const ObjCInterfaceDecl *ID) {
+  std::string Name = "\01L_OBJC_CLASS_" + ID->getNameAsString();
+  
+  if (llvm::GlobalVariable *GV = CGM.getModule().getGlobalVariable(Name,
+                                                                   true)) {
+    assert(GV->getType()->getElementType() == ObjCTypes.ClassTy &&
+           "Forward class metadata reference has incorrect type.");
+    return GV;
+  } else {
+    return new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.ClassTy, false,
+                                    llvm::GlobalValue::ExternalLinkage,
+                                    0,
+                                    Name);
+  }
+}
+
 /*
   struct objc_class_ext {
   uint32_t size;

Added: cfe/trunk/test/CodeGenObjC/super-message-fragileabi.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/super-message-fragileabi.m?rev=87017&view=auto

==============================================================================
--- cfe/trunk/test/CodeGenObjC/super-message-fragileabi.m (added)
+++ cfe/trunk/test/CodeGenObjC/super-message-fragileabi.m Thu Nov 12 14:14:24 2009
@@ -0,0 +1,32 @@
+// RUN: clang-cc -triple i386-apple-darwin9 -emit-llvm %s -o - | FileCheck %s
+
+ at class  Some;
+
+ at protocol Proto
+- (id)initSome:(Some *)anArg;
+ at end
+
+
+ at interface Table <Proto>
+ at end
+
+ at interface BetterTable: Table
+
+- (id)initSome:(Some *)arg;
+
+ at end
+
+ at implementation BetterTable
+
+- (id)initSome:(Some *)arg {
+
+ if(self=[super initSome:arg])
+ {
+	;
+ }
+// CHECK: load %struct._objc_class** getelementptr inbounds (%struct._objc_class* @"\01L_OBJC_CLASS_BetterTable", i32 0, i32 1)
+
+ return self;
+}
+ at end
+





More information about the cfe-commits mailing list