comparison gcc/except.h @ 55:77e2b8dfacca gcc-4.4.5

update it from 4.4.3 to 4.5.0
author ryoma <e075725@ie.u-ryukyu.ac.jp>
date Fri, 12 Feb 2010 23:39:51 +0900
parents a06113de4d67
children b7f97abdc517
comparison
equal deleted inserted replaced
52:c156f1bd5cd9 55:77e2b8dfacca
1 /* Exception Handling interface routines. 1 /* Exception Handling interface routines.
2 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2007, 2008 Free Software Foundation, Inc. 3 2007, 2008, 2009 Free Software Foundation, Inc.
4 Contributed by Mike Stump <mrs@cygnus.com>. 4 Contributed by Mike Stump <mrs@cygnus.com>.
5 5
6 This file is part of GCC. 6 This file is part of GCC.
7 7
8 GCC is free software; you can redistribute it and/or modify it under 8 GCC is free software; you can redistribute it and/or modify it under
17 17
18 You should have received a copy of 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 19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */ 20 <http://www.gnu.org/licenses/>. */
21 21
22 #include "sbitmap.h"
23 #include "vecprim.h"
22 24
23 struct function; 25 struct function;
24 26 struct eh_region_d;
25 /* Per-function EH data. Used only in except.c, but GC and others 27 struct pointer_map_t;
26 manipulate pointers to the opaque type. */ 28
27 struct eh_status; 29 /* The type of an exception region. */
28 30 enum eh_region_type
29 /* Internal structure describing a region. */ 31 {
30 struct eh_region; 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,
38
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,
45
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,
52
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
61 };
62
63
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. */
66
67 struct GTY(()) eh_landing_pad_d
68 {
69 /* The linked list of all landing pads associated with the region. */
70 struct eh_landing_pad_d *next_lp;
71
72 /* The region with which this landing pad is associated. */
73 struct eh_region_d *region;
74
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;
79
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;
86
87 /* The index of this landing pad within fun->eh->lp_array. */
88 int index;
89 };
90
91 /* A catch handler associated with an ERT_TRY region. */
92
93 struct GTY(()) eh_catch_d
94 {
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;
98
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;
102
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;
107
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;
112 };
113
114 /* Describes one exception region. */
115
116 struct GTY(()) eh_region_d
117 {
118 /* The immediately surrounding region. */
119 struct eh_region_d *outer;
120
121 /* The list of immediately contained regions. */
122 struct eh_region_d *inner;
123 struct eh_region_d *next_peer;
124
125 /* The index of this region within fun->eh->region_array. */
126 int index;
127
128 /* Each region does exactly one thing. */
129 enum eh_region_type type;
130
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;
138
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;
152
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;
166
167 /* The list of landing pads associated with this region. */
168 struct eh_landing_pad_d *landing_pads;
169
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;
174
175 /* True if this region should use __cxa_end_cleanup instead
176 of _Unwind_Resume. */
177 bool use_cxa_end_cleanup;
178 };
179
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;
183
184 DEF_VEC_P(eh_region);
185 DEF_VEC_ALLOC_P(eh_region, gc);
186 DEF_VEC_ALLOC_P(eh_region, heap);
187
188 DEF_VEC_P(eh_landing_pad);
189 DEF_VEC_ALLOC_P(eh_landing_pad, gc);
190
191
192 /* The exception status for each function. */
193
194 struct GTY(()) eh_status
195 {
196 /* The tree of all regions for this function. */
197 eh_region region_tree;
198
199 /* The same information as an indexable array. */
200 VEC(eh_region,gc) *region_array;
201
202 /* The landing pads as an indexable array. */
203 VEC(eh_landing_pad,gc) *lp_array;
204
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;
208
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;
212
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;
221 };
222
31 223
32 /* Test: is exception handling turned on? */ 224 /* Test: is exception handling turned on? */
33 extern int doing_eh (int); 225 extern int doing_eh (int);
34
35 /* Note that the current EH region (if any) may contain a throw, or a
36 call to a function which itself may contain a throw. */
37 extern void note_eh_region_may_contain_throw (struct eh_region *);
38 226
39 /* Invokes CALLBACK for every exception handler label. Only used by old 227 /* Invokes CALLBACK for every exception handler label. Only used by old
40 loop hackery; should not be used by new code. */ 228 loop hackery; should not be used by new code. */
41 extern void for_each_eh_label (void (*) (rtx)); 229 extern void for_each_eh_label (void (*) (rtx));
42 230
43 /* Invokes CALLBACK for every exception region in the current function. */
44 extern void for_each_eh_region (void (*) (struct eh_region *));
45
46 /* Determine if the given INSN can throw an exception. */
47 extern bool can_throw_internal_1 (int, bool);
48 extern bool can_throw_internal (const_rtx);
49 extern bool can_throw_external_1 (int, bool);
50 extern bool can_throw_external (const_rtx);
51
52 /* Set TREE_NOTHROW and cfun->all_throwers_are_sibcalls. */
53 extern unsigned int set_nothrow_function_flags (void);
54
55 /* After initial rtl generation, call back to finish generating
56 exception support code. */
57 extern void finish_eh_generation (void);
58
59 extern void init_eh (void); 231 extern void init_eh (void);
60 extern void init_eh_for_function (void); 232 extern void init_eh_for_function (void);
61 233
62 extern rtx reachable_handlers (rtx); 234 extern void remove_eh_landing_pad (eh_landing_pad);
63 extern void maybe_remove_eh_handler (rtx); 235 extern void remove_eh_handler (eh_region);
64 236
65 extern void convert_from_eh_region_ranges (void);
66 extern unsigned int convert_to_eh_region_ranges (void);
67 extern void find_exception_handler_labels (void);
68 extern bool current_function_has_exception_handlers (void); 237 extern bool current_function_has_exception_handlers (void);
69 extern void output_function_exception_table (const char *); 238 extern void output_function_exception_table (const char *);
70 239
240 extern rtx expand_builtin_eh_pointer (tree);
241 extern rtx expand_builtin_eh_filter (tree);
242 extern rtx expand_builtin_eh_copy_values (tree);
71 extern void expand_builtin_unwind_init (void); 243 extern void expand_builtin_unwind_init (void);
72 extern rtx expand_builtin_eh_return_data_regno (tree); 244 extern rtx expand_builtin_eh_return_data_regno (tree);
73 extern rtx expand_builtin_extract_return_addr (tree); 245 extern rtx expand_builtin_extract_return_addr (tree);
74 extern void expand_builtin_init_dwarf_reg_sizes (tree); 246 extern void expand_builtin_init_dwarf_reg_sizes (tree);
75 extern rtx expand_builtin_frob_return_addr (tree); 247 extern rtx expand_builtin_frob_return_addr (tree);
76 extern rtx expand_builtin_dwarf_sp_column (void); 248 extern rtx expand_builtin_dwarf_sp_column (void);
77 extern void expand_builtin_eh_return (tree, tree); 249 extern void expand_builtin_eh_return (tree, tree);
78 extern void expand_eh_return (void); 250 extern void expand_eh_return (void);
79 extern rtx expand_builtin_extend_pointer (tree); 251 extern rtx expand_builtin_extend_pointer (tree);
80 extern rtx get_exception_pointer (void); 252
81 extern rtx get_exception_filter (void);
82 typedef tree (*duplicate_eh_regions_map) (tree, void *); 253 typedef tree (*duplicate_eh_regions_map) (tree, void *);
83 extern int duplicate_eh_regions (struct function *, duplicate_eh_regions_map, 254 extern struct pointer_map_t *duplicate_eh_regions
84 void *, int, int); 255 (struct function *, eh_region, int, duplicate_eh_regions_map, void *);
85 256
86 extern void sjlj_emit_function_exit_after (rtx); 257 extern void sjlj_emit_function_exit_after (rtx);
87 extern void default_init_unwind_resume_libfunc (void); 258
88 259 extern eh_region gen_eh_region_cleanup (eh_region);
89 extern struct eh_region *gen_eh_region_cleanup (struct eh_region *, 260 extern eh_region gen_eh_region_try (eh_region);
90 struct eh_region *); 261 extern eh_region gen_eh_region_allowed (eh_region, tree);
91 extern struct eh_region *gen_eh_region_try (struct eh_region *); 262 extern eh_region gen_eh_region_must_not_throw (eh_region);
92 extern struct eh_region *gen_eh_region_catch (struct eh_region *, tree); 263
93 extern struct eh_region *gen_eh_region_allowed (struct eh_region *, tree); 264 extern eh_catch gen_eh_region_catch (eh_region, tree);
94 extern struct eh_region *gen_eh_region_must_not_throw (struct eh_region *); 265 extern eh_landing_pad gen_eh_landing_pad (eh_region);
95 extern int get_eh_region_number (struct eh_region *); 266
96 extern bool get_eh_region_may_contain_throw (struct eh_region *); 267 extern eh_region get_eh_region_from_number_fn (struct function *, int);
97 extern tree get_eh_region_tree_label (struct eh_region *); 268 extern eh_region get_eh_region_from_number (int);
98 extern void set_eh_region_tree_label (struct eh_region *, tree); 269 extern eh_landing_pad get_eh_landing_pad_from_number_fn (struct function*,int);
99 270 extern eh_landing_pad get_eh_landing_pad_from_number (int);
100 extern void foreach_reachable_handler (int, bool, 271 extern eh_region get_eh_region_from_lp_number_fn (struct function *, int);
101 void (*) (struct eh_region *, void *), 272 extern eh_region get_eh_region_from_lp_number (int);
102 void *); 273
103 274 extern eh_region eh_region_outermost (struct function *, eh_region, eh_region);
104 extern void collect_eh_region_array (void); 275
105 extern void expand_resx_expr (tree); 276 extern void make_reg_eh_region_note (rtx insn, int ecf_flags, int lp_nr);
277 extern void make_reg_eh_region_note_nothrow_nononlocal (rtx);
278
106 extern void verify_eh_tree (struct function *); 279 extern void verify_eh_tree (struct function *);
107 extern void dump_eh_tree (FILE *, struct function *); 280 extern void dump_eh_tree (FILE *, struct function *);
108 extern bool eh_region_outer_p (struct function *, int, int); 281 void debug_eh_tree (struct function *);
109 extern int eh_region_outermost (struct function *, int, int); 282 extern void add_type_for_runtime (tree);
110 283 extern tree lookup_type_for_runtime (tree);
111 /* If non-NULL, this is a function that returns an expression to be 284 extern void assign_filter_values (void);
285
286 extern eh_region get_eh_region_from_rtx (const_rtx);
287 extern eh_landing_pad get_eh_landing_pad_from_rtx (const_rtx);
288
289 /* If non-NULL, this is a function that returns a function decl to be
112 executed if an unhandled exception is propagated out of a cleanup 290 executed if an unhandled exception is propagated out of a cleanup
113 region. For example, in C++, an exception thrown by a destructor 291 region. For example, in C++, an exception thrown by a destructor
114 during stack unwinding is required to result in a call to 292 during stack unwinding is required to result in a call to
115 `std::terminate', so the C++ version of this function returns a 293 `std::terminate', so the C++ version of this function returns a
116 CALL_EXPR for `std::terminate'. */ 294 FUNCTION_DECL for `std::terminate'. */
117 extern gimple (*lang_protect_cleanup_actions) (void); 295 extern tree (*lang_protect_cleanup_actions) (void);
118 296
119 /* Return true if type A catches type B. */ 297 /* Return true if type A catches type B. */
120 extern int (*lang_eh_type_covers) (tree a, tree b); 298 extern int (*lang_eh_type_covers) (tree a, tree b);
121
122 /* Map a type to a runtime object to match type. */
123 extern tree (*lang_eh_runtime_type) (tree);
124 299
125 300
126 /* Just because the user configured --with-sjlj-exceptions=no doesn't 301 /* Just because the user configured --with-sjlj-exceptions=no doesn't
127 mean that we can use call frame exceptions. Detect that the target 302 mean that we can use call frame exceptions. Detect that the target
128 has appropriate support. */ 303 has appropriate support. */
164 # endif 339 # endif
165 #else 340 #else
166 # define USING_SJLJ_EXCEPTIONS MUST_USE_SJLJ_EXCEPTIONS 341 # define USING_SJLJ_EXCEPTIONS MUST_USE_SJLJ_EXCEPTIONS
167 #endif 342 #endif
168 343
169 struct throw_stmt_node GTY(()) 344 struct GTY(()) throw_stmt_node {
170 {
171 gimple stmt; 345 gimple stmt;
172 int region_nr; 346 int lp_nr;
173 }; 347 };
174 348
175 extern struct htab *get_eh_throw_stmt_table (struct function *); 349 extern struct htab *get_eh_throw_stmt_table (struct function *);
176 extern void set_eh_throw_stmt_table (struct function *, struct htab *); 350 extern void set_eh_throw_stmt_table (struct function *, struct htab *);
351
352 enum eh_personality_kind {
353 eh_personality_none,
354 eh_personality_any,
355 eh_personality_lang
356 };
357
358 extern enum eh_personality_kind
359 function_needs_eh_personality (struct function *);
360
361 /* Pre-order iteration within the eh_region tree. */
362
363 static inline eh_region
364 ehr_next (eh_region r, eh_region start)
365 {
366 if (r->inner)
367 r = r->inner;
368 else if (r->next_peer && r != start)
369 r = r->next_peer;
370 else
371 {
372 do
373 {
374 r = r->outer;
375 if (r == start)
376 return NULL;
377 }
378 while (r->next_peer == NULL);
379 r = r->next_peer;
380 }
381 return r;
382 }
383
384 #define FOR_ALL_EH_REGION_AT(R, START) \
385 for ((R) = (START); (R) != NULL; (R) = ehr_next (R, START))
386
387 #define FOR_ALL_EH_REGION_FN(R, FN) \
388 for ((R) = (FN)->eh->region_tree; (R) != NULL; (R) = ehr_next (R, NULL))
389
390 #define FOR_ALL_EH_REGION(R) FOR_ALL_EH_REGION_FN (R, cfun)