PING: PATCH: Calling super from class methods of categories

Ziemowit Laski zlaski@apple.com
Mon Aug 26 11:51:00 GMT 2002


I posted this on Friday, and since then the compiler did
in fact bootstrap with no regressions.  Since I would argue
this is a bug fix rather than a new feature, is it OK for
me to commit this to TOT?

Thanks,

--Zem

======================================================================== 
=========
This Objective-C patch addresses a problem with sending
a message to the super meta-class from a category method (see
test case below).  The compiler is attempting to send the
message to the 'isa' field of struct objc_class; unfortunately,
the layout of struct objc_class is not known to the compiler
unless the <objc/objc-class.h> header is included in addition
to <objc/objc.h>.  Since every Objective-C object begins with
the 'isa' field, we therefore simply cast the metaclass object
to 'id' and access the 'isa' pointer that way.

Currently bootstrapping on i686-pc-linux-gnu.  Ok for TOT
if no regressions are found?

[gcc]
2002-08-23  Ziemowit Laski <zlaski@apple.com>

         * objc/objc-act.c (get_super_receiver): If inside a class method
         of a category, cast the receiver to 'id' before accessing the  
'isa'
         field so that <objc/objc-class.h> is not needed.  NeXT runtime.

[gcc/testsuite]
2002-08-23  Ziemowit Laski  <zlaski@apple.com>

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


Index: gcc/objc/objc-act.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/objc/objc-act.c,v
retrieving revision 1.152
diff -c -3 -p -r1.152 objc-act.c
*** gcc/objc/objc-act.c 20 Aug 2002 01:51:13 -0000      1.152
--- gcc/objc/objc-act.c 24 Aug 2002 01:40:43 -0000
*************** get_super_receiver ()
*** 7042,7050 ****
             {
               super_class = get_class_reference (super_name);
               if (TREE_CODE (objc_method_context) == CLASS_METHOD_DECL)
                 super_class
!                 = build_component_ref (build_indirect_ref  
(super_class, "->"),
!                                        get_identifier ("isa"));
             }
           else
             {
--- 7042,7054 ----
             {
               super_class = get_class_reference (super_name);
               if (TREE_CODE (objc_method_context) == CLASS_METHOD_DECL)
+               /* Cast the super class to 'id', since the user may not  
have
+                  included <objc/objc-class.h>, leaving 'struct  
objc_class'
+                  an incomplete type.  */
                 super_class
!                 = build_component_ref (build_indirect_ref
!                                        (build_c_cast (id_type,  
super_class), "->"),
!                                         get_identifier ("isa"));
             }
           else
             {
Index: gcc/testsuite/objc.dg/super-class-2.m
===================================================================
RCS file: gcc/testsuite/objc.dg/super-class-2.m
diff -N gcc/testsuite/objc.dg/super-class-2.m
*** /dev/null   1 Jan 1970 00:00:00 -0000
--- gcc/testsuite/objc.dg/super-class-2.m       24 Aug 2002 01:40:44  
-0000
***************
*** 0 ****
--- 1,46 ----
+ /* Test calling super from within a category class method.  */
+ /* Author: Ziemowit Laski <zlaski@apple.com>  */
+ /* { dg-do compile } */
+ /* { dg-options "-fnext-runtime" } */
+
+ typedef struct objc_object { struct objc_class *isa; } *id;
+
+ @interface NSObject
+ + (int) test_func0;
+ @end
+ @interface NSMenuItem: NSObject
+ + (int) test_func0;
+ @end
+
+ @implementation NSObject
+ + (int) test_func0
+ {}
+ @end
+
+ @implementation NSMenuItem
+ + (int) test_func0
+ {
+   return [super test_func0];
+ }
+ @end
+
+ @interface NSObject (Test)
+ + (int) test_func;
+ @end
+
+ @implementation NSObject (Test)
+ + (int) test_func
+ {}
+ @end
+
+ @interface NSMenuItem (Test)
+ + (int) test_func;
+ @end
+
+ @implementation NSMenuItem (Test)
+ + (int) test_func
+ {
+    return [super test_func];  /* { dg-bogus "dereferencing pointer to  
incomplete type" } */
+ }
+ @end
+

--------------------------------------------------------------
Ziemowit Laski                 1 Infinite Loop, MS 301-2K
Mac OS X Compiler Group        Cupertino, CA USA  95014-2083
Apple Computer, Inc.           +1.408.974.6229  Fax .5477



More information about the Gcc-patches mailing list