From 2aba33dd6f2d9cf16b2c2e25e73071b5e6d4368c Mon Sep 17 00:00:00 2001 From: Ziemowit Laski Date: Tue, 28 Jun 2005 02:01:08 +0000 Subject: [PATCH] objc-act.c (objc_build_struct): Save the TYPE_OBJC_INFO portion of TYPE_LANG_SPECIFIC info for all variants of... [gcc/objc/ChangeLog] 2005-06-27 Ziemowit Laski * 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 * obj-c++.dg/proto-lossage-5.mm: New. * objc.dg/proto-lossage-5.m: New. From-SVN: r101368 --- gcc/objc/ChangeLog | 7 +++++++ gcc/objc/objc-act.c | 16 +++++++++++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/obj-c++.dg/proto-lossage-5.mm | 22 +++++++++++++++++++++ gcc/testsuite/objc.dg/proto-lossage-5.m | 22 +++++++++++++++++++++ 5 files changed, 72 insertions(+) create mode 100644 gcc/testsuite/obj-c++.dg/proto-lossage-5.mm create mode 100644 gcc/testsuite/objc.dg/proto-lossage-5.m diff --git a/gcc/objc/ChangeLog b/gcc/objc/ChangeLog index 04a402b2d3c..57a326ade94 100644 --- a/gcc/objc/ChangeLog +++ b/gcc/objc/ChangeLog @@ -1,3 +1,10 @@ +2005-06-27 Ziemowit Laski + + * 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. + 2005-06-25 Kelley Cook * all files: Update FSF address in copyright headers. diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c index 6c9018181da..35951fea145 100644 --- a/gcc/objc/objc-act.c +++ b/gcc/objc/objc-act.c @@ -801,6 +801,7 @@ objc_build_struct (tree name, tree fields, tree super_name) { 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 fields, tree super_name) 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 '). + 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); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1fab590a607..5c4b635a4bf 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2005-06-27 Ziemowit Laski + + * obj-c++.dg/proto-lossage-5.mm: New. + * objc.dg/proto-lossage-5.m: New. + 2005-06-27 Diego Novillo PR 21959 diff --git a/gcc/testsuite/obj-c++.dg/proto-lossage-5.mm b/gcc/testsuite/obj-c++.dg/proto-lossage-5.mm new file mode 100644 index 00000000000..35c0956ed8e --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/proto-lossage-5.mm @@ -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 diff --git a/gcc/testsuite/objc.dg/proto-lossage-5.m b/gcc/testsuite/objc.dg/proto-lossage-5.m new file mode 100644 index 00000000000..35c0956ed8e --- /dev/null +++ b/gcc/testsuite/objc.dg/proto-lossage-5.m @@ -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 -- 2.30.2