1 /* Exception Handling interface routines.
2 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2007, 2008 Free Software Foundation, Inc.
4 Contributed by Mike Stump <mrs@cygnus.com>.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
27 /* Describes one exception region. */
28 struct GTY(()) eh_region
30 /* The immediately surrounding region. */
31 struct eh_region
*outer
;
33 /* The list of immediately contained regions. */
34 struct eh_region
*inner
;
35 struct eh_region
*next_peer
;
37 /* An identifier for this region. */
40 /* When a region is deleted, its parents inherit the REG_EH_REGION
41 numbers already assigned. */
44 /* Each region does exactly one thing. */
51 ERT_ALLOWED_EXCEPTIONS
,
56 /* Holds the action to perform based on the preceding type. */
58 /* A list of catch blocks, a surrounding try block,
59 and the label for continuing after a catch. */
60 struct eh_region_u_try
{
61 struct eh_region
*eh_catch
;
62 struct eh_region
*last_catch
;
63 } GTY ((tag ("ERT_TRY"))) eh_try
;
65 /* The list through the catch handlers, the list of type objects
66 matched, and the list of associated filters. */
67 struct eh_region_u_catch
{
68 struct eh_region
*next_catch
;
69 struct eh_region
*prev_catch
;
72 } GTY ((tag ("ERT_CATCH"))) eh_catch
;
74 /* A tree_list of allowed types. */
75 struct eh_region_u_allowed
{
78 } GTY ((tag ("ERT_ALLOWED_EXCEPTIONS"))) allowed
;
80 /* The type given by a call to "throw foo();", or discovered
82 struct eh_region_u_throw
{
84 } GTY ((tag ("ERT_THROW"))) eh_throw
;
86 /* Retain the cleanup expression even after expansion so that
87 we can match up fixup regions. */
88 struct eh_region_u_cleanup
{
89 struct eh_region
*prev_try
;
90 } GTY ((tag ("ERT_CLEANUP"))) cleanup
;
91 } GTY ((desc ("%0.type"))) u
;
93 /* Entry point for this region's handler before landing pads are built. */
97 /* Entry point for this region's handler from the runtime eh library. */
100 /* Entry point for this region's handler from an inner region. */
101 rtx post_landing_pad
;
103 /* The RESX insn for handing off control to the next outermost handler,
107 /* True if something in this region may throw. */
108 unsigned may_contain_throw
: 1;
111 typedef struct eh_region
*eh_region
;
112 DEF_VEC_P(eh_region
);
113 DEF_VEC_ALLOC_P(eh_region
, gc
);
114 DEF_VEC_ALLOC_P(eh_region
, heap
);
116 /* Per-function EH data. Used to save exception status for each
118 struct GTY(()) eh_status
120 /* The tree of all regions for this function. */
121 struct eh_region
*region_tree
;
123 /* The same information as an indexable array. */
124 VEC(eh_region
,gc
) *region_array
;
125 int last_region_number
;
127 htab_t
GTY((param_is (struct throw_stmt_node
))) throw_stmt_table
;
131 /* Test: is exception handling turned on? */
132 extern int doing_eh (int);
134 /* Note that the current EH region (if any) may contain a throw, or a
135 call to a function which itself may contain a throw. */
136 extern void note_eh_region_may_contain_throw (struct eh_region
*);
138 /* Invokes CALLBACK for every exception handler label. Only used by old
139 loop hackery; should not be used by new code. */
140 extern void for_each_eh_label (void (*) (rtx
));
142 /* Invokes CALLBACK for every exception region in the current function. */
143 extern void for_each_eh_region (void (*) (struct eh_region
*));
145 /* Determine if the given INSN can throw an exception. */
146 extern bool can_throw_internal_1 (int, bool, bool);
147 extern bool can_throw_internal (const_rtx
);
148 extern bool can_throw_external_1 (int, bool, bool);
149 extern bool can_throw_external (const_rtx
);
151 /* Set TREE_NOTHROW and cfun->all_throwers_are_sibcalls. */
152 extern unsigned int set_nothrow_function_flags (void);
154 extern void init_eh (void);
155 extern void init_eh_for_function (void);
157 extern rtx
reachable_handlers (rtx
);
158 void remove_eh_region (int);
160 extern void convert_from_eh_region_ranges (void);
161 extern unsigned int convert_to_eh_region_ranges (void);
162 extern void find_exception_handler_labels (void);
163 extern bool current_function_has_exception_handlers (void);
164 extern void output_function_exception_table (const char *);
166 extern void expand_builtin_unwind_init (void);
167 extern rtx
expand_builtin_eh_return_data_regno (tree
);
168 extern rtx
expand_builtin_extract_return_addr (tree
);
169 extern void expand_builtin_init_dwarf_reg_sizes (tree
);
170 extern rtx
expand_builtin_frob_return_addr (tree
);
171 extern rtx
expand_builtin_dwarf_sp_column (void);
172 extern void expand_builtin_eh_return (tree
, tree
);
173 extern void expand_eh_return (void);
174 extern rtx
expand_builtin_extend_pointer (tree
);
175 extern rtx
get_exception_pointer (void);
176 extern rtx
get_exception_filter (void);
177 typedef tree (*duplicate_eh_regions_map
) (tree
, void *);
178 extern int duplicate_eh_regions (struct function
*, duplicate_eh_regions_map
,
181 extern void sjlj_emit_function_exit_after (rtx
);
182 extern void default_init_unwind_resume_libfunc (void);
184 extern struct eh_region
*gen_eh_region_cleanup (struct eh_region
*,
186 extern struct eh_region
*gen_eh_region_try (struct eh_region
*);
187 extern struct eh_region
*gen_eh_region_catch (struct eh_region
*, tree
);
188 extern struct eh_region
*gen_eh_region_allowed (struct eh_region
*, tree
);
189 extern struct eh_region
*gen_eh_region_must_not_throw (struct eh_region
*);
190 extern int get_eh_region_number (struct eh_region
*);
191 extern bool get_eh_region_may_contain_throw (struct eh_region
*);
192 extern tree
get_eh_region_no_tree_label (int);
193 extern tree
get_eh_region_tree_label (struct eh_region
*);
194 extern void set_eh_region_tree_label (struct eh_region
*, tree
);
196 extern void foreach_reachable_handler (int, bool, bool,
197 void (*) (struct eh_region
*, void *),
200 extern void collect_eh_region_array (void);
201 extern void expand_resx_expr (tree
);
202 extern void verify_eh_tree (struct function
*);
203 extern void dump_eh_tree (FILE *, struct function
*);
204 void debug_eh_tree (struct function
*);
205 extern int eh_region_outermost (struct function
*, int, int);
206 extern void add_type_for_runtime (tree
);
207 extern tree
lookup_type_for_runtime (tree
);
209 /* If non-NULL, this is a function that returns an expression to be
210 executed if an unhandled exception is propagated out of a cleanup
211 region. For example, in C++, an exception thrown by a destructor
212 during stack unwinding is required to result in a call to
213 `std::terminate', so the C++ version of this function returns a
214 CALL_EXPR for `std::terminate'. */
215 extern gimple (*lang_protect_cleanup_actions
) (void);
217 /* Return true if type A catches type B. */
218 extern int (*lang_eh_type_covers
) (tree a
, tree b
);
220 /* Map a type to a runtime object to match type. */
221 extern tree (*lang_eh_runtime_type
) (tree
);
224 /* Just because the user configured --with-sjlj-exceptions=no doesn't
225 mean that we can use call frame exceptions. Detect that the target
226 has appropriate support. */
228 #ifndef MUST_USE_SJLJ_EXCEPTIONS
229 # if defined (EH_RETURN_DATA_REGNO) \
230 && (defined (TARGET_UNWIND_INFO) \
231 || (DWARF2_UNWIND_INFO \
232 && (defined (EH_RETURN_HANDLER_RTX) \
233 || defined (HAVE_eh_return))))
234 # define MUST_USE_SJLJ_EXCEPTIONS 0
236 # define MUST_USE_SJLJ_EXCEPTIONS 1
240 #ifdef CONFIG_SJLJ_EXCEPTIONS
241 # if CONFIG_SJLJ_EXCEPTIONS == 1
242 # define USING_SJLJ_EXCEPTIONS 1
244 # if CONFIG_SJLJ_EXCEPTIONS == 0
245 # define USING_SJLJ_EXCEPTIONS 0
246 # if !defined(EH_RETURN_DATA_REGNO)
247 #error "EH_RETURN_DATA_REGNO required"
249 # if ! (defined(TARGET_UNWIND_INFO) || DWARF2_UNWIND_INFO)
250 #error "{DWARF2,TARGET}_UNWIND_INFO required"
252 # if !defined(TARGET_UNWIND_INFO) \
253 && !(defined(EH_RETURN_HANDLER_RTX) || defined(HAVE_eh_return))
254 #error "EH_RETURN_HANDLER_RTX or eh_return required"
256 /* Usually the above error checks will have already triggered an
257 error, but backends may set MUST_USE_SJLJ_EXCEPTIONS for their own
259 # if MUST_USE_SJLJ_EXCEPTIONS
260 #error "Must use SJLJ exceptions but configured not to"
264 # define USING_SJLJ_EXCEPTIONS MUST_USE_SJLJ_EXCEPTIONS
267 struct GTY(()) throw_stmt_node
{
272 extern struct htab
*get_eh_throw_stmt_table (struct function
*);
273 extern void set_eh_throw_stmt_table (struct function
*, struct htab
*);
274 extern void remove_unreachable_regions (sbitmap
, sbitmap
);
275 extern VEC(int,heap
) * label_to_region_map (void);
276 extern int num_eh_regions (void);