This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH: Remove unnecessary ObjC declaration


Whenever an ObjC program declares a class, e.g.,

  @interface Foo
   :
  @end

the compiler currently synthesizes

extern objc_object *_Foo;

which I assume to be an archeological remnant of some sort, since nowhere else does
the compiler reference '_Foo' in any way. In most cases, this bizarre behavior is
harmless, but not if the user decides to declare


int _Foo;

at which point (s)he gets a confusing song-and-dance about conflicting types for '_Foo'.
This patch simply removes the code that synthesizes the '_Foo'; the attached super-class-3.m
test case passes as a result.


Thoughts?

--Zem

[gcc/objc/ChangeLog]
2004-10-25  Ziemowit Laski  <zlaski@apple.com>

        * objc-act.c (finish_class): Do not synthesize bogus
        'extern objc_object *_Foo;' declarations for @interface Foo.

[gcc/testsuite/ChangeLog]
2004-10-25  Ziemowit Laski  <zlaski@apple.com>

* objc.dg/super-class-3.m: New test.

Index: gcc/objc/objc-act.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/objc/objc-act.c,v
retrieving revision 1.251
diff -u -3 -p -r1.251 objc-act.c
--- gcc/objc/objc-act.c 25 Oct 2004 22:55:21 -0000 1.251
+++ gcc/objc/objc-act.c 26 Oct 2004 01:24:05 -0000
@@ -6896,23 +6896,6 @@ finish_class (tree class)
IDENTIFIER_POINTER (CLASS_SUPER_NAME (objc_implementation_context)));
}
}
-
- else if (TREE_CODE (class) == CLASS_INTERFACE_TYPE)
- {
- tree decl;
- const char *class_name = IDENTIFIER_POINTER (CLASS_NAME (class));
- char *string = (char *) alloca (strlen (class_name) + 3);
-
- /* extern struct objc_object *_<my_name>; */
-
- sprintf (string, "_%s", class_name);
-
- decl = build_decl (VAR_DECL, get_identifier (string),
- build_pointer_type (objc_object_reference));
- DECL_EXTERNAL (decl) = 1;
- lang_hooks.decls.pushdecl (decl);
- finish_decl (decl, NULL_TREE, NULL_TREE);
- }
}


static tree
Index: gcc/testsuite/objc.dg/super-class-3.m
===================================================================
RCS file: gcc/testsuite/objc.dg/super-class-3.m
diff -N gcc/testsuite/objc.dg/super-class-3.m
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gcc/testsuite/objc.dg/super-class-3.m 26 Oct 2004 01:24:15 -0000
@@ -0,0 +1,43 @@
+/* Ensure that the compiler does not emit spurious extern declarations named '_Foo', where 'Foo'
+ is an ObjC class name. */
+/* Contributed by Ziemowit Laski <zlaski@apple.com>. */
+/* { dg-do run } */
+
+#include <objc/Object.h>
+#include <stdlib.h>
+#define CHECK_IF(expr) if(!(expr)) abort()
+
+@interface _Child: Object
++ (int) flashCache;
+@end
+
+@interface Child: _Child
++ (int) flushCache1;
+@end
+
+@interface Child (Categ)
++ (int) flushCache2;
+@end
+
+int _Object = 23; /* Should not conflict with @interface Object. */
+
+@implementation _Child
++ (int) flashCache { return 12 + _Object; }
+@end
+
+@implementation Child
++ (int) flushCache1 { return 7 + [super flashCache]; }
+@end
+
+@implementation Child (Categ)
++ (int) flushCache2 { return 9 + [super flashCache]; }
+@end
+
+int main(void) {
+ CHECK_IF([_Child flashCache] == 35);
+ CHECK_IF([Child flushCache1] == 42);
+ CHECK_IF([Child flushCache2] == 44);
+
+ return 0;
+}
+



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]