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: Fix lossage of protocols attached to forward-declared ObjC classes


Someone discovered this in Apple's compiler, but it turns out the FSF
tree has the same bug. If you compile the attached objc.dg/proto-lossage-5.m
testcase without the patch applied, you'll get a mysterious


gcc/testsuite/objc.dg/proto-lossage-5.m: In function '-[MyClassThatFails aMethod]':
gcc/testsuite/objc.dg/proto-lossage-5.m:19: warning: conflicting types for '-(MyBaseClass <_MyProtocol> *)aMethod'
gcc/testsuite/objc.dg/proto-lossage-5.m:8: warning: previous declaration of '-(MyBaseClass *)aMethod'


The problem is that finish_struct() clobbers the lang-specific information for all the variants of a RECORD_TYPE;
since I think it is entitled to do this, I basically save and then restore the ObjC portions of the lang-specific
stuff in objc-act.c:objc_build_struct().


I shall now do a bootstrap; if all goes well (and no one points out a fatal flaw with my patch :-)) I'll commit this
to mainline.


--Zem

[gcc/objc/ChangeLog]
2005-06-27  Ziemowit Laski  <zlaski@apple.com>

        * objc-act.c (objc_build_struct): Save the TYPE_OBJC_INFO
        portion of TYPE_LANG_SPECIFIC info for all variants of
        a class before calling finish_struct(), and restore
        same TYPE_OBJC_INFO afterwards.

[gcc/testsuite/ChangeLog]
2005-06-27  Ziemowit Laski  <zlaski@apple.com>

        * obj-c++.dg/proto-lossage-5.mm: New.
        * objc.dg/proto-lossage-5.m: New.

Index: gcc/objc/objc-act.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/objc/objc-act.c,v
retrieving revision 1.278
diff -u -3 -p -r1.278 objc-act.c
--- gcc/objc/objc-act.c 25 Jun 2005 00:30:48 -0000 1.278
+++ gcc/objc/objc-act.c 27 Jun 2005 19:56:37 -0000
@@ -801,6 +801,7 @@ objc_build_struct (tree name, tree field
{
tree s = start_struct (RECORD_TYPE, name);
tree super = (super_name ? xref_tag (RECORD_TYPE, super_name) : NULL_TREE);
+ tree t, objc_info = NULL_TREE;


   if (super)
     {
@@ -844,8 +845,23 @@ objc_build_struct (tree name, tree field
       fields = base;
     }

+ /* NB: Calling finish_struct() may cause type TYPE_LANG_SPECIFIC fields
+ in all variants of this RECORD_TYPE to be clobbered, but it is therein
+ that we store protocol conformance info (e.g., 'NSObject <MyProtocol>').
+ Hence, we must squirrel away the ObjC-specific information before calling
+ finish_struct(), and then reinstate it afterwards. */
+
+ for (t = TYPE_NEXT_VARIANT (s); t; t = TYPE_NEXT_VARIANT (t))
+ objc_info
+ = chainon (objc_info,
+ build_tree_list (NULL_TREE, TYPE_OBJC_INFO (t)));
+
s = finish_struct (s, fields, NULL_TREE);


+  for (t = TYPE_NEXT_VARIANT (s); t;
+       t = TYPE_NEXT_VARIANT (t), objc_info = TREE_CHAIN (objc_info))
+    TYPE_OBJC_INFO (t) = TREE_VALUE (objc_info);
+
   /* Use TYPE_BINFO structures to point at the super class, if any.  */
   objc_xref_basetypes (s, super);

Index: gcc/testsuite/obj-c++.dg/proto-lossage-5.mm
===================================================================
RCS file: gcc/testsuite/obj-c++.dg/proto-lossage-5.mm
diff -N gcc/testsuite/obj-c++.dg/proto-lossage-5.mm
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gcc/testsuite/obj-c++.dg/proto-lossage-5.mm 27 Jun 2005 19:56:41 -0000
@@ -0,0 +1,22 @@
+/* Do not lose references to forward-declared protocols. */
+/* { dg-do compile } */
+@class MyBaseClass;
+@class MyClassThatFails;
+@protocol _MyProtocol;
+
+@interface MyClassThatFails
+- (MyBaseClass<_MyProtocol> *) aMethod;
+@end
+
+@interface MyBaseClass
+@end
+
+@protocol _MyProtocol
+@end
+
+@implementation MyClassThatFails
+- (MyBaseClass<_MyProtocol> *) aMethod
+{
+ return 0;
+}
+@end
Index: gcc/testsuite/objc.dg/proto-lossage-5.m
===================================================================
RCS file: gcc/testsuite/objc.dg/proto-lossage-5.m
diff -N gcc/testsuite/objc.dg/proto-lossage-5.m
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gcc/testsuite/objc.dg/proto-lossage-5.m 27 Jun 2005 19:56:41 -0000
@@ -0,0 +1,22 @@
+/* Do not lose references to forward-declared protocols. */
+/* { dg-do compile } */
+@class MyBaseClass;
+@class MyClassThatFails;
+@protocol _MyProtocol;
+
+@interface MyClassThatFails
+- (MyBaseClass<_MyProtocol> *) aMethod;
+@end
+
+@interface MyBaseClass
+@end
+
+@protocol _MyProtocol
+@end
+
+@implementation MyClassThatFails
+- (MyBaseClass<_MyProtocol> *) aMethod
+{
+ return 0;
+}
+@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


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