150397Sobrien/* Exception Handling interface routines. 2169689Skan Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 390075Sobrien Free Software Foundation, Inc. 450397Sobrien Contributed by Mike Stump <mrs@cygnus.com>. 550397Sobrien 690075SobrienThis file is part of GCC. 750397Sobrien 890075SobrienGCC is free software; you can redistribute it and/or modify it under 990075Sobrienthe terms of the GNU General Public License as published by the Free 1090075SobrienSoftware Foundation; either version 2, or (at your option) any later 1190075Sobrienversion. 1250397Sobrien 1390075SobrienGCC is distributed in the hope that it will be useful, but WITHOUT ANY 1490075SobrienWARRANTY; without even the implied warranty of MERCHANTABILITY or 1590075SobrienFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1690075Sobrienfor more details. 1750397Sobrien 1850397SobrienYou should have received a copy of the GNU General Public License 1990075Sobrienalong with GCC; see the file COPYING. If not, write to the Free 20169689SkanSoftware Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 21169689Skan02110-1301, USA. */ 2250397Sobrien 2390075Sobrien 2490075Sobrienstruct function; 2552284Sobrien 2690075Sobrien/* Per-function EH data. Used only in except.c, but GC and others 2790075Sobrien manipulate pointers to the opaque type. */ 2890075Sobrienstruct eh_status; 2950397Sobrien 3090075Sobrien/* Internal structure describing a region. */ 3190075Sobrienstruct eh_region; 3250397Sobrien 3390075Sobrien/* Test: is exception handling turned on? */ 34132718Skanextern int doing_eh (int); 3550397Sobrien 36117395Skan/* Note that the current EH region (if any) may contain a throw, or a 37117395Skan call to a function which itself may contain a throw. */ 38169689Skanextern void note_eh_region_may_contain_throw (struct eh_region *); 39169689Skanextern void note_current_region_may_contain_throw (void); 4050397Sobrien 4196263Sobrien/* Invokes CALLBACK for every exception handler label. Only used by old 4296263Sobrien loop hackery; should not be used by new code. */ 43132718Skanextern void for_each_eh_label (void (*) (rtx)); 4450397Sobrien 45169689Skan/* Invokes CALLBACK for every exception region in the current function. */ 46169689Skanextern void for_each_eh_region (void (*) (struct eh_region *)); 47169689Skan 4890075Sobrien/* Determine if the given INSN can throw an exception. */ 49169689Skanextern bool can_throw_internal_1 (int, bool); 50132718Skanextern bool can_throw_internal (rtx); 51169689Skanextern bool can_throw_external_1 (int, bool); 52132718Skanextern bool can_throw_external (rtx); 5350397Sobrien 54169689Skan/* Set TREE_NOTHROW and cfun->all_throwers_are_sibcalls. */ 55169689Skanextern unsigned int set_nothrow_function_flags (void); 5650397Sobrien 5790075Sobrien/* After initial rtl generation, call back to finish generating 5890075Sobrien exception support code. */ 59132718Skanextern void finish_eh_generation (void); 6050397Sobrien 61132718Skanextern void init_eh (void); 62132718Skanextern void init_eh_for_function (void); 6350397Sobrien 64132718Skanextern rtx reachable_handlers (rtx); 65132718Skanextern void maybe_remove_eh_handler (rtx); 6650397Sobrien 67132718Skanextern void convert_from_eh_region_ranges (void); 68169689Skanextern unsigned int convert_to_eh_region_ranges (void); 69132718Skanextern void find_exception_handler_labels (void); 70132718Skanextern bool current_function_has_exception_handlers (void); 71132718Skanextern void output_function_exception_table (void); 7250397Sobrien 73132718Skanextern void expand_builtin_unwind_init (void); 74132718Skanextern rtx expand_builtin_eh_return_data_regno (tree); 75132718Skanextern rtx expand_builtin_extract_return_addr (tree); 76132718Skanextern void expand_builtin_init_dwarf_reg_sizes (tree); 77132718Skanextern rtx expand_builtin_frob_return_addr (tree); 78132718Skanextern rtx expand_builtin_dwarf_sp_column (void); 79132718Skanextern void expand_builtin_eh_return (tree, tree); 80132718Skanextern void expand_eh_return (void); 81132718Skanextern rtx expand_builtin_extend_pointer (tree); 82132718Skanextern rtx get_exception_pointer (struct function *); 83169689Skanextern rtx get_exception_filter (struct function *); 84169689Skantypedef tree (*duplicate_eh_regions_map) (tree, void *); 85169689Skanextern int duplicate_eh_regions (struct function *, duplicate_eh_regions_map, 86169689Skan void *, int, int); 8750397Sobrien 88132718Skanextern void sjlj_emit_function_exit_after (rtx); 89169689Skanextern void default_init_unwind_resume_libfunc (void); 9050397Sobrien 91169689Skanextern struct eh_region *gen_eh_region_cleanup (struct eh_region *, 92169689Skan struct eh_region *); 93169689Skanextern struct eh_region *gen_eh_region_try (struct eh_region *); 94169689Skanextern struct eh_region *gen_eh_region_catch (struct eh_region *, tree); 95169689Skanextern struct eh_region *gen_eh_region_allowed (struct eh_region *, tree); 96169689Skanextern struct eh_region *gen_eh_region_must_not_throw (struct eh_region *); 97169689Skanextern int get_eh_region_number (struct eh_region *); 98169689Skanextern bool get_eh_region_may_contain_throw (struct eh_region *); 99169689Skanextern tree get_eh_region_tree_label (struct eh_region *); 100169689Skanextern void set_eh_region_tree_label (struct eh_region *, tree); 10150397Sobrien 102169689Skanextern void foreach_reachable_handler (int, bool, 103169689Skan void (*) (struct eh_region *, void *), 104169689Skan void *); 105169689Skan 106169689Skanextern void collect_eh_region_array (void); 107169689Skanextern void expand_resx_expr (tree); 108169689Skanextern void verify_eh_tree (struct function *); 109169689Skanextern void dump_eh_tree (FILE *, struct function *); 110169689Skanextern bool eh_region_outer_p (struct function *, int, int); 111169689Skanextern int eh_region_outermost (struct function *, int, int); 112169689Skan 113169689Skan/* tree-eh.c */ 114169689Skanextern void add_stmt_to_eh_region_fn (struct function *, tree, int); 115169689Skanextern bool remove_stmt_from_eh_region_fn (struct function *, tree); 116169689Skanextern int lookup_stmt_eh_region_fn (struct function *, tree); 117169689Skanextern int lookup_stmt_eh_region (tree); 118169689Skanextern bool verify_eh_edges (tree); 119169689Skan 12090075Sobrien/* If non-NULL, this is a function that returns an expression to be 12190075Sobrien executed if an unhandled exception is propagated out of a cleanup 12290075Sobrien region. For example, in C++, an exception thrown by a destructor 12390075Sobrien during stack unwinding is required to result in a call to 12490075Sobrien `std::terminate', so the C++ version of this function returns a 12590075Sobrien CALL_EXPR for `std::terminate'. */ 126132718Skanextern tree (*lang_protect_cleanup_actions) (void); 12750397Sobrien 12890075Sobrien/* Return true if type A catches type B. */ 129132718Skanextern int (*lang_eh_type_covers) (tree a, tree b); 13050397Sobrien 13190075Sobrien/* Map a type to a runtime object to match type. */ 132132718Skanextern tree (*lang_eh_runtime_type) (tree); 13350397Sobrien 13450397Sobrien 13590075Sobrien/* Just because the user configured --with-sjlj-exceptions=no doesn't 13690075Sobrien mean that we can use call frame exceptions. Detect that the target 13790075Sobrien has appropriate support. */ 13850397Sobrien 139132718Skan#ifndef MUST_USE_SJLJ_EXCEPTIONS 140132718Skan# if !(defined (EH_RETURN_DATA_REGNO) \ 141169689Skan && (defined (TARGET_UNWIND_INFO) \ 14290075Sobrien || (DWARF2_UNWIND_INFO \ 14390075Sobrien && (defined (EH_RETURN_HANDLER_RTX) \ 14490075Sobrien || defined (HAVE_eh_return))))) 145132718Skan# define MUST_USE_SJLJ_EXCEPTIONS 1 146132718Skan# else 147132718Skan# define MUST_USE_SJLJ_EXCEPTIONS 0 148132718Skan# endif 14950397Sobrien#endif 15050397Sobrien 15190075Sobrien#ifdef CONFIG_SJLJ_EXCEPTIONS 15290075Sobrien# if CONFIG_SJLJ_EXCEPTIONS == 1 15390075Sobrien# define USING_SJLJ_EXCEPTIONS 1 15490075Sobrien# endif 15590075Sobrien# if CONFIG_SJLJ_EXCEPTIONS == 0 15690075Sobrien# define USING_SJLJ_EXCEPTIONS 0 15790075Sobrien# ifndef EH_RETURN_DATA_REGNO 15890075Sobrien #error "EH_RETURN_DATA_REGNO required" 15990075Sobrien# endif 16090075Sobrien# if !defined(EH_RETURN_HANDLER_RTX) && !defined(HAVE_eh_return) 16190075Sobrien #error "EH_RETURN_HANDLER_RTX or eh_return required" 16290075Sobrien# endif 163169689Skan# if !defined(DWARF2_UNWIND_INFO) && !defined(TARGET_UNWIND_INFO) 164169689Skan #error "{DWARF2,TARGET}_UNWIND_INFO required" 16590075Sobrien# endif 16690075Sobrien# endif 16790075Sobrien#else 16890075Sobrien# define USING_SJLJ_EXCEPTIONS MUST_USE_SJLJ_EXCEPTIONS 16950397Sobrien#endif 170169689Skan 171169689Skanstruct throw_stmt_node GTY(()) 172169689Skan{ 173169689Skan tree stmt; 174169689Skan int region_nr; 175169689Skan}; 176169689Skan 177169689Skanextern struct htab *get_eh_throw_stmt_table (struct function *); 178169689Skanextern void set_eh_throw_stmt_table (struct function *, struct htab *); 179169689Skan 180169689Skan#ifdef ENABLE_CHECKING 181169689Skanextern void verify_eh_throw_table_statements (void); 182169689Skan#endif 183