]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/except.h
Finish implementation of VTTs.
[thirdparty/gcc.git] / gcc / except.h
CommitLineData
4956d07c 1/* Exception Handling interface routines.
ef58a523 2 Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
4956d07c
MS
3 Contributed by Mike Stump <mrs@cygnus.com>.
4
5This file is part of GNU CC.
6
7GNU CC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12GNU CC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU CC; see the file COPYING. If not, write to
19the Free Software Foundation, 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA. */
21
d05a5492
MM
22#if !defined(NULL_RTX) && !defined(rtx)
23typedef struct rtx_def *_except_rtx;
24#define rtx _except_rtx
4956d07c
MS
25#endif
26
27#ifdef TREE_CODE
28
911fdd58
RK
29/* A stack of labels. CHAIN points to the next entry in the stack. */
30
4956d07c
MS
31struct label_node {
32 union {
33 rtx rlabel;
34 tree tlabel;
35 } u;
36 struct label_node *chain;
37};
38
911fdd58
RK
39/* An eh_entry is used to describe one exception handling region.
40
478b0752 41 OUTER_CONTEXT is the label used for rethrowing into the outer context.
911fdd58
RK
42
43 EXCEPTION_HANDLER_LABEL is the label corresponding to the handler
44 for this region.
45
9a0d1e1b
AM
46 LABEL_USED indicates whether a CATCH block has already used this
47 label or not. New ones are needed for additional catch blocks if
48 it has.
49
bf71cd2e
AM
50 FALSE_LABEL is used when either setjmp/longjmp exceptions are in
51 use, or old style table exceptions. It contains the label for
52 branching to the next runtime type check as handlers are processed.
53
911fdd58
RK
54 FINALIZATION is the tree codes for the handler, or is NULL_TREE if
55 one hasn't been generated yet, or is integer_zero_node to mark the
56 end of a group of try blocks. */
57
4956d07c 58struct eh_entry {
478b0752 59 rtx outer_context;
4956d07c 60 rtx exception_handler_label;
4956d07c 61 tree finalization;
9a0d1e1b 62 int label_used;
bf71cd2e 63 rtx false_label;
e6cfb550 64 rtx rethrow_label;
1e4ceb6f
MM
65 /* If non-zero, this entry is for a handler created when we left an
66 exception-region via goto. */
67 unsigned goto_entry_p : 1;
4956d07c 68};
b384405b
BS
69#else
70struct label_node;
71struct eh_entry;
72#endif
4956d07c 73
911fdd58
RK
74/* A list of EH_ENTRYs. ENTRY is the entry; CHAIN points to the next
75 entry in the list, or is NULL if this is the last entry. */
76
4956d07c
MS
77struct eh_node {
78 struct eh_entry *entry;
79 struct eh_node *chain;
80};
81
911fdd58
RK
82/* A stack of EH_ENTRYs. TOP is the topmost entry on the stack. TOP is
83 NULL if the stack is empty. */
84
4956d07c
MS
85struct eh_stack {
86 struct eh_node *top;
87};
88
911fdd58
RK
89/* A queue of EH_ENTRYs. HEAD is the front of the queue; TAIL is the
90 end (the latest entry). HEAD and TAIL are NULL if the queue is
91 empty. */
92
4956d07c
MS
93struct eh_queue {
94 struct eh_node *head;
95 struct eh_node *tail;
f54a7f6f 96 struct eh_queue *next;
4956d07c
MS
97};
98
b384405b
BS
99/* Used to save exception handling status for each function. */
100struct eh_status
101{
102 /* A stack used for keeping track of the currently active exception
103 handling region. As each exception region is started, an entry
104 describing the region is pushed onto this stack. The current
105 region can be found by looking at the top of the stack, and as we
106 exit regions, the corresponding entries are popped.
107
108 Entries cannot overlap; they can be nested. So there is only one
109 entry at most that corresponds to the current instruction, and that
110 is the entry on the top of the stack. */
111 struct eh_stack x_ehstack;
112 /* This stack is used to represent what the current eh region is
113 for the catch blocks beings processed */
114 struct eh_stack x_catchstack;
1e4ceb6f 115 /* A queue used for tracking which exception regions have closed.
b384405b 116 As we exit a region, we enqueue a new entry. The entries are then
1e4ceb6f
MM
117 dequeued during expand_leftover_cleanups and
118 expand_start_all_catch. */
f54a7f6f 119 struct eh_queue *x_ehqueue;
b384405b
BS
120 /* Insns for all of the exception handlers for the current function.
121 They are currently emitted by the frontend code. */
122 rtx x_catch_clauses;
c14f7160
ML
123 /* End of exception handler insn sequence. */
124 rtx x_catch_clauses_last;
b384405b
BS
125 /* A random data area for the front end's own use. */
126 struct label_node *x_false_label_stack;
127 /* Keeps track of the label to resume to should one want to resume
128 normal control flow out of a handler (instead of, say, returning to
129 the caller of the current function or exiting the program). */
130 struct label_node *x_caught_return_label_stack;
76fc91c7
MM
131 /* A stack (TREE_LIST) of lists of handlers. The TREE_VALUE of each
132 node is itself a TREE_CHAINed list of handlers for regions that
133 are not yet closed. The TREE_VALUE of each entry contains the
134 handler for the corresponding entry on the ehstack. */
b384405b
BS
135 union tree_node *x_protect_list;
136 /* The EH context. Nonzero if the function has already
137 fetched a pointer to the EH context for exception handling. */
138 rtx ehc;
139 /* The label generated by expand_builtin_eh_return. */
140 rtx x_eh_return_stub_label;
141};
142
01d939e8
BS
143#define ehstack (cfun->eh->x_ehstack)
144#define catchstack (cfun->eh->x_catchstack)
145#define ehqueue (cfun->eh->x_ehqueue)
146#define catch_clauses (cfun->eh->x_catch_clauses)
c14f7160 147#define catch_clauses_last (cfun->eh->x_catch_clauses_last)
01d939e8
BS
148#define false_label_stack (cfun->eh->x_false_label_stack)
149#define caught_return_label_stack (cfun->eh->x_caught_return_label_stack)
150#define protect_list (cfun->eh->x_protect_list)
151#define current_function_ehc (cfun->eh->ehc)
152#define eh_return_stub_label (cfun->eh->x_eh_return_stub_label)
b384405b
BS
153
154#ifdef TREE_CODE
e976b8b2
MS
155/* Start an exception handling region. All instructions emitted after
156 this point are considered to be part of the region until
157 expand_eh_region_end () is invoked. */
158
711d877c 159extern void expand_eh_region_start PARAMS ((void));
911fdd58 160
4c581243
MS
161/* Just like expand_eh_region_start, except if a cleanup action is
162 entered on the cleanup chain, the TREE_PURPOSE of the element put
163 on the chain is DECL. DECL should be the associated VAR_DECL, if
164 any, otherwise it should be NULL_TREE. */
165
711d877c 166extern void expand_eh_region_start_for_decl PARAMS ((tree));
4c581243 167
e976b8b2
MS
168/* Start an exception handling region for the given cleanup action.
169 All instructions emitted after this point are considered to be part
170 of the region until expand_eh_region_end () is invoked. CLEANUP is
171 the cleanup action to perform. The return value is true if the
172 exception region was optimized away. If that case,
173 expand_eh_region_end does not need to be called for this cleanup,
174 nor should it be.
175
176 This routine notices one particular common case in C++ code
177 generation, and optimizes it so as to not need the exception
178 region. */
179
711d877c 180extern int expand_eh_region_start_tree PARAMS ((tree, tree));
e976b8b2
MS
181
182/* End an exception handling region. The information about the region
183 is found on the top of ehstack.
184
185 HANDLER is either the cleanup for the exception region, or if we're
186 marking the end of a try block, HANDLER is integer_zero_node.
187
188 HANDLER will be transformed to rtl when expand_leftover_cleanups ()
189 is invoked. */
190
711d877c 191extern void expand_eh_region_end PARAMS ((tree));
911fdd58
RK
192
193/* Push RLABEL or TLABEL onto LABELSTACK. Only one of RLABEL or TLABEL
194 should be set; the other must be NULL. */
195
711d877c
KG
196extern void push_label_entry PARAMS ((struct label_node **labelstack,
197 rtx rlabel, tree tlabel));
911fdd58
RK
198
199/* Pop the topmost entry from LABELSTACK and return its value as an
200 rtx node. If LABELSTACK is empty, return NULL. */
201
711d877c 202extern rtx pop_label_entry PARAMS ((struct label_node **labelstack));
911fdd58
RK
203
204/* Return the topmost entry of LABELSTACK as a tree node, or return
205 NULL_TREE if LABELSTACK is empty. */
206
711d877c 207extern tree top_label_entry PARAMS ((struct label_node **labelstack));
4956d07c 208
4956d07c
MS
209#endif
210
d6f4ec51
KG
211/* Test: is exception handling turned on? */
212
711d877c 213extern int doing_eh PARAMS ((int));
d6f4ec51 214
911fdd58
RK
215/* Toplevel initialization for EH. */
216
711d877c
KG
217void set_exception_lang_code PARAMS ((int));
218void set_exception_version_code PARAMS ((int));
9a0d1e1b 219
9a0d1e1b
AM
220/* A list of handlers asocciated with an exception region. HANDLER_LABEL
221 is the the label that control should be transfered to if the data
222 in TYPE_INFO matches an exception. a value of NULL_TREE for TYPE_INFO
223 means This is a cleanup, and must always be called. A value of
224 CATCH_ALL_TYPE works like a cleanup, but a call to the runtime matcher
225 is still performed to avoid being caught by a different language
226 exception. NEXT is a pointer to the next handler for this region.
227 NULL means there are no more. */
228
9a0d1e1b
AM
229typedef struct handler_info
230{
0177de87
AM
231 rtx handler_label;
232 int handler_number;
9a0d1e1b
AM
233 void *type_info;
234 struct handler_info *next;
235} handler_info;
236
237
9a0d1e1b
AM
238/* Add new handler information to an exception range. The first parameter
239 specifies the range number (returned from new_eh_entry()). The second
240 parameter specifies the handler. By default the handler is inserted at
241 the end of the list. A handler list may contain only ONE NULL_TREE
242 typeinfo entry. Regardless where it is positioned, a NULL_TREE entry
243 is always output as the LAST handler in the exception table for a region. */
244
711d877c 245void add_new_handler PARAMS ((int, struct handler_info *));
9a0d1e1b 246
9f8e6243
AM
247/* Remove a handler label. The handler label is being deleted, so all
248 regions which reference this handler should have it removed from their
249 list of possible handlers. Any region which has the final handler
250 removed can be deleted. */
251
711d877c 252void remove_handler PARAMS ((rtx));
9f8e6243 253
9a0d1e1b
AM
254/* Create a new handler structure initialized with the handler label and
255 typeinfo fields passed in. */
256
711d877c 257struct handler_info *get_new_handler PARAMS ((rtx, void *));
9a0d1e1b
AM
258
259/* Make a duplicate of an exception region by copying all the handlers
260 for an exception region. Return the new handler index. */
261
711d877c 262int duplicate_eh_handlers PARAMS ((int, int, rtx (*)(rtx)));
e6cfb550
AM
263
264/* map symbol refs for rethrow */
265
711d877c 266rtx rethrow_symbol_map PARAMS ((rtx, rtx (*)(rtx)));
e6cfb550
AM
267
268/* Is the rethrow label for a region used? */
269
711d877c 270int rethrow_used PARAMS ((int));
e6cfb550 271
1ef1bf06
AM
272/* Update the rethrow references to reflect rethrows which have been
273 optimized away. */
274
711d877c 275void update_rethrow_references PARAMS ((void));
1ef1bf06 276
9a0d1e1b
AM
277/* Get a pointer to the first handler in an exception region's list. */
278
711d877c 279struct handler_info *get_first_handler PARAMS ((int));
9a0d1e1b 280
9c606f69
AM
281/* Find all the runtime handlers type matches currently referenced */
282
711d877c 283int find_all_handler_type_matches PARAMS ((void ***));
9a0d1e1b 284
1ef1bf06
AM
285/* The eh_nesting_info structure is used to find a list of valid handlers
286 for any arbitrary exception region. When init_eh_nesting_info is called,
287 the information is all pre-calculated and entered in this structure.
288 REGION_INDEX is a vector over all possible region numbers. Since the
289 number of regions is typically much smaller than the range of block
290 numbers, this is a sparse vector and the other data structures are
291 represented as dense vectors. Indexed with an exception region number, this
292 returns the index to use in the other data structures to retreive the
293 correct information.
294 HANDLERS is an array of vectors which point to handler_info structures.
295 when indexed, it gives the list of all possible handlers which can
296 be reached by a throw from this exception region.
297 NUM_HANDLERS is the equivilent array indicating how many handler
298 pointers there are in the HANDLERS vector.
299 OUTER_INDEX indicates which index represents the information for the
300 outer block. 0 indicates there is no outer context.
301 REGION_COUNT is the number of regions. */
302
303typedef struct eh_nesting
304{
305 int *region_index;
306 handler_info ***handlers;
307 int *num_handlers;
308 int *outer_index;
309 int region_count;
310} eh_nesting_info;
311
312/* Initialize the eh_nesting_info structure. */
313
711d877c 314eh_nesting_info *init_eh_nesting_info PARAMS ((void));
1ef1bf06
AM
315
316/* Get a list of handlers reachable from a an exception region/insn. */
317
711d877c
KG
318int reachable_handlers PARAMS ((int, eh_nesting_info *, rtx,
319 handler_info ***handlers));
1ef1bf06
AM
320
321/* Free the eh_nesting_info structure. */
322
711d877c 323void free_eh_nesting_info PARAMS ((eh_nesting_info *));
1ef1bf06 324
711d877c 325extern void init_eh PARAMS ((void));
911fdd58
RK
326
327/* Initialization for the per-function EH data. */
328
711d877c 329extern void init_eh_for_function PARAMS ((void));
911fdd58 330
9a0d1e1b
AM
331/* Generate an exception label. Use instead of gen_label_rtx */
332
711d877c 333extern rtx gen_exception_label PARAMS ((void));
9a0d1e1b 334
911fdd58
RK
335/* Adds an EH table entry for EH entry number N. Called from
336 final_scan_insn for NOTE_INSN_EH_REGION_BEG. */
337
711d877c 338extern void add_eh_table_entry PARAMS ((int n));
911fdd58 339
9a0d1e1b
AM
340/* Start a catch clause, triggered by runtime value paramter. */
341
342#ifdef TREE_CODE
711d877c 343extern void start_catch_handler PARAMS ((tree));
9a0d1e1b
AM
344#endif
345
bf71cd2e
AM
346/* End an individual catch clause. */
347
711d877c 348extern void end_catch_handler PARAMS ((void));
bf71cd2e 349
911fdd58
RK
350/* Returns a non-zero value if we need to output an exception table. */
351
711d877c 352extern int exception_table_p PARAMS ((void));
911fdd58
RK
353
354/* Outputs the exception table if we have one. */
355
711d877c 356extern void output_exception_table PARAMS ((void));
911fdd58 357
ce152ef8
AM
358/* Free the exception table. */
359
360extern void free_exception_table PARAMS((void));
361
362/* Used by the ia64 unwind format to output data for an individual
363 function. */
364
365extern void output_function_exception_table PARAMS((void));
366
911fdd58
RK
367/* Given a return address in ADDR, determine the address we should use
368 to find the corresponding EH region. */
369
711d877c 370extern rtx eh_outer_context PARAMS ((rtx addr));
911fdd58
RK
371
372/* Called at the start of a block of try statements for which there is
373 a supplied catch handler. */
374
711d877c 375extern void expand_start_try_stmts PARAMS ((void));
911fdd58
RK
376
377/* Called at the start of a block of catch statements. It terminates the
378 previous set of try statements. */
379
711d877c 380extern void expand_start_all_catch PARAMS ((void));
911fdd58
RK
381
382/* Called at the end of a block of catch statements. */
383
711d877c 384extern void expand_end_all_catch PARAMS ((void));
911fdd58 385
76fc91c7
MM
386/* Begin a region that will contain entries created with
387 add_partial_entry. */
388
711d877c 389extern void begin_protect_partials PARAMS ((void));
76fc91c7 390
911fdd58
RK
391#ifdef TREE_CODE
392/* Create a new exception region and add the handler for the region
393 onto a list. These regions will be ended (and their handlers
394 emitted) when end_protect_partials is invoked. */
395
711d877c 396extern void add_partial_entry PARAMS ((tree handler));
911fdd58
RK
397#endif
398
399/* End all of the pending exception regions that have handlers added with
400 push_protect_entry (). */
401
711d877c 402extern void end_protect_partials PARAMS ((void));
911fdd58 403
e701eb4d 404/* An internal throw. */
911fdd58 405
711d877c 406extern void expand_internal_throw PARAMS ((void));
911fdd58
RK
407
408/* Called from expand_exception_blocks and expand_end_catch_block to
409 expand and pending handlers. */
410
711d877c 411extern void expand_leftover_cleanups PARAMS ((void));
911fdd58 412
154bba13
TT
413/* If necessary, emit insns to get EH context for the current
414 function. */
415
711d877c 416extern void emit_eh_context PARAMS ((void));
154bba13 417
911fdd58
RK
418/* Builds a list of handler labels and puts them in the global
419 variable exception_handler_labels. */
420
711d877c 421extern void find_exception_handler_labels PARAMS ((void));
911fdd58 422
9a0d1e1b
AM
423/* Determine if an arbitrary label is an exception label */
424
711d877c 425extern int is_exception_handler_label PARAMS ((int));
9a0d1e1b 426
911fdd58
RK
427/* Performs sanity checking on the check_exception_handler_labels
428 list. */
429
711d877c 430extern void check_exception_handler_labels PARAMS ((void));
911fdd58 431
956d6950
JL
432/* Keeps track of the label used as the context of a throw to rethrow an
433 exception to the outer exception region. */
434
435extern struct label_node *outer_context_label_stack;
436
911fdd58
RK
437/* A list of labels used for exception handlers. It is created by
438 find_exception_handler_labels for the optimization passes. */
439
4956d07c
MS
440extern rtx exception_handler_labels;
441
fb13d4d0
JM
442/* Return nonzero if nothing in this function can throw. */
443
444extern int nothrow_function_p PARAMS ((void));
445
911fdd58
RK
446/* Performs optimizations for exception handling, such as removing
447 unnecessary exception regions. Invoked from jump_optimize (). */
448
711d877c 449extern void exception_optimize PARAMS ((void));
e976b8b2 450
01eb7f9a 451/* Return EH context (and set it up once per fn). */
711d877c 452extern rtx get_eh_context PARAMS ((void));
154bba13 453
e976b8b2 454/* Get the dynamic handler chain. */
711d877c 455extern rtx get_dynamic_handler_chain PARAMS ((void));
e976b8b2
MS
456
457/* Get the dynamic cleanup chain. */
711d877c 458extern rtx get_dynamic_cleanup_chain PARAMS ((void));
e976b8b2
MS
459
460/* Throw an exception. */
461
711d877c 462extern void emit_throw PARAMS ((void));
e976b8b2 463
f54a7f6f 464/* Save away the current ehqueue. */
711d877c 465extern void push_ehqueue PARAMS ((void));
f54a7f6f
MM
466
467/* Restore a previously pushed ehqueue. */
711d877c 468extern void pop_ehqueue PARAMS ((void));
f54a7f6f 469
e976b8b2
MS
470/* One to use setjmp/longjmp method of generating code. */
471
472extern int exceptions_via_longjmp;
473
474/* One to enable asynchronous exception support. */
475
476extern int asynchronous_exceptions;
477
478/* One to protect cleanup actions with a handler that calls
479 __terminate, zero otherwise. */
480
481extern int protect_cleanup_actions_with_terminate;
482
483#ifdef TREE_CODE
711d877c 484extern tree protect_with_terminate PARAMS ((tree));
e976b8b2 485#endif
0021b564 486
711d877c 487extern void expand_fixup_region_start PARAMS ((void));
487a6e06 488#ifdef TREE_CODE
711d877c 489extern void expand_fixup_region_end PARAMS ((tree));
487a6e06
KG
490#endif
491
0021b564
JM
492/* Various hooks for the DWARF 2 __throw routine. */
493
711d877c
KG
494void expand_builtin_unwind_init PARAMS ((void));
495rtx expand_builtin_dwarf_fp_regnum PARAMS ((void));
0021b564 496#ifdef TREE_CODE
711d877c
KG
497rtx expand_builtin_frob_return_addr PARAMS ((tree));
498rtx expand_builtin_extract_return_addr PARAMS ((tree));
499void expand_builtin_init_dwarf_reg_sizes PARAMS ((tree));
500void expand_builtin_eh_return PARAMS ((tree, tree, tree));
0021b564 501#endif
711d877c 502void expand_eh_return PARAMS ((void));
5aa55043
AM
503
504
505/* Checking whether 2 instructions are within the same exception region. */
506
711d877c
KG
507int in_same_eh_region PARAMS ((rtx, rtx));
508void free_insn_eh_region PARAMS ((void));
509void init_insn_eh_region PARAMS ((rtx, int));
d05a5492
MM
510
511#ifdef rtx
512#undef rtx
513#endif