[llvm-commits] [llvm-gcc-4.2] r101804 - in /llvm-gcc-4.2/trunk/gcc: objc/objc-act.c testsuite/objc.dg/weak_import_class.m
Stuart Hastings
stuart at apple.com
Mon Apr 19 12:13:10 PDT 2010
Author: stuart
Date: Mon Apr 19 14:13:10 2010
New Revision: 101804
URL: http://llvm.org/viewvc/llvm-project?rev=101804&view=rev
Log:
Support weak_import for Objective-C classes. Radar 7865106. Patch by Fariborz Jahanian!
Added:
llvm-gcc-4.2/trunk/gcc/testsuite/objc.dg/weak_import_class.m
Modified:
llvm-gcc-4.2/trunk/gcc/objc/objc-act.c
Modified: llvm-gcc-4.2/trunk/gcc/objc/objc-act.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/objc/objc-act.c?rev=101804&r1=101803&r2=101804&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/objc/objc-act.c (original)
+++ llvm-gcc-4.2/trunk/gcc/objc/objc-act.c Mon Apr 19 14:13:10 2010
@@ -924,6 +924,28 @@
return 0;
}
+/* APPLE LOCAL begin radar 7865106 */
+static bool objc_class_weak_import(tree class)
+{
+ tree chain;
+ gcc_assert (class && TREE_CODE (class) == CLASS_INTERFACE_TYPE);
+ for (chain = CLASS_ATTRIBUTES (class); chain; chain = TREE_CHAIN (chain))
+ if (is_attribute_p ("weak_import", TREE_PURPOSE (chain)))
+ return true;
+ return false;
+}
+
+static char*
+objc_build_weak_reference_internal_classname (tree ident, bool metaclass)
+{
+ static char string[BUFSIZE];
+ sprintf (string, ".weak_reference %s_%s", !metaclass ? "_OBJC_CLASS_$"
+ : "_OBJC_METACLASS_$",
+ IDENTIFIER_POINTER (ident));
+ return string;
+}
+/* APPLE LOCAL end radar 7865106 */
+
void
/* APPLE LOCAL radar 4548636 */
objc_start_class_interface (tree class, tree super_class, tree protos, tree attributes)
@@ -935,6 +957,17 @@
CLASS_ATTRIBUTES (objc_interface_context) = attributes;
objc_warn_on_class_attributes (objc_interface_context, false);
/* APPLE LOCAL end radar 4548636 */
+ /* APPLE LOCAL begin radar 7865106 */
+ if (flag_objc_abi == 2 && objc_class_weak_import(objc_interface_context)) {
+ const char * name =
+ objc_build_weak_reference_internal_classname(CLASS_NAME(objc_interface_context) , 0);
+ tree asm_str = build_string(strlen(name), name);
+ cgraph_add_asm_node(asm_str);
+ name = objc_build_weak_reference_internal_classname(CLASS_NAME(objc_interface_context) , 1);
+ asm_str = build_string(strlen(name), name);
+ cgraph_add_asm_node(asm_str);
+ }
+ /* APPLE LOCAL end radar 7865106 */
objc_public_flag = 0;
}
@@ -15175,6 +15208,10 @@
else if (is_attribute_p ("objc_exception", TREE_PURPOSE (chain)))
;
/* APPLE LOCAL end radar 5008110 */
+ /* APPLE LOCAL begin radar 7865106 */
+ else if (is_attribute_p ("weak_import", TREE_PURPOSE (chain)))
+ ;
+ /* APPLE LOCAL end radar 7865106 */
else if (!use)
warning (0, "attribute %s is unknown - ignored",
IDENTIFIER_POINTER (TREE_PURPOSE (chain)));
Added: llvm-gcc-4.2/trunk/gcc/testsuite/objc.dg/weak_import_class.m
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/testsuite/objc.dg/weak_import_class.m?rev=101804&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/testsuite/objc.dg/weak_import_class.m (added)
+++ llvm-gcc-4.2/trunk/gcc/testsuite/objc.dg/weak_import_class.m Mon Apr 19 14:13:10 2010
@@ -0,0 +1,29 @@
+/* APPLE LOCAL file radar 7865106 */
+/* { dg-do compile { target *-*-darwin* } } */
+/* { dg-options "-mmacosx-version-min=10.6 -fobjc-abi-version=2" { target i?86*-*-darwin* } } */
+
+__attribute__((weak_import)) @interface WeakRootClass @end
+ at implementation WeakRootClass @end
+
+
+__attribute__((weak_import)) @interface WeakClass : WeakRootClass @end
+ at implementation WeakClass @end
+
+ at interface MySubclass : WeakClass @end
+ at implementation MySubclass @end
+
+__attribute__((weak_import)) @interface CategoryImplementsThis @end
+ at implementation CategoryImplementsThis(MyCategory) @end
+ at implementation CategoryImplementsThis(YourCategory) @end
+
+ at interface Super : WeakRootClass @end
+ at implementation Super @end
+
+ at interface Sub : Super @end
+ at implementation Sub @end
+/* { dg-final { scan-assembler ".weak_reference _OBJC_METACLASS_\\\$_WeakClass" } } */
+/* { dg-final { scan-assembler ".weak_reference _OBJC_METACLASS_\\\$_WeakRootClass" } } */
+/* { dg-final { scan-assembler ".weak_reference _OBJC_CLASS_\\\$_WeakRootClass" } } */
+/* { dg-final { scan-assembler ".weak_reference _OBJC_METACLASS_\\\$_WeakRootClass" } } */
+/* { dg-final { scan-assembler ".weak_reference _OBJC_CLASS_\\\$_CategoryImplementsThis" } } */
+/* { dg-final { scan-assembler ".weak_reference _OBJC_METACLASS_\\\$_CategoryImplementsThis" } } */
More information about the llvm-commits
mailing list