From patchwork Sun Jun 27 20:50:18 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Bosscher X-Patchwork-Id: 57103 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 638E1B6EF2 for ; Mon, 28 Jun 2010 06:50:40 +1000 (EST) Received: (qmail 26435 invoked by alias); 27 Jun 2010 20:50:38 -0000 Received: (qmail 26422 invoked by uid 22791); 27 Jun 2010 20:50:33 -0000 X-SWARE-Spam-Status: No, hits=-0.7 required=5.0 tests=AWL, BAYES_20, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, TW_BJ, TW_CX, TW_JC, TW_TM X-Spam-Check-By: sourceware.org Received: from mail-iw0-f175.google.com (HELO mail-iw0-f175.google.com) (209.85.214.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 27 Jun 2010 20:50:21 +0000 Received: by iwn9 with SMTP id 9so438576iwn.20 for ; Sun, 27 Jun 2010 13:50:19 -0700 (PDT) MIME-Version: 1.0 Received: by 10.231.121.15 with SMTP id f15mr4410730ibr.171.1277671818928; Sun, 27 Jun 2010 13:50:18 -0700 (PDT) Received: by 10.231.207.83 with HTTP; Sun, 27 Jun 2010 13:50:18 -0700 (PDT) Date: Sun, 27 Jun 2010 22:50:18 +0200 Message-ID: Subject: [patch] Banish except.h from the front ends From: Steven Bosscher To: GCC Patches , Diego Novillo 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 Hello, The implementation of exception handling is a middle-end thing, so front ends do not need to know about anything defined in except.h. Well, almost nothing: init_eh and init_eh_for_function are called from front ends (esp. init_eh for Ada and LTO) because not all front ends let toplev initialize EH handling. This makes sense because a front end may not know at the start of the compilation of a file whether EH will be needed or not (and in Ada: what kind of EH). Bootstrapped on x86_64-unknown-linux-gnu all languages except java, which does not build for me, without the patch or with. OK for trunk? Ciao! Steven gcc/ChangeLog: * system.h: Poison GCC_EXCEPT_H for front-end files. * langhooks.h (struct lang_hooks): Add eh_protect_cleanup_actions langhook. * langhooks-def.h (LANG_HOOKS_EH_PROTECT_CLEANUP_ACTIONS) New. Define to NULL by default. * except.h: Define GCC_EXCEPT_H. (doing_eh): Remove prototype. (init_eh, init_eh_for_function): Move prototypes to toplev.h. (lang_protect_cleanup_actions): Remove. * except.c (lang_protect_cleanup_actions): Remove. (doing_eh): Remove. (gen_eh_region): Don't check doing_eh here. * toplev.h (init_eh, init_eh_for_function_): Moved from except.h. * tree-eh.c (honor_protect_cleanup_actions): Use new langhook instead of lang_protect_cleanup_actions. * omp-low.c (maybe_catch_exception): Likewise. gcc/c-family/ChangeLog: * c-cppbuiltin.c: Do not include except.h. gcc/objc/ChangeLog: * objc-act.c: Do not include except.h. gcc/cp/ChangeLog: * init.c: Do not include except.h. * decl.c: Likewise. * expr.c: Likewise. * cp-lang.c: Likewise. * pt.c: Likewise. * semantics.c: Likewise. * decl2.c: Likewise. * except.c: Likewise. (init_exception_processing): Do not set the removed lang_protect_cleanup_actions here. (cp_protect_cleanup_actions): Make non-static and remove prototype. (doing_eh): New, moved from except.c but removed the do_warning flag. (expand_start_catch_block): Update doing_eh call. (expand_end_catch_block): Likewise. (build_throw): Likewise. * cp-tree.h: Prototype cp_protect_cleanup_actions. * cp-objcp-common.h: Set LANG_HOOKS_EH_PROTECT_CLEANUP_ACTIONS to cp_protect_cleanup_actions. gcc/objcp/ChangeLog: * objcp-lang.c: Do not include except.h. gcc/java/ChangeLog: * lang.c: Do not include except.h * except.c: Likewise. (doing_eh): New, moved from except.c (in gcc/) but removed the do_warning flag. (maybe_start_try): Update doing_eh call. Index: system.h =================================================================== --- system.h (revision 161470) +++ system.h (working copy) @@ -799,7 +799,7 @@ extern void fancy_abort (const char *, int, const /* Front ends should never have to include middle-end headers. Enforce this by poisoning the header double-include protection defines. */ #ifdef IN_GCC_FRONTEND -#pragma GCC poison GCC_RTL_H +#pragma GCC poison GCC_RTL_H GCC_EXCEPT_H #endif /* Note: not all uses of the `index' token (e.g. variable names and Index: langhooks.h =================================================================== --- langhooks.h (revision 161470) +++ langhooks.h (working copy) @@ -446,6 +446,14 @@ struct lang_hooks /* Map a type to a runtime object to match type. */ tree (*eh_runtime_type) (tree); + /* If non-NULL, this is a function that returns a function decl to be + executed if an unhandled exception is propagated out of a cleanup + region. For example, in C++, an exception thrown by a destructor + during stack unwinding is required to result in a call to + `std::terminate', so the C++ version of this function returns a + FUNCTION_DECL for `std::terminate'. */ + tree (*eh_protect_cleanup_actions) (void); + /* True if this language uses __cxa_end_cleanup when the ARM EABI is enabled. */ bool eh_use_cxa_end_cleanup; Index: langhooks-def.h =================================================================== --- langhooks-def.h (revision 161470) +++ langhooks-def.h (working copy) @@ -110,6 +110,7 @@ extern void lhd_omp_firstprivatize_type_sizes (str #define LANG_HOOKS_INIT_TS lhd_do_nothing #define LANG_HOOKS_EH_PERSONALITY lhd_gcc_personality #define LANG_HOOKS_EH_RUNTIME_TYPE lhd_pass_through_t +#define LANG_HOOKS_EH_PROTECT_CLEANUP_ACTIONS NULL #define LANG_HOOKS_EH_USE_CXA_END_CLEANUP false #define LANG_HOOKS_DEEP_UNSHARING false @@ -299,6 +300,7 @@ extern void lhd_end_section (void); LANG_HOOKS_EXPR_TO_DECL, \ LANG_HOOKS_EH_PERSONALITY, \ LANG_HOOKS_EH_RUNTIME_TYPE, \ + LANG_HOOKS_EH_PROTECT_CLEANUP_ACTIONS, \ LANG_HOOKS_EH_USE_CXA_END_CLEANUP, \ LANG_HOOKS_DEEP_UNSHARING \ } Index: except.h =================================================================== --- except.h (revision 161470) +++ except.h (working copy) @@ -19,6 +19,13 @@ You should have received a copy of the GNU General along with GCC; see the file COPYING3. If not see . */ +/* No include guards here, but define an include file marker anyway, so + that the compiler can keep track of where this file is included. This + is e.g. used to avoid including this file in front-end specific files. */ +#ifndef GCC_EXCEPT_H +# define GCC_EXCEPT_H +#endif + #include "hashtab.h" #include "vecprim.h" #include "vecir.h" @@ -222,16 +229,10 @@ struct GTY(()) eh_status }; -/* Test: is exception handling turned on? */ -extern int doing_eh (int); - /* Invokes CALLBACK for every exception handler label. Only used by old loop hackery; should not be used by new code. */ extern void for_each_eh_label (void (*) (rtx)); -extern void init_eh (void); -extern void init_eh_for_function (void); - extern void remove_eh_landing_pad (eh_landing_pad); extern void remove_eh_handler (eh_region); @@ -287,14 +288,6 @@ extern void assign_filter_values (void); extern eh_region get_eh_region_from_rtx (const_rtx); extern eh_landing_pad get_eh_landing_pad_from_rtx (const_rtx); -/* If non-NULL, this is a function that returns a function decl to be - executed if an unhandled exception is propagated out of a cleanup - region. For example, in C++, an exception thrown by a destructor - during stack unwinding is required to result in a call to - `std::terminate', so the C++ version of this function returns a - FUNCTION_DECL for `std::terminate'. */ -extern tree (*lang_protect_cleanup_actions) (void); - struct GTY(()) throw_stmt_node { gimple stmt; int lp_nr; Index: except.c =================================================================== --- except.c (revision 161470) +++ except.c (working copy) @@ -40,7 +40,7 @@ along with GCC; see the file COPYING3. If not see During pass_lower_eh (tree-eh.c) we record the nested structure of the TRY nodes in EH_REGION nodes in CFUN->EH->REGION_TREE. - We expand the lang_protect_cleanup_actions hook into MUST_NOT_THROW + We expand the eh_protect_cleanup_actions langhook into MUST_NOT_THROW regions at this time. We can then flatten the statements within the TRY nodes to straight-line code. Statements that had been within TRY nodes that can throw are recorded within CFUN->EH->THROW_STMT_TABLE, @@ -150,10 +150,6 @@ along with GCC; see the file COPYING3. If not see #define EH_RETURN_DATA_REGNO(N) INVALID_REGNUM #endif -/* Protect cleanup actions with must-not-throw regions, with a call - to the given failure handler. */ -tree (*lang_protect_cleanup_actions) (void); - static GTY(()) int call_site_base; static GTY ((param_is (union tree_node))) htab_t type_to_runtime_map; @@ -203,30 +199,6 @@ static void dw2_output_call_site_table (int, int); static void sjlj_output_call_site_table (void); -/* Routine to see if exception handling is turned on. - DO_WARN is nonzero if we want to inform the user that exception - handling is turned off. - - This is used to ensure that -fexceptions has been specified if the - compiler tries to use any exception-specific functions. */ - -int -doing_eh (int do_warn) -{ - if (! flag_exceptions) - { - static int warned = 0; - if (! warned && do_warn) - { - error ("exception handling disabled, use -fexceptions to enable"); - warned = 1; - } - return 0; - } - return 1; -} - - void init_eh (void) { @@ -345,10 +317,6 @@ gen_eh_region (enum eh_region_type type, eh_region { eh_region new_eh; -#ifdef ENABLE_CHECKING - gcc_assert (doing_eh (0)); -#endif - /* Insert a new blank region as a leaf in the tree. */ new_eh = ggc_alloc_cleared_eh_region_d (); new_eh->type = type; Index: toplev.h =================================================================== --- toplev.h (revision 161470) +++ toplev.h (working copy) @@ -49,6 +49,9 @@ extern void init_optimization_passes (void); extern void finish_optimization_passes (void); extern bool enable_rtl_dump_file (void); +extern void init_eh (void); +extern void init_eh_for_function (void); + extern void announce_function (tree); extern void error_for_asm (const_rtx, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3); Index: tree-eh.c =================================================================== --- tree-eh.c (revision 161470) +++ tree-eh.c (working copy) @@ -951,12 +951,12 @@ lower_try_finally_fallthru_label (struct leh_tf_st return label; } -/* A subroutine of lower_try_finally. If lang_protect_cleanup_actions - returns non-null, then the language requires that the exception path out - of a try_finally be treated specially. To wit: the code within the - finally block may not itself throw an exception. We have two choices here. - First we can duplicate the finally block and wrap it in a must_not_throw - region. Second, we can generate code like +/* A subroutine of lower_try_finally. If the eh_protect_cleanup_actions + langhook returns non-null, then the language requires that the exception + path out of a try_finally be treated specially. To wit: the code within + the finally block may not itself throw an exception. We have two choices + here. First we can duplicate the finally block and wrap it in a + must_not_throw region. Second, we can generate code like try { finally_block; @@ -983,9 +983,9 @@ honor_protect_cleanup_actions (struct leh_state *o gimple x; /* First check for nothing to do. */ - if (lang_protect_cleanup_actions == NULL) + if (lang_hooks.eh_protect_cleanup_actions == NULL) return; - protect_cleanup_actions = lang_protect_cleanup_actions (); + protect_cleanup_actions = lang_hooks.eh_protect_cleanup_actions (); if (protect_cleanup_actions == NULL) return; Index: omp-low.c =================================================================== --- omp-low.c (revision 161470) +++ omp-low.c (working copy) @@ -3112,8 +3112,8 @@ maybe_catch_exception (gimple_seq body) if (!flag_exceptions) return body; - if (lang_protect_cleanup_actions) - decl = lang_protect_cleanup_actions (); + if (lang_hooks.eh_protect_cleanup_actions != NULL) + decl = lang_hooks.eh_protect_cleanup_actions (); else decl = built_in_decls[BUILT_IN_TRAP]; Index: c-family/c-cppbuiltin.c =================================================================== --- c-family/c-cppbuiltin.c (revision 161470) +++ c-family/c-cppbuiltin.c (working copy) @@ -28,7 +28,6 @@ along with GCC; see the file COPYING3. If not see #include "c-common.h" #include "c-pragma.h" #include "output.h" -#include "except.h" /* For USING_SJLJ_EXCEPTIONS. */ #include "debug.h" /* For dwarf2out_do_cfi_asm. */ #include "toplev.h" #include "tm_p.h" /* For TARGET_CPU_CPP_BUILTINS & friends. */ Index: objc/objc-act.c =================================================================== --- objc/objc-act.c (revision 161470) +++ objc/objc-act.c (working copy) @@ -59,7 +59,6 @@ along with GCC; see the file COPYING3. If not see #include "langhooks.h" #include "objc-act.h" #include "input.h" -#include "except.h" /* For USING_SJLJ_EXCEPTIONS. */ #include "function.h" #include "output.h" #include "toplev.h" Index: cp/init.c =================================================================== --- cp/init.c (revision 161470) +++ cp/init.c (working copy) @@ -30,7 +30,6 @@ along with GCC; see the file COPYING3. If not see #include "cp-tree.h" #include "flags.h" #include "output.h" -#include "except.h" #include "toplev.h" #include "target.h" Index: cp/decl.c =================================================================== --- cp/decl.c (revision 161470) +++ cp/decl.c (working copy) @@ -40,7 +40,6 @@ along with GCC; see the file COPYING3. If not see #include "decl.h" #include "intl.h" #include "output.h" -#include "except.h" #include "toplev.h" #include "hashtab.h" #include "tm_p.h" Index: cp/expr.c =================================================================== --- cp/expr.c (revision 161470) +++ cp/expr.c (working copy) @@ -28,7 +28,6 @@ along with GCC; see the file COPYING3. If not see #include "flags.h" #include "cp-tree.h" #include "toplev.h" -#include "except.h" #include "tm_p.h" /* Expand C++-specific constants. Currently, this means PTRMEM_CST. */ Index: cp/cp-lang.c =================================================================== --- cp/cp-lang.c (revision 161470) +++ cp/cp-lang.c (working copy) @@ -32,7 +32,6 @@ along with GCC; see the file COPYING3. If not see #include "debug.h" #include "cp-objcp-common.h" #include "hashtab.h" -#include "except.h" enum c_language_kind c_language = clk_cxx; static void cp_init_ts (void); Index: cp/pt.c =================================================================== --- cp/pt.c (revision 161470) +++ cp/pt.c (working copy) @@ -40,7 +40,6 @@ along with GCC; see the file COPYING3. If not see #include "tree-inline.h" #include "decl.h" #include "output.h" -#include "except.h" #include "toplev.h" #include "timevar.h" #include "tree-iterator.h" Index: cp/semantics.c =================================================================== --- cp/semantics.c (revision 161470) +++ cp/semantics.c (working copy) @@ -33,7 +33,6 @@ along with GCC; see the file COPYING3. If not see #include "c-family/c-common.h" #include "tree-inline.h" #include "tree-mudflap.h" -#include "except.h" #include "toplev.h" #include "flags.h" #include "output.h" Index: cp/decl2.c =================================================================== --- cp/decl2.c (revision 161470) +++ cp/decl2.c (working copy) @@ -37,7 +37,6 @@ along with GCC; see the file COPYING3. If not see #include "cp-tree.h" #include "decl.h" #include "output.h" -#include "except.h" #include "toplev.h" #include "timevar.h" #include "cpplib.h" Index: cp/except.c =================================================================== --- cp/except.c (revision 161470) +++ cp/except.c (working copy) @@ -31,7 +31,6 @@ along with GCC; see the file COPYING3. If not see #include "cp-tree.h" #include "flags.h" #include "output.h" -#include "except.h" #include "toplev.h" #include "tree-inline.h" #include "tree-iterator.h" @@ -50,7 +49,6 @@ static tree wrap_cleanups_r (tree *, int *, void * static int complete_ptr_ref_or_void_ptr_p (tree, tree); static bool is_admissible_throw_operand (tree); static int can_convert_eh (tree, tree); -static tree cp_protect_cleanup_actions (void); /* Sets up all the global eh stuff that needs to be initialized at the start of compilation. */ @@ -72,14 +70,12 @@ init_exception_processing (void) tmp = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE); call_unexpected_node = push_throw_library_fn (get_identifier ("__cxa_call_unexpected"), tmp); - - lang_protect_cleanup_actions = &cp_protect_cleanup_actions; } /* Returns an expression to be executed if an unhandled exception is propagated out of a cleanup region. */ -static tree +tree cp_protect_cleanup_actions (void) { /* [except.terminate] @@ -407,6 +403,30 @@ initialize_handler_parm (tree decl, tree exp) LOOKUP_ONLYCONVERTING|DIRECT_BIND); } + +/* Routine to see if exception handling is turned on. + DO_WARN is nonzero if we want to inform the user that exception + handling is turned off. + + This is used to ensure that -fexceptions has been specified if the + compiler tries to use any exception-specific functions. */ + +static inline int +doing_eh (void) +{ + if (! flag_exceptions) + { + static int warned = 0; + if (! warned) + { + error ("exception handling disabled, use -fexceptions to enable"); + warned = 1; + } + return 0; + } + return 1; +} + /* Call this to start a catch block. DECL is the catch parameter. */ tree @@ -415,7 +435,7 @@ expand_start_catch_block (tree decl) tree exp; tree type, init; - if (! doing_eh (1)) + if (! doing_eh ()) return NULL_TREE; /* Make sure this declaration is reasonable. */ @@ -494,7 +514,7 @@ expand_start_catch_block (tree decl) void expand_end_catch_block (void) { - if (! doing_eh (1)) + if (! doing_eh ()) return; /* The exception being handled is rethrown if control reaches the end of @@ -641,7 +661,7 @@ build_throw (tree exp) return error_mark_node; } - if (! doing_eh (1)) + if (! doing_eh ()) return error_mark_node; if (exp && decl_is_java_type (TREE_TYPE (exp), 1)) Index: cp/cp-tree.h =================================================================== --- cp/cp-tree.h (revision 161470) +++ cp/cp-tree.h (working copy) @@ -4855,6 +4855,7 @@ extern tree eh_type_info (tree); extern tree begin_eh_spec_block (void); extern void finish_eh_spec_block (tree, tree); extern tree build_eh_type_type (tree); +extern tree cp_protect_cleanup_actions (void); /* in expr.c */ extern tree cplus_expand_constant (tree); Index: cp/cp-objcp-common.h =================================================================== --- cp/cp-objcp-common.h (revision 161470) +++ cp/cp-objcp-common.h (working copy) @@ -143,4 +143,7 @@ extern bool cp_function_decl_explicit_p (tree decl #undef LANG_HOOKS_EH_USE_CXA_END_CLEANUP #define LANG_HOOKS_EH_USE_CXA_END_CLEANUP true +#undef LANG_HOOKS_EH_PROTECT_CLEANUP_ACTIONS +#define LANG_HOOKS_EH_PROTECT_CLEANUP_ACTIONS cp_protect_cleanup_actions + #endif /* GCC_CP_OBJCP_COMMON */ Index: objcp/objcp-lang.c =================================================================== --- objcp/objcp-lang.c (revision 161470) +++ objcp/objcp-lang.c (working copy) @@ -30,7 +30,6 @@ along with GCC; see the file COPYING3. If not see #include "langhooks.h" #include "langhooks-def.h" #include "cp-objcp-common.h" -#include "except.h" /* For USING_SJLJ_EXCEPTIONS. */ enum c_language_kind c_language = clk_objcxx; static void objcxx_init_ts (void); Index: java/lang.c =================================================================== --- java/lang.c (revision 161470) +++ java/lang.c (working copy) @@ -43,7 +43,6 @@ The Free Software Foundation is independent of Sun #include "tree-dump.h" #include "opts.h" #include "options.h" -#include "except.h" /* For USING_SJLJ_EXCEPTIONS. */ static bool java_init (void); static void java_finish (void); Index: java/except.c =================================================================== --- java/except.c (revision 161470) +++ java/except.c (working copy) @@ -31,7 +31,6 @@ The Free Software Foundation is independent of Sun #include "javaop.h" #include "java-opcodes.h" #include "jcf.h" -#include "except.h" /* for doing_eh. */ #include "java-except.h" #include "toplev.h" #include "tree-iterator.h" @@ -565,6 +564,29 @@ check_start_handlers (struct eh_range *range, int } +/* Routine to see if exception handling is turned on. + DO_WARN is nonzero if we want to inform the user that exception + handling is turned off. + + This is used to ensure that -fexceptions has been specified if the + compiler tries to use any exception-specific functions. */ + +static inline int +doing_eh (void) +{ + if (! flag_exceptions) + { + static int warned = 0; + if (! warned) + { + error ("exception handling disabled, use -fexceptions to enable"); + warned = 1; + } + return 0; + } + return 1; +} + static struct eh_range *current_range; /* Emit any start-of-try-range starting at start_pc and ending after @@ -574,7 +596,7 @@ void maybe_start_try (int start_pc, int end_pc) { struct eh_range *range; - if (! doing_eh (1)) + if (! doing_eh ()) return; range = find_handler (start_pc); Index: ada/gcc-interface/misc.c =================================================================== --- ada/gcc-interface/misc.c (revision 161470) +++ ada/gcc-interface/misc.c (working copy) @@ -25,7 +25,7 @@ /* This file contains parts of the compiler that are required for interfacing with GCC but otherwise do nothing and parts of Gigi that need to know - about RTL. */ + about GIMPLE. */ #include "config.h" #include "system.h"