[cfe-commits] r89157 - in /cfe/trunk: lib/CodeGen/CGObjCMac.cpp test/CodeGenObjC/objc2-weak-import-attribute.m

Fariborz Jahanian fjahanian at apple.com
Tue Nov 17 14:42:00 PST 2009


Author: fjahanian
Date: Tue Nov 17 16:42:00 2009
New Revision: 89157

URL: http://llvm.org/viewvc/llvm-project?rev=89157&view=rev
Log:
This patch finalizes implementatin of weak_import
objective-c2 classes (radar 6815425).

Added:
    cfe/trunk/test/CodeGenObjC/objc2-weak-import-attribute.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=89157&r1=89156&r2=89157&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Tue Nov 17 16:42:00 2009
@@ -5243,6 +5243,12 @@
 /// decl.
 llvm::Value *CGObjCNonFragileABIMac::GetClass(CGBuilderTy &Builder,
                                               const ObjCInterfaceDecl *ID) {
+  if (ID->hasAttr<WeakImportAttr>()) {
+    std::string ClassName(getClassSymbolPrefix() + ID->getNameAsString());
+    llvm::GlobalVariable *ClassGV = GetClassGlobal(ClassName);
+    ClassGV->setLinkage(llvm::GlobalValue::ExternalWeakLinkage);
+  }
+  
   return EmitClassRef(Builder, ID);
 }
 

Added: cfe/trunk/test/CodeGenObjC/objc2-weak-import-attribute.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/objc2-weak-import-attribute.m?rev=89157&view=auto

==============================================================================
--- cfe/trunk/test/CodeGenObjC/objc2-weak-import-attribute.m (added)
+++ cfe/trunk/test/CodeGenObjC/objc2-weak-import-attribute.m Tue Nov 17 16:42:00 2009
@@ -0,0 +1,34 @@
+// RUN: clang-cc -fobjc-nonfragile-abi -triple x86_64-apple-darwin10 -emit-llvm -o - %s | FileCheck -check-prefix=CHECK-X86-64 %s
+
+__attribute__((weak_import)) @interface WeakClass 
+ at end
+
+ at interface MySubclass : WeakClass @end
+
+ at implementation MySubclass @end
+
+ at implementation WeakClass(MyCategory) @end
+
+
+__attribute__((weak_import))
+ at interface WeakClass1 @end
+
+ at implementation WeakClass1(MyCategory) @end
+
+ at implementation WeakClass1(YourCategory) @end
+
+ __attribute__((weak_import))
+ at interface WeakClass3 
++ message;
+ at end
+
+int main() {
+     [WeakClass3 message];
+}
+
+// CHECK-X86-64: OBJC_METACLASS_$_WeakClass" = extern_weak global
+// CHECK-X86-64: OBJC_CLASS_$_WeakClass" = extern_weak global
+// CHECK-X86-64: OBJC_CLASS_$_WeakClass1" = extern_weak global
+// CHECK-X86-64: OBJC_CLASS_$_WeakClass3" = extern_weak global
+
+





More information about the cfe-commits mailing list