From patchwork Tue Oct 19 20:34:14 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Pero X-Patchwork-Id: 68379 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 0A011B70DE for ; Wed, 20 Oct 2010 07:34:31 +1100 (EST) Received: (qmail 13906 invoked by alias); 19 Oct 2010 20:34:29 -0000 Received: (qmail 13156 invoked by uid 22791); 19 Oct 2010 20:34:27 -0000 X-SWARE-Spam-Status: No, hits=-1.1 required=5.0 tests=AWL, BAYES_00, SARE_SUB_ENC_UTF8, TW_BJ, TW_JC, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from fencepost.gnu.org (HELO fencepost.gnu.org) (140.186.70.10) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 19 Oct 2010 20:34:20 +0000 Received: from eggs.gnu.org ([140.186.70.92]:40000) by fencepost.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1P8Isz-0000W1-MS for gcc-patches@gnu.org; Tue, 19 Oct 2010 16:34:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P8Isw-00026b-UB for gcc-patches@gnu.org; Tue, 19 Oct 2010 16:34:17 -0400 Received: from smtp171.iad.emailsrvr.com ([207.97.245.171]:37397) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P8Isw-00026X-Pd for gcc-patches@gnu.org; Tue, 19 Oct 2010 16:34:14 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp47.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id 301503A8BA4 for ; Tue, 19 Oct 2010 16:34:14 -0400 (EDT) Received: from dynamic1.wm-web.iad.mlsrvr.com (dynamic1.wm-web.iad1a.rsapps.net [192.168.2.150]) by smtp47.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id 1D3A93A839A for ; Tue, 19 Oct 2010 16:34:14 -0400 (EDT) Received: from meta-innovation.com (localhost [127.0.0.1]) by dynamic1.wm-web.iad.mlsrvr.com (Postfix) with ESMTP id 0DB8CC98070 for ; Tue, 19 Oct 2010 16:34:14 -0400 (EDT) Received: by www2.webmail.us (Authenticated sender: nicola.pero@meta-innovation.com, from: nicola.pero@meta-innovation.com) with HTTP; Tue, 19 Oct 2010 22:34:14 +0200 (CEST) Date: Tue, 19 Oct 2010 22:34:14 +0200 (CEST) Subject: =?UTF-8?Q?Update=20ObjC/ObjC++=20objc=5Ffinish=5Ffile=20to=20become=20ob?= =?UTF-8?Q?jc=5Fwrite=5Fglobal=5Fdeclarations?= From: "Nicola Pero" To: "gcc-patches@gnu.org" MIME-Version: 1.0 X-Type: plain Message-ID: <1287520454.04951779@192.168.2.229> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org This patch updates Objective-C / Objective-C++ to move away from finish_file and use the new LANG_HOOKS_WRITE_GLOBALS (c_write_global_declarations / cp_write_global_declarations). It is good in itself, but it is also required to fix the included Objective-C++ testcase (template-8.mm). :-) That testcase comes from the FSF apple/trunk, and it seems an important testcase to fix (it is a simple Objective-C method call inside a C++ template destructor). Unfortunately the fix in the apple/trunk branch is to make sure cp_finish_file() is called before objc_finish_file(), but we no longer have cp_finish_file() in trunk; we now have cp_write_global_declarations, which is guaranteed to be called *after* any finish_file. ;-) This patch fixes it by updating Objective-C / Objective-C++ to move away from finish_file and to blend in the new c_write_global_declarations / cp_write_global_declarations framework so that we can place calls to objc_finish_file, now renamed to objc_write_global_declarations, at exactly the right time. And as Objective-C / Objective-C++ seemed to be the only remaining user of finish_file for C languages, I was also able to remove finish_file after updating Objective-C / Objective-C++ to use the new write global declarations. :-) No regressions, and the new testcase now passes. Any comments or suggestions welcome. Else, Ok to apply to trunk ? Thanks In gcc/: 2010-10-19 Nicola Pero * c-decl.c (c_write_global_declarations): Call objc_write_global_declarations when compiling Objective-C. * c-lang.c (finish_file): Removed. In gcc/c-family/: 2010-10-19 Nicola Pero * c-common.h (finish_file): Removed. (objc_write_global_declarations): New. * c-opts.c (c_common_parse_file): Do not call finish_file. * stub-objc.c (objc_write_global_declarations): New. In gcc/cp/: 2010-10-19 Nicola Pero * cp-lang.c (finish_file): Removed. * decl2.c (cp_write_global_declarations): Call objc_write_global_declarations when compiling Objective-C++. In gcc/objc/: 2010-10-19 Nicola Pero * objc-lang.c (finish_file): Removed. * objc-act.c (objc_finish_file): Renamed to objc_write_global_declarations. Do not try to instantiate C++ templates when compiling Objective-C++ as this is now automatically done before this function is called. Do not check for syntax-only run or PCH generation as this is done by the callers. * objc-act.h (objc_finish_file): Removed. In gcc/objcp/: 2010-10-19 Nicola Pero * objcp-lang.c (finish_file): Removed. In gcc/testsuite/: 2010-10-19 Nicola Pero Merge from 'apple/trunk' branch on FSF servers. Test adapted to not require Foundation and run with the GNU runtime as well. 2006-03-13 Fariborz Jahanian Radar 4439126 * obj-c++.dg/template-8.mm: New. Index: gcc/c-family/c-opts.c =================================================================== --- gcc/c-family/c-opts.c (revision 165694) +++ gcc/c-family/c-opts.c (working copy) @@ -1160,7 +1160,6 @@ c_common_parse_file (int set_yydebug) pch_init (); push_file_scope (); c_parse_file (); - finish_file (); pop_file_scope (); /* And end the main input file, if the debug writer wants it */ if (debug_hooks->start_end_main_source_file) Index: gcc/c-family/ChangeLog =================================================================== --- gcc/c-family/ChangeLog (revision 165694) +++ gcc/c-family/ChangeLog (working copy) @@ -1,3 +1,10 @@ +2010-10-19 Nicola Pero + + * c-common.h (finish_file): Removed. + (objc_write_global_declarations): New. + * c-opts.c (c_common_parse_file): Do not call finish_file. + * stub-objc.c (objc_write_global_declarations): New. + 2010-10-18 Nicola Pero Implemented parsing @synthesize and @dynamic for Index: gcc/c-family/c-common.h =================================================================== --- gcc/c-family/c-common.h (revision 165694) +++ gcc/c-family/c-common.h (working copy) @@ -788,8 +788,6 @@ extern HOST_WIDE_INT c_common_to_target_charset (H /* This is the basic parsing function. */ extern void c_parse_file (void); -/* This is misnamed, it actually performs end-of-compilation processing. */ -extern void finish_file (void); extern void warn_for_omitted_condop (location_t, tree); @@ -981,6 +979,7 @@ extern void c_parse_error (const char *, enum cpp_ /* The following ObjC/ObjC++ functions are called by the C and/or C++ front-ends; they all must have corresponding stubs in stub-objc.c. */ +extern void objc_write_global_declarations (void); extern tree objc_is_class_name (tree); extern tree objc_is_object_ptr (tree); extern void objc_check_decl (tree); Index: gcc/c-family/stub-objc.c =================================================================== --- gcc/c-family/stub-objc.c (revision 165694) +++ gcc/c-family/stub-objc.c (working copy) @@ -416,3 +416,8 @@ objc_finish_foreach_loop (location_t ARG_UNUSED (l { return; } + +void +objc_write_global_declarations (void) +{ +} Index: gcc/objc/objc-act.c =================================================================== --- gcc/objc/objc-act.c (revision 165694) +++ gcc/objc/objc-act.c (working copy) @@ -624,23 +624,16 @@ objc_init (void) return true; } +/* This is called automatically (at the very end of compilation) by + c_write_global_declarations and cp_write_global_declarations. */ void -objc_finish_file (void) +objc_write_global_declarations (void) { mark_referenced_methods (); -#ifdef OBJCPLUS - /* We need to instantiate templates _before_ we emit ObjC metadata; - if we do not, some metadata (such as selectors) may go missing. */ - at_eof = 1; - instantiate_pending_templates (0); -#endif + /* Finalize Objective-C runtime data. */ + finish_objc (); - /* Finalize Objective-C runtime data. No need to generate tables - and code if only checking syntax, or if generating a PCH file. */ - if (!flag_syntax_only && !pch_file) - finish_objc (); - if (gen_declaration_file) fclose (gen_declaration_file); } Index: gcc/objc/ChangeLog =================================================================== --- gcc/objc/ChangeLog (revision 165694) +++ gcc/objc/ChangeLog (working copy) @@ -1,3 +1,14 @@ +2010-10-19 Nicola Pero + + * objc-lang.c (finish_file): Removed. + * objc-act.c (objc_finish_file): Renamed to + objc_write_global_declarations. Do not try to instantiate C++ + templates when compiling Objective-C++ as this is now + automatically done before this function is called. Do not check + for syntax-only run or PCH generation as this is done by the + callers. + * objc-act.h (objc_finish_file): Removed. + 2010-10-18 Nicola Pero Implemented parsing @synthesize and @dynamic for Index: gcc/objc/objc-act.h =================================================================== --- gcc/objc/objc-act.h (revision 165694) +++ gcc/objc/objc-act.h (working copy) @@ -26,7 +26,6 @@ along with GCC; see the file COPYING3. If not see bool objc_init (void); const char *objc_printable_name (tree, int); -void objc_finish_file (void); tree objc_fold_obj_type_ref (tree, tree); int objc_gimplify_expr (tree *, gimple_seq *, gimple_seq *); tree objc_eh_runtime_type (tree); Index: gcc/objc/objc-lang.c =================================================================== --- gcc/objc/objc-lang.c (revision 165694) +++ gcc/objc/objc-lang.c (working copy) @@ -92,10 +92,4 @@ objc_init_ts (void) tree_contains_struct[PROPERTY_DECL][TS_DECL_COMMON] = 1; } -void -finish_file (void) -{ - objc_finish_file (); -} - #include "gtype-objc.h" Index: gcc/ChangeLog =================================================================== --- gcc/ChangeLog (revision 165694) +++ gcc/ChangeLog (working copy) @@ -1,3 +1,9 @@ +2010-10-19 Nicola Pero + + * c-decl.c (c_write_global_declarations): Call + objc_write_global_declarations when compiling Objective-C. + * c-lang.c (finish_file): Removed. + 2010-10-19 Nick Clifton * config/rx/rx.c (rx_function_value): Small integer types are Index: gcc/testsuite/ChangeLog =================================================================== --- gcc/testsuite/ChangeLog (revision 165694) +++ gcc/testsuite/ChangeLog (working copy) @@ -1,3 +1,13 @@ +2010-10-19 Nicola Pero + + Merge from 'apple/trunk' branch on FSF servers. Test adapted to + not require Foundation and run with the GNU runtime as well. + + 2006-03-13 Fariborz Jahanian + + Radar 4439126 + * obj-c++.dg/template-8.mm: New. + 2010-10-18 Nicola Pero Merge from 'apple/trunk' branch on FSF servers. Index: gcc/testsuite/obj-c++.dg/template-8.mm =================================================================== --- gcc/testsuite/obj-c++.dg/template-8.mm (revision 0) +++ gcc/testsuite/obj-c++.dg/template-8.mm (revision 0) @@ -0,0 +1,49 @@ +/* Test that all pending instantiations have taken place before meta-data + generation. */ +/* Author: Fariborz Jahanian */ +/* Adapted by Nicola Pero */ +/* { dg-do run } */ + +#include +#include + +@interface MyRootClass +{ Class isa; } ++ alloc; +- init; +- doSomething; +@end + +@implementation MyRootClass ++ alloc { return class_createInstance (self, 0); } +- init { return self; } +- doSomething { return self; } +@end + +class Base +{ +public: + Base() { } + virtual ~Base() { } + + void destroy() { delete this; } +}; + +template +class Subclass : public T +{ +public: + Subclass() { } + + virtual ~Subclass() + { + [[[MyRootClass alloc] init] doSomething]; + } +}; + +int main(int argc, const char * argv[]) +{ + Subclass* theSubclass = new Subclass(); + theSubclass->destroy(); + return 0; +} Index: gcc/objcp/ChangeLog =================================================================== --- gcc/objcp/ChangeLog (revision 165694) +++ gcc/objcp/ChangeLog (working copy) @@ -1,3 +1,7 @@ +2010-10-19 Nicola Pero + + * objcp-lang.c (finish_file): Removed. + 2010-10-14 Iain Sandoe merge from FSF apple 'trunk' branch. Index: gcc/objcp/objcp-lang.c =================================================================== --- gcc/objcp/objcp-lang.c (revision 165694) +++ gcc/objcp/objcp-lang.c (working copy) @@ -156,11 +156,4 @@ objcxx_eh_personality (void) return objcp_eh_personality_decl; } - -void -finish_file (void) -{ - objc_finish_file (); -} - #include "gtype-objcp.h" Index: gcc/cp/ChangeLog =================================================================== --- gcc/cp/ChangeLog (revision 165694) +++ gcc/cp/ChangeLog (working copy) @@ -1,3 +1,9 @@ +2010-10-19 Nicola Pero + + * cp-lang.c (finish_file): Removed. + * decl2.c (cp_write_global_declarations): Call + objc_write_global_declarations when compiling Objective-C++. + 2010-10-18 Nicola Pero Implemented parsing @synthesize and @dynamic for Objective-C++. Index: gcc/cp/cp-lang.c =================================================================== --- gcc/cp/cp-lang.c (revision 165694) +++ gcc/cp/cp-lang.c (working copy) @@ -154,11 +154,6 @@ cp_classify_record (tree type) return RECORD_IS_STRUCT; } -void -finish_file (void) -{ -} - static GTY(()) tree cp_eh_personality_decl; static tree Index: gcc/cp/decl2.c =================================================================== --- gcc/cp/decl2.c (revision 165694) +++ gcc/cp/decl2.c (working copy) @@ -3896,6 +3896,14 @@ cp_write_global_declarations (void) if (!decl_defined_p (decl)) no_linkage_error (decl); + /* Then, do the Objective-C stuff. This is where all the + Objective-C module stuff gets generated (symtab, + class/protocol/selector lists etc). This must be done after C++ + templates, destructors etc. so that selectors used in C++ + templates are properly allocated. */ + if (c_dialect_objc ()) + objc_write_global_declarations (); + /* We give C linkage to static constructors and destructors. */ push_lang_context (lang_name_c); Index: gcc/c-decl.c =================================================================== --- gcc/c-decl.c (revision 165694) +++ gcc/c-decl.c (working copy) @@ -9782,6 +9782,12 @@ c_write_global_declarations (void) if (pch_file) return; + /* Do the Objective-C stuff. This is where all the Objective-C + module stuff gets generated (symtab, class/protocol/selector + lists etc). */ + if (c_dialect_objc ()) + objc_write_global_declarations (); + /* Close the external scope. */ ext_block = pop_scope (); external_scope = 0; Index: gcc/c-lang.c =================================================================== --- gcc/c-lang.c (revision 165694) +++ gcc/c-lang.c (working copy) @@ -47,11 +47,4 @@ enum c_language_kind c_language = clk_c; /* Each front end provides its own lang hook initializer. */ struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER; -/* Final processing of file-scope data. The Objective-C version of - this function still does something. */ -void -finish_file (void) -{ -} - #include "gtype-c.h"