OSDN Git Service

2009-05-06 Javier Miranda <miranda@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / except.h
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>.
5
6 This file is part of GCC.
7
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.
12
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.
17
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/>.  */
21
22 #include "sbitmap.h"
23 #include "vecprim.h"
24
25 struct function;
26
27 /* Describes one exception region.  */
28 struct GTY(()) eh_region
29 {
30   /* The immediately surrounding region.  */
31   struct eh_region *outer;
32
33   /* The list of immediately contained regions.  */
34   struct eh_region *inner;
35   struct eh_region *next_peer;
36
37   /* List of regions sharing label.  */
38   struct eh_region *next_region_sharing_label;
39
40   /* An identifier for this region.  */
41   int region_number;
42
43   /* When a region is deleted, its parents inherit the REG_EH_REGION
44      numbers already assigned.  */
45   bitmap aka;
46
47   /* Each region does exactly one thing.  */
48   enum eh_region_type
49   {
50     ERT_UNKNOWN = 0,
51     ERT_CLEANUP,
52     ERT_TRY,
53     ERT_CATCH,
54     ERT_ALLOWED_EXCEPTIONS,
55     ERT_MUST_NOT_THROW,
56     ERT_THROW
57   } type;
58
59   /* Holds the action to perform based on the preceding type.  */
60   union eh_region_u {
61     /* A list of catch blocks, a surrounding try block,
62        and the label for continuing after a catch.  */
63     struct eh_region_u_try {
64       struct eh_region *eh_catch;
65       struct eh_region *last_catch;
66     } GTY ((tag ("ERT_TRY"))) eh_try;
67
68     /* The list through the catch handlers, the list of type objects
69        matched, and the list of associated filters.  */
70     struct eh_region_u_catch {
71       struct eh_region *next_catch;
72       struct eh_region *prev_catch;
73       tree type_list;
74       tree filter_list;
75     } GTY ((tag ("ERT_CATCH"))) eh_catch;
76
77     /* A tree_list of allowed types.  */
78     struct eh_region_u_allowed {
79       tree type_list;
80       int filter;
81     } GTY ((tag ("ERT_ALLOWED_EXCEPTIONS"))) allowed;
82
83     /* The type given by a call to "throw foo();", or discovered
84        for a throw.  */
85     struct eh_region_u_throw {
86       tree type;
87     } GTY ((tag ("ERT_THROW"))) eh_throw;
88
89     /* Retain the cleanup expression even after expansion so that
90        we can match up fixup regions.  */
91     struct eh_region_u_cleanup {
92       struct eh_region *prev_try;
93     } GTY ((tag ("ERT_CLEANUP"))) cleanup;
94   } GTY ((desc ("%0.type"))) u;
95
96   /* Entry point for this region's handler before landing pads are built.  */
97   rtx label;
98   tree tree_label;
99
100   /* Entry point for this region's handler from the runtime eh library.  */
101   rtx landing_pad;
102
103   /* Entry point for this region's handler from an inner region.  */
104   rtx post_landing_pad;
105
106   /* The RESX insn for handing off control to the next outermost handler,
107      if appropriate.  */
108   rtx resume;
109
110   /* True if something in this region may throw.  */
111   unsigned may_contain_throw : 1;
112 };
113
114 typedef struct eh_region *eh_region;
115 DEF_VEC_P(eh_region);
116 DEF_VEC_ALLOC_P(eh_region, gc);
117 DEF_VEC_ALLOC_P(eh_region, heap);
118
119 /* Per-function EH data.  Used to save exception status for each
120    function.  */
121 struct GTY(()) eh_status
122 {
123   /* The tree of all regions for this function.  */
124   struct eh_region *region_tree;
125
126   /* The same information as an indexable array.  */
127   VEC(eh_region,gc) *region_array;
128   int last_region_number;
129
130   htab_t GTY((param_is (struct throw_stmt_node))) throw_stmt_table;
131 };
132
133
134 /* Test: is exception handling turned on?  */
135 extern int doing_eh (int);
136
137 /* Note that the current EH region (if any) may contain a throw, or a
138    call to a function which itself may contain a throw.  */
139 extern void note_eh_region_may_contain_throw (struct eh_region *);
140
141 /* Invokes CALLBACK for every exception handler label.  Only used by old
142    loop hackery; should not be used by new code.  */
143 extern void for_each_eh_label (void (*) (rtx));
144
145 /* Invokes CALLBACK for every exception region in the current function.  */
146 extern void for_each_eh_region (void (*) (struct eh_region *));
147
148 /* Determine if the given INSN can throw an exception.  */
149 extern bool can_throw_internal_1 (int, bool, bool);
150 extern bool can_throw_internal (const_rtx);
151 extern bool can_throw_external_1 (int, bool, bool);
152 extern bool can_throw_external (const_rtx);
153
154 /* Set TREE_NOTHROW and cfun->all_throwers_are_sibcalls.  */
155 extern unsigned int set_nothrow_function_flags (void);
156
157 extern void init_eh (void);
158 extern void init_eh_for_function (void);
159
160 extern rtx reachable_handlers (rtx);
161 extern void remove_eh_region (int);
162 extern void remove_eh_region_and_replace_by_outer_of (int, int);
163
164 extern void convert_from_eh_region_ranges (void);
165 extern unsigned int convert_to_eh_region_ranges (void);
166 extern void find_exception_handler_labels (void);
167 extern bool current_function_has_exception_handlers (void);
168 extern void output_function_exception_table (const char *);
169
170 extern void expand_builtin_unwind_init (void);
171 extern rtx expand_builtin_eh_return_data_regno (tree);
172 extern rtx expand_builtin_extract_return_addr (tree);
173 extern void expand_builtin_init_dwarf_reg_sizes (tree);
174 extern rtx expand_builtin_frob_return_addr (tree);
175 extern rtx expand_builtin_dwarf_sp_column (void);
176 extern void expand_builtin_eh_return (tree, tree);
177 extern void expand_eh_return (void);
178 extern rtx expand_builtin_extend_pointer (tree);
179 extern rtx get_exception_pointer (void);
180 extern rtx get_exception_filter (void);
181 typedef tree (*duplicate_eh_regions_map) (tree, void *);
182 extern int duplicate_eh_regions (struct function *, duplicate_eh_regions_map,
183                                  void *, int, int);
184
185 extern void sjlj_emit_function_exit_after (rtx);
186 extern void default_init_unwind_resume_libfunc (void);
187
188 extern struct eh_region *gen_eh_region_cleanup (struct eh_region *,
189                                                 struct eh_region *);
190 extern struct eh_region *gen_eh_region_try (struct eh_region *);
191 extern struct eh_region *gen_eh_region_catch (struct eh_region *, tree);
192 extern struct eh_region *gen_eh_region_allowed (struct eh_region *, tree);
193 extern struct eh_region *gen_eh_region_must_not_throw (struct eh_region *);
194 extern int get_eh_region_number (struct eh_region *);
195 extern bool get_eh_region_may_contain_throw (struct eh_region *);
196 extern tree get_eh_region_no_tree_label (int);
197 extern tree get_eh_region_tree_label (struct eh_region *);
198 extern void set_eh_region_tree_label (struct eh_region *, tree);
199
200 extern void foreach_reachable_handler (int, bool, bool,
201                                        void (*) (struct eh_region *, void *),
202                                        void *);
203
204 extern void collect_eh_region_array (void);
205 extern void expand_resx_expr (tree);
206 extern void verify_eh_tree (struct function *);
207 extern void dump_eh_tree (FILE *, struct function *);
208 void debug_eh_tree (struct function *);
209 extern int eh_region_outermost (struct function *, int, int);
210 extern void add_type_for_runtime (tree);
211 extern tree lookup_type_for_runtime (tree);
212
213 /* If non-NULL, this is a function that returns an expression to be
214    executed if an unhandled exception is propagated out of a cleanup
215    region.  For example, in C++, an exception thrown by a destructor
216    during stack unwinding is required to result in a call to
217    `std::terminate', so the C++ version of this function returns a
218    CALL_EXPR for `std::terminate'.  */
219 extern gimple (*lang_protect_cleanup_actions) (void);
220
221 /* Return true if type A catches type B.  */
222 extern int (*lang_eh_type_covers) (tree a, tree b);
223
224 /* Map a type to a runtime object to match type.  */
225 extern tree (*lang_eh_runtime_type) (tree);
226
227
228 /* Just because the user configured --with-sjlj-exceptions=no doesn't
229    mean that we can use call frame exceptions.  Detect that the target
230    has appropriate support.  */
231
232 #ifndef MUST_USE_SJLJ_EXCEPTIONS
233 # if defined (EH_RETURN_DATA_REGNO)                     \
234        && (defined (TARGET_UNWIND_INFO)                 \
235            || (DWARF2_UNWIND_INFO                       \
236                && (defined (EH_RETURN_HANDLER_RTX)      \
237                    || defined (HAVE_eh_return))))
238 #  define MUST_USE_SJLJ_EXCEPTIONS      0
239 # else
240 #  define MUST_USE_SJLJ_EXCEPTIONS      1
241 # endif
242 #endif
243
244 #ifdef CONFIG_SJLJ_EXCEPTIONS
245 # if CONFIG_SJLJ_EXCEPTIONS == 1
246 #  define USING_SJLJ_EXCEPTIONS         1
247 # endif
248 # if CONFIG_SJLJ_EXCEPTIONS == 0
249 #  define USING_SJLJ_EXCEPTIONS         0
250 #  if !defined(EH_RETURN_DATA_REGNO)
251     #error "EH_RETURN_DATA_REGNO required"
252 #  endif
253 #  if ! (defined(TARGET_UNWIND_INFO) || DWARF2_UNWIND_INFO)
254     #error "{DWARF2,TARGET}_UNWIND_INFO required"
255 #  endif
256 #  if !defined(TARGET_UNWIND_INFO) \
257         && !(defined(EH_RETURN_HANDLER_RTX) || defined(HAVE_eh_return))
258     #error "EH_RETURN_HANDLER_RTX or eh_return required"
259 #  endif
260 /* Usually the above error checks will have already triggered an
261    error, but backends may set MUST_USE_SJLJ_EXCEPTIONS for their own
262    reasons.  */
263 #  if MUST_USE_SJLJ_EXCEPTIONS
264     #error "Must use SJLJ exceptions but configured not to"
265 #  endif
266 # endif
267 #else
268 # define USING_SJLJ_EXCEPTIONS          MUST_USE_SJLJ_EXCEPTIONS
269 #endif
270
271 struct GTY(()) throw_stmt_node {
272   gimple stmt;
273   int region_nr;
274 };
275
276 extern struct htab *get_eh_throw_stmt_table (struct function *);
277 extern void set_eh_throw_stmt_table (struct function *, struct htab *);
278 extern void remove_unreachable_regions (sbitmap, sbitmap);
279 extern VEC(int,heap) * label_to_region_map (void);
280 extern int num_eh_regions (void);
281 extern struct eh_region *redirect_eh_edge_to_label (struct edge_def *, tree, bool, bool, int);
282 extern int get_next_region_sharing_label (int);