]> granicus.if.org Git - clang/commitdiff
This patch finalizes implementatin of weak_import
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 17 Nov 2009 22:42:00 +0000 (22:42 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 17 Nov 2009 22:42:00 +0000 (22:42 +0000)
objective-c2 classes (radar 6815425).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89157 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGObjCMac.cpp
test/CodeGenObjC/objc2-weak-import-attribute.m [new file with mode: 0644]

index 2a89620ce9b504a84073f15a7e97bd7f9149f397..4355e66feecd9088451457753ed51151eec22218 100644 (file)
@@ -5243,6 +5243,12 @@ llvm::Value *CGObjCNonFragileABIMac::EmitMetaClassRef(CGBuilderTy &Builder,
 /// 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);
 }
 
diff --git a/test/CodeGenObjC/objc2-weak-import-attribute.m b/test/CodeGenObjC/objc2-weak-import-attribute.m
new file mode 100644 (file)
index 0000000..4a5f14e
--- /dev/null
@@ -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 
+@end
+
+@interface MySubclass : WeakClass @end
+
+@implementation MySubclass @end
+
+@implementation WeakClass(MyCategory) @end
+
+
+__attribute__((weak_import))
+@interface WeakClass1 @end
+
+@implementation WeakClass1(MyCategory) @end
+
+@implementation WeakClass1(YourCategory) @end
+
+ __attribute__((weak_import))
+@interface WeakClass3 
++ message;
+@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
+
+