Fix DealII type problems.
[official-gcc/Ramakrishna.git] / gcc / except.h
blob13aadd79ccbbe67afe17cb1e288b1d65cf01ebd0
1 /* Exception Handling interface routines.
2 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2007, 2008, 2009 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
11 version.
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
16 for more details.
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/>. */
22 #include "sbitmap.h"
23 #include "vecprim.h"
25 struct function;
26 struct eh_region_d;
27 struct pointer_map_t;
29 /* The type of an exception region. */
30 enum eh_region_type
32 /* CLEANUP regions implement e.g. destructors run when exiting a block.
33 They can be generated from both GIMPLE_TRY_FINALLY and GIMPLE_TRY_CATCH
34 nodes. It is expected by the runtime that cleanup regions will *not*
35 resume normal program flow, but will continue propagation of the
36 exception. */
37 ERT_CLEANUP,
39 /* TRY regions implement catching an exception. The list of types associated
40 with the attached catch handlers is examined in order by the runtime and
41 control is transfered to the appropriate handler. Note that a NULL type
42 list is a catch-all handler, and that it will catch *all* exceptions
43 including those originating from a different language. */
44 ERT_TRY,
46 /* ALLOWED_EXCEPTIONS regions implement exception filtering, e.g. the
47 throw(type-list) specification that can be added to C++ functions.
48 The runtime examines the thrown exception vs the type list, and if
49 the exception does not match, transfers control to the handler. The
50 normal handler for C++ calls __cxa_call_unexpected. */
51 ERT_ALLOWED_EXCEPTIONS,
53 /* MUST_NOT_THROW regions prevent all exceptions from propagating. This
54 region type is used in C++ to surround destructors being run inside a
55 CLEANUP region. This differs from an ALLOWED_EXCEPTIONS region with
56 an empty type list in that the runtime is prepared to terminate the
57 program directly. We only generate code for MUST_NOT_THROW regions
58 along control paths that are already handling an exception within the
59 current function. */
60 ERT_MUST_NOT_THROW
64 /* A landing pad for a given exception region. Any transfer of control
65 from the EH runtime to the function happens at a landing pad. */
67 struct GTY(()) eh_landing_pad_d
69 /* The linked list of all landing pads associated with the region. */
70 struct eh_landing_pad_d *next_lp;
72 /* The region with which this landing pad is associated. */
73 struct eh_region_d *region;
75 /* At the gimple level, the location to which control will be transfered
76 for this landing pad. There can be both EH and normal edges into the
77 block containing the post-landing-pad label. */
78 tree post_landing_pad;
80 /* At the rtl level, the location to which the runtime will transfer
81 control. This differs from the post-landing-pad in that the target's
82 EXCEPTION_RECEIVER pattern will be expanded here, as well as other
83 bookkeeping specific to exceptions. There must not be normal edges
84 into the block containing the landing-pad label. */
85 rtx landing_pad;
87 /* The index of this landing pad within fun->eh->lp_array. */
88 int index;
91 /* A catch handler associated with an ERT_TRY region. */
93 struct GTY(()) eh_catch_d
95 /* The double-linked list of all catch handlers for the region. */
96 struct eh_catch_d *next_catch;
97 struct eh_catch_d *prev_catch;
99 /* A TREE_LIST of runtime type objects that this catch handler
100 will catch, or NULL if all exceptions are caught. */
101 tree type_list;
103 /* A TREE_LIST of INTEGER_CSTs that correspond to the type_list entries,
104 having been mapped by assign_filter_values. These integers are to be
105 compared against the __builtin_eh_filter value. */
106 tree filter_list;
108 /* The code that should be executed if this catch handler matches the
109 thrown exception. This label is only maintained until
110 pass_lower_eh_dispatch, at which point it is cleared. */
111 tree label;
114 /* Describes one exception region. */
116 struct GTY(()) eh_region_d
118 /* The immediately surrounding region. */
119 struct eh_region_d *outer;
121 /* The list of immediately contained regions. */
122 struct eh_region_d *inner;
123 struct eh_region_d *next_peer;
125 /* The index of this region within fun->eh->region_array. */
126 int index;
128 /* Each region does exactly one thing. */
129 enum eh_region_type type;
131 /* Holds the action to perform based on the preceding type. */
132 union eh_region_u {
133 struct eh_region_u_try {
134 /* The double-linked list of all catch handlers for this region. */
135 struct eh_catch_d *first_catch;
136 struct eh_catch_d *last_catch;
137 } GTY ((tag ("ERT_TRY"))) eh_try;
139 struct eh_region_u_allowed {
140 /* A TREE_LIST of runtime type objects allowed to pass. */
141 tree type_list;
142 /* The code that should be executed if the thrown exception does
143 not match the type list. This label is only maintained until
144 pass_lower_eh_dispatch, at which point it is cleared. */
145 tree label;
146 /* The integer that will be passed by the runtime to signal that
147 we should execute the code at LABEL. This integer is assigned
148 by assign_filter_values and is to be compared against the
149 __builtin_eh_filter value. */
150 int filter;
151 } GTY ((tag ("ERT_ALLOWED_EXCEPTIONS"))) allowed;
153 struct eh_region_u_must_not_throw {
154 /* A function decl to be invoked if this region is actually reachable
155 from within the function, rather than implementable from the runtime.
156 The normal way for this to happen is for there to be a CLEANUP region
157 contained within this MUST_NOT_THROW region. Note that if the
158 runtime handles the MUST_NOT_THROW region, we have no control over
159 what termination function is called; it will be decided by the
160 personality function in effect for this CIE. */
161 tree failure_decl;
162 /* The location assigned to the call of FAILURE_DECL, if expanded. */
163 location_t failure_loc;
164 } GTY ((tag ("ERT_MUST_NOT_THROW"))) must_not_throw;
165 } GTY ((desc ("%0.type"))) u;
167 /* The list of landing pads associated with this region. */
168 struct eh_landing_pad_d *landing_pads;
170 /* EXC_PTR and FILTER values copied from the runtime for this region.
171 Each region gets its own psuedos so that if there are nested exceptions
172 we do not overwrite the values of the first exception. */
173 rtx exc_ptr_reg, filter_reg;
175 /* True if this region should use __cxa_end_cleanup instead
176 of _Unwind_Resume. */
177 bool use_cxa_end_cleanup;
180 typedef struct eh_landing_pad_d *eh_landing_pad;
181 typedef struct eh_catch_d *eh_catch;
182 typedef struct eh_region_d *eh_region;
184 DEF_VEC_P(eh_region);
185 DEF_VEC_ALLOC_P(eh_region, gc);
186 DEF_VEC_ALLOC_P(eh_region, heap);
188 DEF_VEC_P(eh_landing_pad);
189 DEF_VEC_ALLOC_P(eh_landing_pad, gc);
192 /* The exception status for each function. */
194 struct GTY(()) eh_status
196 /* The tree of all regions for this function. */
197 eh_region region_tree;
199 /* The same information as an indexable array. */
200 VEC(eh_region,gc) *region_array;
202 /* The landing pads as an indexable array. */
203 VEC(eh_landing_pad,gc) *lp_array;
205 /* At the gimple level, a mapping from gimple statement to landing pad
206 or must-not-throw region. See record_stmt_eh_region. */
207 htab_t GTY((param_is (struct throw_stmt_node))) throw_stmt_table;
209 /* All of the runtime type data used by the function. These objects
210 are emitted to the lang-specific-data-area for the function. */
211 VEC(tree,gc) *ttype_data;
213 /* The table of all action chains. These encode the eh_region tree in
214 a compact form for use by the runtime, and is also emitted to the
215 lang-specific-data-area. Note that the ARM EABI uses a different
216 format for the encoding than all other ports. */
217 union eh_status_u {
218 VEC(tree,gc) * GTY((tag ("1"))) arm_eabi;
219 VEC(uchar,gc) * GTY((tag ("0"))) other;
220 } GTY ((desc ("targetm.arm_eabi_unwinder"))) ehspec_data;
224 /* Test: is exception handling turned on? */
225 extern int doing_eh (int);
227 /* Invokes CALLBACK for every exception handler label. Only used by old
228 loop hackery; should not be used by new code. */
229 extern void for_each_eh_label (void (*) (rtx));
231 /* Set TREE_NOTHROW and cfun->all_throwers_are_sibcalls. */
232 extern unsigned int set_nothrow_function_flags (void);
234 extern void init_eh (void);
235 extern void init_eh_for_function (void);
237 extern void remove_eh_landing_pad (eh_landing_pad);
238 extern void remove_eh_handler (eh_region);
240 extern bool current_function_has_exception_handlers (void);
241 extern void output_function_exception_table (const char *);
243 extern rtx expand_builtin_eh_pointer (tree);
244 extern rtx expand_builtin_eh_filter (tree);
245 extern rtx expand_builtin_eh_copy_values (tree);
246 extern void expand_builtin_unwind_init (void);
247 extern rtx expand_builtin_eh_return_data_regno (tree);
248 extern rtx expand_builtin_extract_return_addr (tree);
249 extern void expand_builtin_init_dwarf_reg_sizes (tree);
250 extern rtx expand_builtin_frob_return_addr (tree);
251 extern rtx expand_builtin_dwarf_sp_column (void);
252 extern void expand_builtin_eh_return (tree, tree);
253 extern void expand_eh_return (void);
254 extern rtx expand_builtin_extend_pointer (tree);
256 typedef tree (*duplicate_eh_regions_map) (tree, void *);
257 extern struct pointer_map_t *duplicate_eh_regions
258 (struct function *, eh_region, int, duplicate_eh_regions_map, void *);
260 extern void sjlj_emit_function_exit_after (rtx);
262 extern eh_region gen_eh_region_cleanup (eh_region);
263 extern eh_region gen_eh_region_try (eh_region);
264 extern eh_region gen_eh_region_allowed (eh_region, tree);
265 extern eh_region gen_eh_region_must_not_throw (eh_region);
267 extern eh_catch gen_eh_region_catch (eh_region, tree);
268 extern eh_landing_pad gen_eh_landing_pad (eh_region);
270 extern eh_region get_eh_region_from_number_fn (struct function *, int);
271 extern eh_region get_eh_region_from_number (int);
272 extern eh_landing_pad get_eh_landing_pad_from_number_fn (struct function*,int);
273 extern eh_landing_pad get_eh_landing_pad_from_number (int);
274 extern eh_region get_eh_region_from_lp_number_fn (struct function *, int);
275 extern eh_region get_eh_region_from_lp_number (int);
277 extern eh_region eh_region_outermost (struct function *, eh_region, eh_region);
279 extern void make_reg_eh_region_note (rtx insn, int ecf_flags, int lp_nr);
280 extern void make_reg_eh_region_note_nothrow_nononlocal (rtx);
282 extern void verify_eh_tree (struct function *);
283 extern void dump_eh_tree (FILE *, struct function *);
284 void debug_eh_tree (struct function *);
285 extern void add_type_for_runtime (tree);
286 extern tree lookup_type_for_runtime (tree);
287 extern void assign_filter_values (void);
289 extern eh_region get_eh_region_from_rtx (const_rtx);
290 extern eh_landing_pad get_eh_landing_pad_from_rtx (const_rtx);
292 /* If non-NULL, this is a function that returns a function decl to be
293 executed if an unhandled exception is propagated out of a cleanup
294 region. For example, in C++, an exception thrown by a destructor
295 during stack unwinding is required to result in a call to
296 `std::terminate', so the C++ version of this function returns a
297 FUNCTION_DECL for `std::terminate'. */
298 extern tree (*lang_protect_cleanup_actions) (void);
300 /* Return true if type A catches type B. */
301 extern int (*lang_eh_type_covers) (tree a, tree b);
304 /* Just because the user configured --with-sjlj-exceptions=no doesn't
305 mean that we can use call frame exceptions. Detect that the target
306 has appropriate support. */
308 #ifndef MUST_USE_SJLJ_EXCEPTIONS
309 # if defined (EH_RETURN_DATA_REGNO) \
310 && (defined (TARGET_UNWIND_INFO) \
311 || (DWARF2_UNWIND_INFO \
312 && (defined (EH_RETURN_HANDLER_RTX) \
313 || defined (HAVE_eh_return))))
314 # define MUST_USE_SJLJ_EXCEPTIONS 0
315 # else
316 # define MUST_USE_SJLJ_EXCEPTIONS 1
317 # endif
318 #endif
320 #ifdef CONFIG_SJLJ_EXCEPTIONS
321 # if CONFIG_SJLJ_EXCEPTIONS == 1
322 # define USING_SJLJ_EXCEPTIONS 1
323 # endif
324 # if CONFIG_SJLJ_EXCEPTIONS == 0
325 # define USING_SJLJ_EXCEPTIONS 0
326 # if !defined(EH_RETURN_DATA_REGNO)
327 #error "EH_RETURN_DATA_REGNO required"
328 # endif
329 # if ! (defined(TARGET_UNWIND_INFO) || DWARF2_UNWIND_INFO)
330 #error "{DWARF2,TARGET}_UNWIND_INFO required"
331 # endif
332 # if !defined(TARGET_UNWIND_INFO) \
333 && !(defined(EH_RETURN_HANDLER_RTX) || defined(HAVE_eh_return))
334 #error "EH_RETURN_HANDLER_RTX or eh_return required"
335 # endif
336 /* Usually the above error checks will have already triggered an
337 error, but backends may set MUST_USE_SJLJ_EXCEPTIONS for their own
338 reasons. */
339 # if MUST_USE_SJLJ_EXCEPTIONS
340 #error "Must use SJLJ exceptions but configured not to"
341 # endif
342 # endif
343 #else
344 # define USING_SJLJ_EXCEPTIONS MUST_USE_SJLJ_EXCEPTIONS
345 #endif
347 struct GTY(()) throw_stmt_node {
348 gimple stmt;
349 int lp_nr;
352 extern struct htab *get_eh_throw_stmt_table (struct function *);
353 extern void set_eh_throw_stmt_table (struct function *, struct htab *);
355 enum eh_personality_kind {
356 eh_personality_none,
357 eh_personality_any,
358 eh_personality_lang
361 extern enum eh_personality_kind
362 function_needs_eh_personality (struct function *);
364 /* Pre-order iteration within the eh_region tree. */
366 static inline eh_region
367 ehr_next (eh_region r, eh_region start)
369 if (r->inner)
370 r = r->inner;
371 else if (r->next_peer && r != start)
372 r = r->next_peer;
373 else
377 r = r->outer;
378 if (r == start)
379 return NULL;
381 while (r->next_peer == NULL);
382 r = r->next_peer;
384 return r;
387 #define FOR_ALL_EH_REGION_AT(R, START) \
388 for ((R) = (START); (R) != NULL; (R) = ehr_next (R, START))
390 #define FOR_ALL_EH_REGION_FN(R, FN) \
391 for ((R) = (FN)->eh->region_tree; (R) != NULL; (R) = ehr_next (R, NULL))
393 #define FOR_ALL_EH_REGION(R) FOR_ALL_EH_REGION_FN (R, cfun)