1 /* Implements exception handling.
2 Copyright (C) 1989-2015 Free Software Foundation, Inc.
3 Contributed by Mike Stump <mrs@cygnus.com>.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
22 /* An exception is an event that can be "thrown" from within a
23 function. This event can then be "caught" by the callers of
26 The representation of exceptions changes several times during
27 the compilation process:
29 In the beginning, in the front end, we have the GENERIC trees
30 TRY_CATCH_EXPR, TRY_FINALLY_EXPR, WITH_CLEANUP_EXPR,
31 CLEANUP_POINT_EXPR, CATCH_EXPR, and EH_FILTER_EXPR.
33 During initial gimplification (gimplify.c) these are lowered
34 to the GIMPLE_TRY, GIMPLE_CATCH, and GIMPLE_EH_FILTER nodes.
35 The WITH_CLEANUP_EXPR and CLEANUP_POINT_EXPR nodes are converted
36 into GIMPLE_TRY_FINALLY nodes; the others are a more direct 1-1
39 During pass_lower_eh (tree-eh.c) we record the nested structure
40 of the TRY nodes in EH_REGION nodes in CFUN->EH->REGION_TREE.
41 We expand the eh_protect_cleanup_actions langhook into MUST_NOT_THROW
42 regions at this time. We can then flatten the statements within
43 the TRY nodes to straight-line code. Statements that had been within
44 TRY nodes that can throw are recorded within CFUN->EH->THROW_STMT_TABLE,
45 so that we may remember what action is supposed to be taken if
46 a given statement does throw. During this lowering process,
47 we create an EH_LANDING_PAD node for each EH_REGION that has
48 some code within the function that needs to be executed if a
49 throw does happen. We also create RESX statements that are
50 used to transfer control from an inner EH_REGION to an outer
51 EH_REGION. We also create EH_DISPATCH statements as placeholders
52 for a runtime type comparison that should be made in order to
53 select the action to perform among different CATCH and EH_FILTER
56 During pass_lower_eh_dispatch (tree-eh.c), which is run after
57 all inlining is complete, we are able to run assign_filter_values,
58 which allows us to map the set of types manipulated by all of the
59 CATCH and EH_FILTER regions to a set of integers. This set of integers
60 will be how the exception runtime communicates with the code generated
61 within the function. We then expand the GIMPLE_EH_DISPATCH statements
62 to a switch or conditional branches that use the argument provided by
63 the runtime (__builtin_eh_filter) and the set of integers we computed
64 in assign_filter_values.
66 During pass_lower_resx (tree-eh.c), which is run near the end
67 of optimization, we expand RESX statements. If the eh region
68 that is outer to the RESX statement is a MUST_NOT_THROW, then
69 the RESX expands to some form of abort statement. If the eh
70 region that is outer to the RESX statement is within the current
71 function, then the RESX expands to a bookkeeping call
72 (__builtin_eh_copy_values) and a goto. Otherwise, the next
73 handler for the exception must be within a function somewhere
74 up the call chain, so we call back into the exception runtime
75 (__builtin_unwind_resume).
77 During pass_expand (cfgexpand.c), we generate REG_EH_REGION notes
78 that create an rtl to eh_region mapping that corresponds to the
79 gimple to eh_region mapping that had been recorded in the
82 Then, via finish_eh_generation, we generate the real landing pads
83 to which the runtime will actually transfer control. These new
84 landing pads perform whatever bookkeeping is needed by the target
85 backend in order to resume execution within the current function.
86 Each of these new landing pads falls through into the post_landing_pad
87 label which had been used within the CFG up to this point. All
88 exception edges within the CFG are redirected to the new landing pads.
89 If the target uses setjmp to implement exceptions, the various extra
90 calls into the runtime to register and unregister the current stack
91 frame are emitted at this time.
93 During pass_convert_to_eh_region_ranges (except.c), we transform
94 the REG_EH_REGION notes attached to individual insns into
95 non-overlapping ranges of insns bounded by NOTE_INSN_EH_REGION_BEG
96 and NOTE_INSN_EH_REGION_END. Each insn within such ranges has the
97 same associated action within the exception region tree, meaning
98 that (1) the exception is caught by the same landing pad within the
99 current function, (2) the exception is blocked by the runtime with
100 a MUST_NOT_THROW region, or (3) the exception is not handled at all
101 within the current function.
103 Finally, during assembly generation, we call
104 output_function_exception_table (except.c) to emit the tables with
105 which the exception runtime can determine if a given stack frame
106 handles a given exception, and if so what filter value to provide
107 to the function when the non-local control transfer is effected.
108 If the target uses dwarf2 unwinding to implement exceptions, then
109 output_call_frame_info (dwarf2out.c) emits the required unwind data. */
114 #include "coretypes.h"
120 #include "fold-const.h"
121 #include "stringpool.h"
122 #include "stor-layout.h"
124 #include "hard-reg-set.h"
125 #include "function.h"
126 #include "insn-codes.h"
128 #include "insn-config.h"
133 #include "emit-rtl.h"
137 #include "libfuncs.h"
140 #include "dwarf2asm.h"
141 #include "dwarf2out.h"
147 #include "common/common-target.h"
148 #include "langhooks.h"
150 #include "dominance.h"
153 #include "basic-block.h"
154 #include "plugin-api.h"
157 #include "diagnostic.h"
158 #include "tree-pretty-print.h"
159 #include "tree-pass.h"
161 #include "builtins.h"
162 #include "tree-hash-traits.h"
164 static GTY(()) int call_site_base
;
166 static GTY (()) hash_map
<tree_hash
, tree
> *type_to_runtime_map
;
168 /* Describe the SjLj_Function_Context structure. */
169 static GTY(()) tree sjlj_fc_type_node
;
170 static int sjlj_fc_call_site_ofs
;
171 static int sjlj_fc_data_ofs
;
172 static int sjlj_fc_personality_ofs
;
173 static int sjlj_fc_lsda_ofs
;
174 static int sjlj_fc_jbuf_ofs
;
177 struct GTY(()) call_site_record_d
183 /* In the following structure and associated functions,
184 we represent entries in the action table as 1-based indices.
187 0: null action record, non-null landing pad; implies cleanups
188 -1: null action record, null landing pad; implies no action
189 -2: no call-site entry; implies must_not_throw
190 -3: we have yet to process outer regions
192 Further, no special cases apply to the "next" field of the record.
193 For next, 0 means end of list. */
202 /* Hashtable helpers. */
204 struct action_record_hasher
: free_ptr_hash
<action_record
>
206 static inline hashval_t
hash (const action_record
*);
207 static inline bool equal (const action_record
*, const action_record
*);
211 action_record_hasher::hash (const action_record
*entry
)
213 return entry
->next
* 1009 + entry
->filter
;
217 action_record_hasher::equal (const action_record
*entry
,
218 const action_record
*data
)
220 return entry
->filter
== data
->filter
&& entry
->next
== data
->next
;
223 typedef hash_table
<action_record_hasher
> action_hash_type
;
225 static bool get_eh_region_and_lp_from_rtx (const_rtx
, eh_region
*,
228 static void dw2_build_landing_pads (void);
230 static int collect_one_action_chain (action_hash_type
*, eh_region
);
231 static int add_call_site (rtx
, int, int);
233 static void push_uleb128 (vec
<uchar
, va_gc
> **, unsigned int);
234 static void push_sleb128 (vec
<uchar
, va_gc
> **, int);
235 #ifndef HAVE_AS_LEB128
236 static int dw2_size_of_call_site_table (int);
237 static int sjlj_size_of_call_site_table (void);
239 static void dw2_output_call_site_table (int, int);
240 static void sjlj_output_call_site_table (void);
246 if (! flag_exceptions
)
249 type_to_runtime_map
= hash_map
<tree_hash
, tree
>::create_ggc (31);
251 /* Create the SjLj_Function_Context structure. This should match
252 the definition in unwind-sjlj.c. */
253 if (targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
)
255 tree f_jbuf
, f_per
, f_lsda
, f_prev
, f_cs
, f_data
, tmp
;
257 sjlj_fc_type_node
= lang_hooks
.types
.make_type (RECORD_TYPE
);
259 f_prev
= build_decl (BUILTINS_LOCATION
,
260 FIELD_DECL
, get_identifier ("__prev"),
261 build_pointer_type (sjlj_fc_type_node
));
262 DECL_FIELD_CONTEXT (f_prev
) = sjlj_fc_type_node
;
264 f_cs
= build_decl (BUILTINS_LOCATION
,
265 FIELD_DECL
, get_identifier ("__call_site"),
267 DECL_FIELD_CONTEXT (f_cs
) = sjlj_fc_type_node
;
269 tmp
= build_index_type (size_int (4 - 1));
270 tmp
= build_array_type (lang_hooks
.types
.type_for_mode
271 (targetm
.unwind_word_mode (), 1),
273 f_data
= build_decl (BUILTINS_LOCATION
,
274 FIELD_DECL
, get_identifier ("__data"), tmp
);
275 DECL_FIELD_CONTEXT (f_data
) = sjlj_fc_type_node
;
277 f_per
= build_decl (BUILTINS_LOCATION
,
278 FIELD_DECL
, get_identifier ("__personality"),
280 DECL_FIELD_CONTEXT (f_per
) = sjlj_fc_type_node
;
282 f_lsda
= build_decl (BUILTINS_LOCATION
,
283 FIELD_DECL
, get_identifier ("__lsda"),
285 DECL_FIELD_CONTEXT (f_lsda
) = sjlj_fc_type_node
;
287 #ifdef DONT_USE_BUILTIN_SETJMP
289 tmp
= size_int (JMP_BUF_SIZE
- 1);
291 /* Should be large enough for most systems, if it is not,
292 JMP_BUF_SIZE should be defined with the proper value. It will
293 also tend to be larger than necessary for most systems, a more
294 optimal port will define JMP_BUF_SIZE. */
295 tmp
= size_int (FIRST_PSEUDO_REGISTER
+ 2 - 1);
298 /* Compute a minimally sized jump buffer. We need room to store at
299 least 3 pointers - stack pointer, frame pointer and return address.
300 Plus for some targets we need room for an extra pointer - in the
301 case of MIPS this is the global pointer. This makes a total of four
302 pointers, but to be safe we actually allocate room for 5.
304 If pointers are smaller than words then we allocate enough room for
305 5 words, just in case the backend needs this much room. For more
306 discussion on this issue see:
307 http://gcc.gnu.org/ml/gcc-patches/2014-05/msg00313.html. */
308 if (POINTER_SIZE
> BITS_PER_WORD
)
309 tmp
= size_int (5 - 1);
311 tmp
= size_int ((5 * BITS_PER_WORD
/ POINTER_SIZE
) - 1);
314 tmp
= build_index_type (tmp
);
315 tmp
= build_array_type (ptr_type_node
, tmp
);
316 f_jbuf
= build_decl (BUILTINS_LOCATION
,
317 FIELD_DECL
, get_identifier ("__jbuf"), tmp
);
318 #ifdef DONT_USE_BUILTIN_SETJMP
319 /* We don't know what the alignment requirements of the
320 runtime's jmp_buf has. Overestimate. */
321 DECL_ALIGN (f_jbuf
) = BIGGEST_ALIGNMENT
;
322 DECL_USER_ALIGN (f_jbuf
) = 1;
324 DECL_FIELD_CONTEXT (f_jbuf
) = sjlj_fc_type_node
;
326 TYPE_FIELDS (sjlj_fc_type_node
) = f_prev
;
327 TREE_CHAIN (f_prev
) = f_cs
;
328 TREE_CHAIN (f_cs
) = f_data
;
329 TREE_CHAIN (f_data
) = f_per
;
330 TREE_CHAIN (f_per
) = f_lsda
;
331 TREE_CHAIN (f_lsda
) = f_jbuf
;
333 layout_type (sjlj_fc_type_node
);
335 /* Cache the interesting field offsets so that we have
336 easy access from rtl. */
337 sjlj_fc_call_site_ofs
338 = (tree_to_uhwi (DECL_FIELD_OFFSET (f_cs
))
339 + tree_to_uhwi (DECL_FIELD_BIT_OFFSET (f_cs
)) / BITS_PER_UNIT
);
341 = (tree_to_uhwi (DECL_FIELD_OFFSET (f_data
))
342 + tree_to_uhwi (DECL_FIELD_BIT_OFFSET (f_data
)) / BITS_PER_UNIT
);
343 sjlj_fc_personality_ofs
344 = (tree_to_uhwi (DECL_FIELD_OFFSET (f_per
))
345 + tree_to_uhwi (DECL_FIELD_BIT_OFFSET (f_per
)) / BITS_PER_UNIT
);
347 = (tree_to_uhwi (DECL_FIELD_OFFSET (f_lsda
))
348 + tree_to_uhwi (DECL_FIELD_BIT_OFFSET (f_lsda
)) / BITS_PER_UNIT
);
350 = (tree_to_uhwi (DECL_FIELD_OFFSET (f_jbuf
))
351 + tree_to_uhwi (DECL_FIELD_BIT_OFFSET (f_jbuf
)) / BITS_PER_UNIT
);
356 init_eh_for_function (void)
358 cfun
->eh
= ggc_cleared_alloc
<eh_status
> ();
360 /* Make sure zero'th entries are used. */
361 vec_safe_push (cfun
->eh
->region_array
, (eh_region
)0);
362 vec_safe_push (cfun
->eh
->lp_array
, (eh_landing_pad
)0);
365 /* Routines to generate the exception tree somewhat directly.
366 These are used from tree-eh.c when processing exception related
367 nodes during tree optimization. */
370 gen_eh_region (enum eh_region_type type
, eh_region outer
)
374 /* Insert a new blank region as a leaf in the tree. */
375 new_eh
= ggc_cleared_alloc
<eh_region_d
> ();
377 new_eh
->outer
= outer
;
380 new_eh
->next_peer
= outer
->inner
;
381 outer
->inner
= new_eh
;
385 new_eh
->next_peer
= cfun
->eh
->region_tree
;
386 cfun
->eh
->region_tree
= new_eh
;
389 new_eh
->index
= vec_safe_length (cfun
->eh
->region_array
);
390 vec_safe_push (cfun
->eh
->region_array
, new_eh
);
392 /* Copy the language's notion of whether to use __cxa_end_cleanup. */
393 if (targetm
.arm_eabi_unwinder
&& lang_hooks
.eh_use_cxa_end_cleanup
)
394 new_eh
->use_cxa_end_cleanup
= true;
400 gen_eh_region_cleanup (eh_region outer
)
402 return gen_eh_region (ERT_CLEANUP
, outer
);
406 gen_eh_region_try (eh_region outer
)
408 return gen_eh_region (ERT_TRY
, outer
);
412 gen_eh_region_catch (eh_region t
, tree type_or_list
)
415 tree type_list
, type_node
;
417 gcc_assert (t
->type
== ERT_TRY
);
419 /* Ensure to always end up with a type list to normalize further
420 processing, then register each type against the runtime types map. */
421 type_list
= type_or_list
;
424 if (TREE_CODE (type_or_list
) != TREE_LIST
)
425 type_list
= tree_cons (NULL_TREE
, type_or_list
, NULL_TREE
);
427 type_node
= type_list
;
428 for (; type_node
; type_node
= TREE_CHAIN (type_node
))
429 add_type_for_runtime (TREE_VALUE (type_node
));
432 c
= ggc_cleared_alloc
<eh_catch_d
> ();
433 c
->type_list
= type_list
;
434 l
= t
->u
.eh_try
.last_catch
;
439 t
->u
.eh_try
.first_catch
= c
;
440 t
->u
.eh_try
.last_catch
= c
;
446 gen_eh_region_allowed (eh_region outer
, tree allowed
)
448 eh_region region
= gen_eh_region (ERT_ALLOWED_EXCEPTIONS
, outer
);
449 region
->u
.allowed
.type_list
= allowed
;
451 for (; allowed
; allowed
= TREE_CHAIN (allowed
))
452 add_type_for_runtime (TREE_VALUE (allowed
));
458 gen_eh_region_must_not_throw (eh_region outer
)
460 return gen_eh_region (ERT_MUST_NOT_THROW
, outer
);
464 gen_eh_landing_pad (eh_region region
)
466 eh_landing_pad lp
= ggc_cleared_alloc
<eh_landing_pad_d
> ();
468 lp
->next_lp
= region
->landing_pads
;
470 lp
->index
= vec_safe_length (cfun
->eh
->lp_array
);
471 region
->landing_pads
= lp
;
473 vec_safe_push (cfun
->eh
->lp_array
, lp
);
479 get_eh_region_from_number_fn (struct function
*ifun
, int i
)
481 return (*ifun
->eh
->region_array
)[i
];
485 get_eh_region_from_number (int i
)
487 return get_eh_region_from_number_fn (cfun
, i
);
491 get_eh_landing_pad_from_number_fn (struct function
*ifun
, int i
)
493 return (*ifun
->eh
->lp_array
)[i
];
497 get_eh_landing_pad_from_number (int i
)
499 return get_eh_landing_pad_from_number_fn (cfun
, i
);
503 get_eh_region_from_lp_number_fn (struct function
*ifun
, int i
)
506 return (*ifun
->eh
->region_array
)[-i
];
512 lp
= (*ifun
->eh
->lp_array
)[i
];
518 get_eh_region_from_lp_number (int i
)
520 return get_eh_region_from_lp_number_fn (cfun
, i
);
523 /* Returns true if the current function has exception handling regions. */
526 current_function_has_exception_handlers (void)
528 return cfun
->eh
->region_tree
!= NULL
;
531 /* A subroutine of duplicate_eh_regions. Copy the eh_region tree at OLD.
532 Root it at OUTER, and apply LP_OFFSET to the lp numbers. */
534 struct duplicate_eh_regions_data
536 duplicate_eh_regions_map label_map
;
537 void *label_map_data
;
538 hash_map
<void *, void *> *eh_map
;
542 duplicate_eh_regions_1 (struct duplicate_eh_regions_data
*data
,
543 eh_region old_r
, eh_region outer
)
545 eh_landing_pad old_lp
, new_lp
;
548 new_r
= gen_eh_region (old_r
->type
, outer
);
549 gcc_assert (!data
->eh_map
->put (old_r
, new_r
));
559 for (oc
= old_r
->u
.eh_try
.first_catch
; oc
; oc
= oc
->next_catch
)
561 /* We should be doing all our region duplication before and
562 during inlining, which is before filter lists are created. */
563 gcc_assert (oc
->filter_list
== NULL
);
564 nc
= gen_eh_region_catch (new_r
, oc
->type_list
);
565 nc
->label
= data
->label_map (oc
->label
, data
->label_map_data
);
570 case ERT_ALLOWED_EXCEPTIONS
:
571 new_r
->u
.allowed
.type_list
= old_r
->u
.allowed
.type_list
;
572 if (old_r
->u
.allowed
.label
)
573 new_r
->u
.allowed
.label
574 = data
->label_map (old_r
->u
.allowed
.label
, data
->label_map_data
);
576 new_r
->u
.allowed
.label
= NULL_TREE
;
579 case ERT_MUST_NOT_THROW
:
580 new_r
->u
.must_not_throw
.failure_loc
=
581 LOCATION_LOCUS (old_r
->u
.must_not_throw
.failure_loc
);
582 new_r
->u
.must_not_throw
.failure_decl
=
583 old_r
->u
.must_not_throw
.failure_decl
;
587 for (old_lp
= old_r
->landing_pads
; old_lp
; old_lp
= old_lp
->next_lp
)
589 /* Don't bother copying unused landing pads. */
590 if (old_lp
->post_landing_pad
== NULL
)
593 new_lp
= gen_eh_landing_pad (new_r
);
594 gcc_assert (!data
->eh_map
->put (old_lp
, new_lp
));
596 new_lp
->post_landing_pad
597 = data
->label_map (old_lp
->post_landing_pad
, data
->label_map_data
);
598 EH_LANDING_PAD_NR (new_lp
->post_landing_pad
) = new_lp
->index
;
601 /* Make sure to preserve the original use of __cxa_end_cleanup. */
602 new_r
->use_cxa_end_cleanup
= old_r
->use_cxa_end_cleanup
;
604 for (old_r
= old_r
->inner
; old_r
; old_r
= old_r
->next_peer
)
605 duplicate_eh_regions_1 (data
, old_r
, new_r
);
608 /* Duplicate the EH regions from IFUN rooted at COPY_REGION into
609 the current function and root the tree below OUTER_REGION.
610 The special case of COPY_REGION of NULL means all regions.
611 Remap labels using MAP/MAP_DATA callback. Return a pointer map
612 that allows the caller to remap uses of both EH regions and
615 hash_map
<void *, void *> *
616 duplicate_eh_regions (struct function
*ifun
,
617 eh_region copy_region
, int outer_lp
,
618 duplicate_eh_regions_map map
, void *map_data
)
620 struct duplicate_eh_regions_data data
;
621 eh_region outer_region
;
623 #ifdef ENABLE_CHECKING
624 verify_eh_tree (ifun
);
627 data
.label_map
= map
;
628 data
.label_map_data
= map_data
;
629 data
.eh_map
= new hash_map
<void *, void *>;
631 outer_region
= get_eh_region_from_lp_number_fn (cfun
, outer_lp
);
633 /* Copy all the regions in the subtree. */
635 duplicate_eh_regions_1 (&data
, copy_region
, outer_region
);
639 for (r
= ifun
->eh
->region_tree
; r
; r
= r
->next_peer
)
640 duplicate_eh_regions_1 (&data
, r
, outer_region
);
643 #ifdef ENABLE_CHECKING
644 verify_eh_tree (cfun
);
650 /* Return the region that is outer to both REGION_A and REGION_B in IFUN. */
653 eh_region_outermost (struct function
*ifun
, eh_region region_a
,
658 gcc_assert (ifun
->eh
->region_array
);
659 gcc_assert (ifun
->eh
->region_tree
);
661 b_outer
= sbitmap_alloc (ifun
->eh
->region_array
->length ());
662 bitmap_clear (b_outer
);
666 bitmap_set_bit (b_outer
, region_b
->index
);
667 region_b
= region_b
->outer
;
673 if (bitmap_bit_p (b_outer
, region_a
->index
))
675 region_a
= region_a
->outer
;
679 sbitmap_free (b_outer
);
684 add_type_for_runtime (tree type
)
686 /* If TYPE is NOP_EXPR, it means that it already is a runtime type. */
687 if (TREE_CODE (type
) == NOP_EXPR
)
690 bool existed
= false;
691 tree
*slot
= &type_to_runtime_map
->get_or_insert (type
, &existed
);
693 *slot
= lang_hooks
.eh_runtime_type (type
);
697 lookup_type_for_runtime (tree type
)
699 /* If TYPE is NOP_EXPR, it means that it already is a runtime type. */
700 if (TREE_CODE (type
) == NOP_EXPR
)
703 /* We should have always inserted the data earlier. */
704 return *type_to_runtime_map
->get (type
);
708 /* Represent an entry in @TTypes for either catch actions
709 or exception filter actions. */
710 struct ttypes_filter
{
715 /* Helper for ttypes_filter hashing. */
717 struct ttypes_filter_hasher
: free_ptr_hash
<ttypes_filter
>
719 typedef tree_node
*compare_type
;
720 static inline hashval_t
hash (const ttypes_filter
*);
721 static inline bool equal (const ttypes_filter
*, const tree_node
*);
724 /* Compare ENTRY (a ttypes_filter entry in the hash table) with DATA
725 (a tree) for a @TTypes type node we are thinking about adding. */
728 ttypes_filter_hasher::equal (const ttypes_filter
*entry
, const tree_node
*data
)
730 return entry
->t
== data
;
734 ttypes_filter_hasher::hash (const ttypes_filter
*entry
)
736 return TREE_HASH (entry
->t
);
739 typedef hash_table
<ttypes_filter_hasher
> ttypes_hash_type
;
742 /* Helper for ehspec hashing. */
744 struct ehspec_hasher
: free_ptr_hash
<ttypes_filter
>
746 static inline hashval_t
hash (const ttypes_filter
*);
747 static inline bool equal (const ttypes_filter
*, const ttypes_filter
*);
750 /* Compare ENTRY with DATA (both struct ttypes_filter) for a @TTypes
751 exception specification list we are thinking about adding. */
752 /* ??? Currently we use the type lists in the order given. Someone
753 should put these in some canonical order. */
756 ehspec_hasher::equal (const ttypes_filter
*entry
, const ttypes_filter
*data
)
758 return type_list_equal (entry
->t
, data
->t
);
761 /* Hash function for exception specification lists. */
764 ehspec_hasher::hash (const ttypes_filter
*entry
)
769 for (list
= entry
->t
; list
; list
= TREE_CHAIN (list
))
770 h
= (h
<< 5) + (h
>> 27) + TREE_HASH (TREE_VALUE (list
));
774 typedef hash_table
<ehspec_hasher
> ehspec_hash_type
;
777 /* Add TYPE (which may be NULL) to cfun->eh->ttype_data, using TYPES_HASH
778 to speed up the search. Return the filter value to be used. */
781 add_ttypes_entry (ttypes_hash_type
*ttypes_hash
, tree type
)
783 struct ttypes_filter
**slot
, *n
;
785 slot
= ttypes_hash
->find_slot_with_hash (type
, (hashval_t
) TREE_HASH (type
),
788 if ((n
= *slot
) == NULL
)
790 /* Filter value is a 1 based table index. */
792 n
= XNEW (struct ttypes_filter
);
794 n
->filter
= vec_safe_length (cfun
->eh
->ttype_data
) + 1;
797 vec_safe_push (cfun
->eh
->ttype_data
, type
);
803 /* Add LIST to cfun->eh->ehspec_data, using EHSPEC_HASH and TYPES_HASH
804 to speed up the search. Return the filter value to be used. */
807 add_ehspec_entry (ehspec_hash_type
*ehspec_hash
, ttypes_hash_type
*ttypes_hash
,
810 struct ttypes_filter
**slot
, *n
;
811 struct ttypes_filter dummy
;
814 slot
= ehspec_hash
->find_slot (&dummy
, INSERT
);
816 if ((n
= *slot
) == NULL
)
820 if (targetm
.arm_eabi_unwinder
)
821 len
= vec_safe_length (cfun
->eh
->ehspec_data
.arm_eabi
);
823 len
= vec_safe_length (cfun
->eh
->ehspec_data
.other
);
825 /* Filter value is a -1 based byte index into a uleb128 buffer. */
827 n
= XNEW (struct ttypes_filter
);
829 n
->filter
= -(len
+ 1);
832 /* Generate a 0 terminated list of filter values. */
833 for (; list
; list
= TREE_CHAIN (list
))
835 if (targetm
.arm_eabi_unwinder
)
836 vec_safe_push (cfun
->eh
->ehspec_data
.arm_eabi
, TREE_VALUE (list
));
839 /* Look up each type in the list and encode its filter
840 value as a uleb128. */
841 push_uleb128 (&cfun
->eh
->ehspec_data
.other
,
842 add_ttypes_entry (ttypes_hash
, TREE_VALUE (list
)));
845 if (targetm
.arm_eabi_unwinder
)
846 vec_safe_push (cfun
->eh
->ehspec_data
.arm_eabi
, NULL_TREE
);
848 vec_safe_push (cfun
->eh
->ehspec_data
.other
, (uchar
)0);
854 /* Generate the action filter values to be used for CATCH and
855 ALLOWED_EXCEPTIONS regions. When using dwarf2 exception regions,
856 we use lots of landing pads, and so every type or list can share
857 the same filter value, which saves table space. */
860 assign_filter_values (void)
866 vec_alloc (cfun
->eh
->ttype_data
, 16);
867 if (targetm
.arm_eabi_unwinder
)
868 vec_alloc (cfun
->eh
->ehspec_data
.arm_eabi
, 64);
870 vec_alloc (cfun
->eh
->ehspec_data
.other
, 64);
872 ehspec_hash_type
ehspec (31);
873 ttypes_hash_type
ttypes (31);
875 for (i
= 1; vec_safe_iterate (cfun
->eh
->region_array
, i
, &r
); ++i
)
883 for (c
= r
->u
.eh_try
.first_catch
; c
; c
= c
->next_catch
)
885 /* Whatever type_list is (NULL or true list), we build a list
886 of filters for the region. */
887 c
->filter_list
= NULL_TREE
;
889 if (c
->type_list
!= NULL
)
891 /* Get a filter value for each of the types caught and store
892 them in the region's dedicated list. */
893 tree tp_node
= c
->type_list
;
895 for ( ; tp_node
; tp_node
= TREE_CHAIN (tp_node
))
898 = add_ttypes_entry (&ttypes
, TREE_VALUE (tp_node
));
899 tree flt_node
= build_int_cst (integer_type_node
, flt
);
902 = tree_cons (NULL_TREE
, flt_node
, c
->filter_list
);
907 /* Get a filter value for the NULL list also since it
908 will need an action record anyway. */
909 int flt
= add_ttypes_entry (&ttypes
, NULL
);
910 tree flt_node
= build_int_cst (integer_type_node
, flt
);
913 = tree_cons (NULL_TREE
, flt_node
, NULL
);
918 case ERT_ALLOWED_EXCEPTIONS
:
920 = add_ehspec_entry (&ehspec
, &ttypes
, r
->u
.allowed
.type_list
);
929 /* Emit SEQ into basic block just before INSN (that is assumed to be
930 first instruction of some existing BB and return the newly
933 emit_to_new_bb_before (rtx_insn
*seq
, rtx insn
)
940 /* If there happens to be a fallthru edge (possibly created by cleanup_cfg
941 call), we don't want it to go into newly created landing pad or other EH
943 for (ei
= ei_start (BLOCK_FOR_INSN (insn
)->preds
); (e
= ei_safe_edge (ei
)); )
944 if (e
->flags
& EDGE_FALLTHRU
)
945 force_nonfallthru (e
);
948 last
= emit_insn_before (seq
, insn
);
949 if (BARRIER_P (last
))
950 last
= PREV_INSN (last
);
951 bb
= create_basic_block (seq
, last
, BLOCK_FOR_INSN (insn
)->prev_bb
);
952 update_bb_for_insn (bb
);
953 bb
->flags
|= BB_SUPERBLOCK
;
957 /* A subroutine of dw2_build_landing_pads, also used for edge splitting
958 at the rtl level. Emit the code required by the target at a landing
959 pad for the given region. */
962 expand_dw2_landing_pad_for_region (eh_region region
)
964 #ifdef HAVE_exception_receiver
965 if (HAVE_exception_receiver
)
966 emit_insn (gen_exception_receiver ());
969 #ifdef HAVE_nonlocal_goto_receiver
970 if (HAVE_nonlocal_goto_receiver
)
971 emit_insn (gen_nonlocal_goto_receiver ());
976 if (region
->exc_ptr_reg
)
977 emit_move_insn (region
->exc_ptr_reg
,
978 gen_rtx_REG (ptr_mode
, EH_RETURN_DATA_REGNO (0)));
979 if (region
->filter_reg
)
980 emit_move_insn (region
->filter_reg
,
981 gen_rtx_REG (targetm
.eh_return_filter_mode (),
982 EH_RETURN_DATA_REGNO (1)));
985 /* Expand the extra code needed at landing pads for dwarf2 unwinding. */
988 dw2_build_landing_pads (void)
992 int e_flags
= EDGE_FALLTHRU
;
994 /* If we're going to partition blocks, we need to be able to add
995 new landing pads later, which means that we need to hold on to
996 the post-landing-pad block. Prevent it from being merged away.
997 We'll remove this bit after partitioning. */
998 if (flag_reorder_blocks_and_partition
)
999 e_flags
|= EDGE_PRESERVE
;
1001 for (i
= 1; vec_safe_iterate (cfun
->eh
->lp_array
, i
, &lp
); ++i
)
1007 if (lp
== NULL
|| lp
->post_landing_pad
== NULL
)
1012 lp
->landing_pad
= gen_label_rtx ();
1013 emit_label (lp
->landing_pad
);
1014 LABEL_PRESERVE_P (lp
->landing_pad
) = 1;
1016 expand_dw2_landing_pad_for_region (lp
->region
);
1021 bb
= emit_to_new_bb_before (seq
, label_rtx (lp
->post_landing_pad
));
1022 e
= make_edge (bb
, bb
->next_bb
, e_flags
);
1023 e
->count
= bb
->count
;
1024 e
->probability
= REG_BR_PROB_BASE
;
1027 struct loop
*loop
= bb
->next_bb
->loop_father
;
1028 /* If we created a pre-header block, add the new block to the
1029 outer loop, otherwise to the loop itself. */
1030 if (bb
->next_bb
== loop
->header
)
1031 add_bb_to_loop (bb
, loop_outer (loop
));
1033 add_bb_to_loop (bb
, loop
);
1039 static vec
<int> sjlj_lp_call_site_index
;
1041 /* Process all active landing pads. Assign each one a compact dispatch
1042 index, and a call-site index. */
1045 sjlj_assign_call_site_values (void)
1047 action_hash_type
ar_hash (31);
1051 vec_alloc (crtl
->eh
.action_record_data
, 64);
1055 for (i
= 1; vec_safe_iterate (cfun
->eh
->lp_array
, i
, &lp
); ++i
)
1056 if (lp
&& lp
->post_landing_pad
)
1058 int action
, call_site
;
1060 /* First: build the action table. */
1061 action
= collect_one_action_chain (&ar_hash
, lp
->region
);
1063 /* Next: assign call-site values. If dwarf2 terms, this would be
1064 the region number assigned by convert_to_eh_region_ranges, but
1065 handles no-action and must-not-throw differently. */
1066 /* Map must-not-throw to otherwise unused call-site index 0. */
1069 /* Map no-action to otherwise unused call-site index -1. */
1070 else if (action
== -1)
1072 /* Otherwise, look it up in the table. */
1074 call_site
= add_call_site (GEN_INT (disp_index
), action
, 0);
1075 sjlj_lp_call_site_index
[i
] = call_site
;
1083 /* Emit code to record the current call-site index before every
1084 insn that can throw. */
1087 sjlj_mark_call_sites (void)
1089 int last_call_site
= -2;
1093 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
1099 rtx_insn
*before
, *p
;
1101 /* Reset value tracking at extended basic block boundaries. */
1103 last_call_site
= -2;
1105 /* If the function allocates dynamic stack space, the context must
1106 be updated after every allocation/deallocation accordingly. */
1107 if (NOTE_P (insn
) && NOTE_KIND (insn
) == NOTE_INSN_UPDATE_SJLJ_CONTEXT
)
1112 buf_addr
= plus_constant (Pmode
, XEXP (crtl
->eh
.sjlj_fc
, 0),
1114 expand_builtin_update_setjmp_buf (buf_addr
);
1117 emit_insn_before (p
, insn
);
1120 if (! INSN_P (insn
))
1123 nothrow
= get_eh_region_and_lp_from_rtx (insn
, &r
, &lp
);
1127 this_call_site
= sjlj_lp_call_site_index
[lp
->index
];
1130 /* Calls (and trapping insns) without notes are outside any
1131 exception handling region in this function. Mark them as
1133 this_call_site
= -1;
1137 gcc_assert (r
->type
== ERT_MUST_NOT_THROW
);
1141 if (this_call_site
!= -1)
1142 crtl
->uses_eh_lsda
= 1;
1144 if (this_call_site
== last_call_site
)
1147 /* Don't separate a call from it's argument loads. */
1150 before
= find_first_parameter_load (insn
, NULL
);
1153 mem
= adjust_address (crtl
->eh
.sjlj_fc
, TYPE_MODE (integer_type_node
),
1154 sjlj_fc_call_site_ofs
);
1155 emit_move_insn (mem
, gen_int_mode (this_call_site
, GET_MODE (mem
)));
1159 emit_insn_before (p
, before
);
1160 last_call_site
= this_call_site
;
1164 /* Construct the SjLj_Function_Context. */
1167 sjlj_emit_function_enter (rtx_code_label
*dispatch_label
)
1169 rtx_insn
*fn_begin
, *seq
;
1171 bool fn_begin_outside_block
;
1172 rtx personality
= get_personality_function (current_function_decl
);
1174 fc
= crtl
->eh
.sjlj_fc
;
1178 /* We're storing this libcall's address into memory instead of
1179 calling it directly. Thus, we must call assemble_external_libcall
1180 here, as we can not depend on emit_library_call to do it for us. */
1181 assemble_external_libcall (personality
);
1182 mem
= adjust_address (fc
, Pmode
, sjlj_fc_personality_ofs
);
1183 emit_move_insn (mem
, personality
);
1185 mem
= adjust_address (fc
, Pmode
, sjlj_fc_lsda_ofs
);
1186 if (crtl
->uses_eh_lsda
)
1191 ASM_GENERATE_INTERNAL_LABEL (buf
, "LLSDA", current_function_funcdef_no
);
1192 sym
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (buf
));
1193 SYMBOL_REF_FLAGS (sym
) = SYMBOL_FLAG_LOCAL
;
1194 emit_move_insn (mem
, sym
);
1197 emit_move_insn (mem
, const0_rtx
);
1201 #ifdef DONT_USE_BUILTIN_SETJMP
1203 x
= emit_library_call_value (setjmp_libfunc
, NULL_RTX
, LCT_RETURNS_TWICE
,
1204 TYPE_MODE (integer_type_node
), 1,
1205 plus_constant (Pmode
, XEXP (fc
, 0),
1206 sjlj_fc_jbuf_ofs
), Pmode
);
1208 emit_cmp_and_jump_insns (x
, const0_rtx
, NE
, 0,
1209 TYPE_MODE (integer_type_node
), 0,
1210 dispatch_label
, REG_BR_PROB_BASE
/ 100);
1212 expand_builtin_setjmp_setup (plus_constant (Pmode
, XEXP (fc
, 0),
1218 emit_library_call (unwind_sjlj_register_libfunc
, LCT_NORMAL
, VOIDmode
,
1219 1, XEXP (fc
, 0), Pmode
);
1224 /* ??? Instead of doing this at the beginning of the function,
1225 do this in a block that is at loop level 0 and dominates all
1226 can_throw_internal instructions. */
1228 fn_begin_outside_block
= true;
1229 for (fn_begin
= get_insns (); ; fn_begin
= NEXT_INSN (fn_begin
))
1230 if (NOTE_P (fn_begin
))
1232 if (NOTE_KIND (fn_begin
) == NOTE_INSN_FUNCTION_BEG
)
1234 else if (NOTE_INSN_BASIC_BLOCK_P (fn_begin
))
1235 fn_begin_outside_block
= false;
1238 if (fn_begin_outside_block
)
1239 insert_insn_on_edge (seq
, single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun
)));
1241 emit_insn_after (seq
, fn_begin
);
1244 /* Call back from expand_function_end to know where we should put
1245 the call to unwind_sjlj_unregister_libfunc if needed. */
1248 sjlj_emit_function_exit_after (rtx_insn
*after
)
1250 crtl
->eh
.sjlj_exit_after
= after
;
1254 sjlj_emit_function_exit (void)
1256 rtx_insn
*seq
, *insn
;
1260 emit_library_call (unwind_sjlj_unregister_libfunc
, LCT_NORMAL
, VOIDmode
,
1261 1, XEXP (crtl
->eh
.sjlj_fc
, 0), Pmode
);
1266 /* ??? Really this can be done in any block at loop level 0 that
1267 post-dominates all can_throw_internal instructions. This is
1268 the last possible moment. */
1270 insn
= crtl
->eh
.sjlj_exit_after
;
1272 insn
= NEXT_INSN (insn
);
1274 emit_insn_after (seq
, insn
);
1278 sjlj_emit_dispatch_table (rtx_code_label
*dispatch_label
, int num_dispatch
)
1280 machine_mode unwind_word_mode
= targetm
.unwind_word_mode ();
1281 machine_mode filter_mode
= targetm
.eh_return_filter_mode ();
1283 rtx mem
, fc
, exc_ptr_reg
, filter_reg
;
1289 vec
<tree
> dispatch_labels
= vNULL
;
1291 fc
= crtl
->eh
.sjlj_fc
;
1295 emit_label (dispatch_label
);
1297 #ifndef DONT_USE_BUILTIN_SETJMP
1298 expand_builtin_setjmp_receiver (dispatch_label
);
1300 /* The caller of expand_builtin_setjmp_receiver is responsible for
1301 making sure that the label doesn't vanish. The only other caller
1302 is the expander for __builtin_setjmp_receiver, which places this
1303 label on the nonlocal_goto_label list. Since we're modeling these
1304 CFG edges more exactly, we can use the forced_labels list instead. */
1305 LABEL_PRESERVE_P (dispatch_label
) = 1;
1307 = gen_rtx_INSN_LIST (VOIDmode
, dispatch_label
, forced_labels
);
1310 /* Load up exc_ptr and filter values from the function context. */
1311 mem
= adjust_address (fc
, unwind_word_mode
, sjlj_fc_data_ofs
);
1312 if (unwind_word_mode
!= ptr_mode
)
1314 #ifdef POINTERS_EXTEND_UNSIGNED
1315 mem
= convert_memory_address (ptr_mode
, mem
);
1317 mem
= convert_to_mode (ptr_mode
, mem
, 0);
1320 exc_ptr_reg
= force_reg (ptr_mode
, mem
);
1322 mem
= adjust_address (fc
, unwind_word_mode
,
1323 sjlj_fc_data_ofs
+ GET_MODE_SIZE (unwind_word_mode
));
1324 if (unwind_word_mode
!= filter_mode
)
1325 mem
= convert_to_mode (filter_mode
, mem
, 0);
1326 filter_reg
= force_reg (filter_mode
, mem
);
1328 /* Jump to one of the directly reachable regions. */
1331 rtx_code_label
*first_reachable_label
= NULL
;
1333 /* If there's exactly one call site in the function, don't bother
1334 generating a switch statement. */
1335 if (num_dispatch
> 1)
1336 dispatch_labels
.create (num_dispatch
);
1338 for (i
= 1; vec_safe_iterate (cfun
->eh
->lp_array
, i
, &lp
); ++i
)
1339 if (lp
&& lp
->post_landing_pad
)
1342 rtx_code_label
*label
;
1346 lp
->landing_pad
= dispatch_label
;
1348 if (num_dispatch
> 1)
1350 tree t_label
, case_elt
, t
;
1352 t_label
= create_artificial_label (UNKNOWN_LOCATION
);
1353 t
= build_int_cst (integer_type_node
, disp_index
);
1354 case_elt
= build_case_label (t
, NULL
, t_label
);
1355 dispatch_labels
.quick_push (case_elt
);
1356 label
= jump_target_rtx (t_label
);
1359 label
= gen_label_rtx ();
1361 if (disp_index
== 0)
1362 first_reachable_label
= label
;
1367 emit_move_insn (r
->exc_ptr_reg
, exc_ptr_reg
);
1369 emit_move_insn (r
->filter_reg
, filter_reg
);
1371 seq2
= get_insns ();
1374 rtx_insn
*before
= label_rtx (lp
->post_landing_pad
);
1375 bb
= emit_to_new_bb_before (seq2
, before
);
1376 e
= make_edge (bb
, bb
->next_bb
, EDGE_FALLTHRU
);
1377 e
->count
= bb
->count
;
1378 e
->probability
= REG_BR_PROB_BASE
;
1381 struct loop
*loop
= bb
->next_bb
->loop_father
;
1382 /* If we created a pre-header block, add the new block to the
1383 outer loop, otherwise to the loop itself. */
1384 if (bb
->next_bb
== loop
->header
)
1385 add_bb_to_loop (bb
, loop_outer (loop
));
1387 add_bb_to_loop (bb
, loop
);
1388 /* ??? For multiple dispatches we will end up with edges
1389 from the loop tree root into this loop, making it a
1390 multiple-entry loop. Discard all affected loops. */
1391 if (num_dispatch
> 1)
1393 for (loop
= bb
->loop_father
;
1394 loop_outer (loop
); loop
= loop_outer (loop
))
1395 mark_loop_for_removal (loop
);
1401 gcc_assert (disp_index
== num_dispatch
);
1403 if (num_dispatch
> 1)
1405 rtx disp
= adjust_address (fc
, TYPE_MODE (integer_type_node
),
1406 sjlj_fc_call_site_ofs
);
1407 expand_sjlj_dispatch_table (disp
, dispatch_labels
);
1413 bb
= emit_to_new_bb_before (seq
, first_reachable_label
);
1414 if (num_dispatch
== 1)
1416 e
= make_edge (bb
, bb
->next_bb
, EDGE_FALLTHRU
);
1417 e
->count
= bb
->count
;
1418 e
->probability
= REG_BR_PROB_BASE
;
1421 struct loop
*loop
= bb
->next_bb
->loop_father
;
1422 /* If we created a pre-header block, add the new block to the
1423 outer loop, otherwise to the loop itself. */
1424 if (bb
->next_bb
== loop
->header
)
1425 add_bb_to_loop (bb
, loop_outer (loop
));
1427 add_bb_to_loop (bb
, loop
);
1432 /* We are not wiring up edges here, but as the dispatcher call
1433 is at function begin simply associate the block with the
1434 outermost (non-)loop. */
1436 add_bb_to_loop (bb
, current_loops
->tree_root
);
1441 sjlj_build_landing_pads (void)
1445 num_dispatch
= vec_safe_length (cfun
->eh
->lp_array
);
1446 if (num_dispatch
== 0)
1448 sjlj_lp_call_site_index
.safe_grow_cleared (num_dispatch
);
1450 num_dispatch
= sjlj_assign_call_site_values ();
1451 if (num_dispatch
> 0)
1453 rtx_code_label
*dispatch_label
= gen_label_rtx ();
1454 int align
= STACK_SLOT_ALIGNMENT (sjlj_fc_type_node
,
1455 TYPE_MODE (sjlj_fc_type_node
),
1456 TYPE_ALIGN (sjlj_fc_type_node
));
1458 = assign_stack_local (TYPE_MODE (sjlj_fc_type_node
),
1459 int_size_in_bytes (sjlj_fc_type_node
),
1462 sjlj_mark_call_sites ();
1463 sjlj_emit_function_enter (dispatch_label
);
1464 sjlj_emit_dispatch_table (dispatch_label
, num_dispatch
);
1465 sjlj_emit_function_exit ();
1468 /* If we do not have any landing pads, we may still need to register a
1469 personality routine and (empty) LSDA to handle must-not-throw regions. */
1470 else if (function_needs_eh_personality (cfun
) != eh_personality_none
)
1472 int align
= STACK_SLOT_ALIGNMENT (sjlj_fc_type_node
,
1473 TYPE_MODE (sjlj_fc_type_node
),
1474 TYPE_ALIGN (sjlj_fc_type_node
));
1476 = assign_stack_local (TYPE_MODE (sjlj_fc_type_node
),
1477 int_size_in_bytes (sjlj_fc_type_node
),
1480 sjlj_mark_call_sites ();
1481 sjlj_emit_function_enter (NULL
);
1482 sjlj_emit_function_exit ();
1485 sjlj_lp_call_site_index
.release ();
1488 /* Update the sjlj function context. This function should be called
1489 whenever we allocate or deallocate dynamic stack space. */
1492 update_sjlj_context (void)
1494 if (!flag_exceptions
)
1497 emit_note (NOTE_INSN_UPDATE_SJLJ_CONTEXT
);
1500 /* After initial rtl generation, call back to finish generating
1501 exception support code. */
1504 finish_eh_generation (void)
1508 /* Construct the landing pads. */
1509 if (targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
)
1510 sjlj_build_landing_pads ();
1512 dw2_build_landing_pads ();
1513 break_superblocks ();
1515 if (targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
1516 /* Kludge for Alpha (see alpha_gp_save_rtx). */
1517 || single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun
))->insns
.r
)
1518 commit_edge_insertions ();
1520 /* Redirect all EH edges from the post_landing_pad to the landing pad. */
1521 FOR_EACH_BB_FN (bb
, cfun
)
1527 lp
= get_eh_landing_pad_from_rtx (BB_END (bb
));
1529 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
1530 if (e
->flags
& EDGE_EH
)
1533 /* We should not have generated any new throwing insns during this
1534 pass, and we should not have lost any EH edges, so we only need
1535 to handle two cases here:
1536 (1) reachable handler and an existing edge to post-landing-pad,
1537 (2) no reachable handler and no edge. */
1538 gcc_assert ((lp
!= NULL
) == (e
!= NULL
));
1541 gcc_assert (BB_HEAD (e
->dest
) == label_rtx (lp
->post_landing_pad
));
1543 redirect_edge_succ (e
, BLOCK_FOR_INSN (lp
->landing_pad
));
1544 e
->flags
|= (CALL_P (BB_END (bb
))
1545 ? EDGE_ABNORMAL
| EDGE_ABNORMAL_CALL
1551 /* This section handles removing dead code for flow. */
1554 remove_eh_landing_pad (eh_landing_pad lp
)
1558 for (pp
= &lp
->region
->landing_pads
; *pp
!= lp
; pp
= &(*pp
)->next_lp
)
1562 if (lp
->post_landing_pad
)
1563 EH_LANDING_PAD_NR (lp
->post_landing_pad
) = 0;
1564 (*cfun
->eh
->lp_array
)[lp
->index
] = NULL
;
1567 /* Splice the EH region at PP from the region tree. */
1570 remove_eh_handler_splicer (eh_region
*pp
)
1572 eh_region region
= *pp
;
1575 for (lp
= region
->landing_pads
; lp
; lp
= lp
->next_lp
)
1577 if (lp
->post_landing_pad
)
1578 EH_LANDING_PAD_NR (lp
->post_landing_pad
) = 0;
1579 (*cfun
->eh
->lp_array
)[lp
->index
] = NULL
;
1585 outer
= region
->outer
;
1587 *pp
= p
= region
->inner
;
1596 *pp
= region
->next_peer
;
1598 (*cfun
->eh
->region_array
)[region
->index
] = NULL
;
1601 /* Splice a single EH region REGION from the region tree.
1603 To unlink REGION, we need to find the pointer to it with a relatively
1604 expensive search in REGION's outer region. If you are going to
1605 remove a number of handlers, using remove_unreachable_eh_regions may
1606 be a better option. */
1609 remove_eh_handler (eh_region region
)
1611 eh_region
*pp
, *pp_start
, p
, outer
;
1613 outer
= region
->outer
;
1615 pp_start
= &outer
->inner
;
1617 pp_start
= &cfun
->eh
->region_tree
;
1618 for (pp
= pp_start
, p
= *pp
; p
!= region
; pp
= &p
->next_peer
, p
= *pp
)
1621 remove_eh_handler_splicer (pp
);
1624 /* Worker for remove_unreachable_eh_regions.
1625 PP is a pointer to the region to start a region tree depth-first
1626 search from. R_REACHABLE is the set of regions that have to be
1630 remove_unreachable_eh_regions_worker (eh_region
*pp
, sbitmap r_reachable
)
1634 eh_region region
= *pp
;
1635 remove_unreachable_eh_regions_worker (®ion
->inner
, r_reachable
);
1636 if (!bitmap_bit_p (r_reachable
, region
->index
))
1637 remove_eh_handler_splicer (pp
);
1639 pp
= ®ion
->next_peer
;
1643 /* Splice all EH regions *not* marked in R_REACHABLE from the region tree.
1644 Do this by traversing the EH tree top-down and splice out regions that
1645 are not marked. By removing regions from the leaves, we avoid costly
1646 searches in the region tree. */
1649 remove_unreachable_eh_regions (sbitmap r_reachable
)
1651 remove_unreachable_eh_regions_worker (&cfun
->eh
->region_tree
, r_reachable
);
1654 /* Invokes CALLBACK for every exception handler landing pad label.
1655 Only used by reload hackery; should not be used by new code. */
1658 for_each_eh_label (void (*callback
) (rtx
))
1663 for (i
= 1; vec_safe_iterate (cfun
->eh
->lp_array
, i
, &lp
); ++i
)
1667 rtx_code_label
*lab
= lp
->landing_pad
;
1668 if (lab
&& LABEL_P (lab
))
1674 /* Create the REG_EH_REGION note for INSN, given its ECF_FLAGS for a
1677 At the gimple level, we use LP_NR
1678 > 0 : The statement transfers to landing pad LP_NR
1679 = 0 : The statement is outside any EH region
1680 < 0 : The statement is within MUST_NOT_THROW region -LP_NR.
1682 At the rtl level, we use LP_NR
1683 > 0 : The insn transfers to landing pad LP_NR
1684 = 0 : The insn cannot throw
1685 < 0 : The insn is within MUST_NOT_THROW region -LP_NR
1686 = INT_MIN : The insn cannot throw or execute a nonlocal-goto.
1687 missing note: The insn is outside any EH region.
1689 ??? This difference probably ought to be avoided. We could stand
1690 to record nothrow for arbitrary gimple statements, and so avoid
1691 some moderately complex lookups in stmt_could_throw_p. Perhaps
1692 NOTHROW should be mapped on both sides to INT_MIN. Perhaps the
1693 no-nonlocal-goto property should be recorded elsewhere as a bit
1694 on the call_insn directly. Perhaps we should make more use of
1695 attaching the trees to call_insns (reachable via symbol_ref in
1696 direct call cases) and just pull the data out of the trees. */
1699 make_reg_eh_region_note (rtx_insn
*insn
, int ecf_flags
, int lp_nr
)
1702 if (ecf_flags
& ECF_NOTHROW
)
1704 else if (lp_nr
!= 0)
1705 value
= GEN_INT (lp_nr
);
1708 add_reg_note (insn
, REG_EH_REGION
, value
);
1711 /* Create a REG_EH_REGION note for a CALL_INSN that cannot throw
1712 nor perform a non-local goto. Replace the region note if it
1716 make_reg_eh_region_note_nothrow_nononlocal (rtx_insn
*insn
)
1718 rtx note
= find_reg_note (insn
, REG_EH_REGION
, NULL_RTX
);
1719 rtx intmin
= GEN_INT (INT_MIN
);
1722 XEXP (note
, 0) = intmin
;
1724 add_reg_note (insn
, REG_EH_REGION
, intmin
);
1727 /* Return true if INSN could throw, assuming no REG_EH_REGION note
1731 insn_could_throw_p (const_rtx insn
)
1733 if (!flag_exceptions
)
1737 if (INSN_P (insn
) && cfun
->can_throw_non_call_exceptions
)
1738 return may_trap_p (PATTERN (insn
));
1742 /* Copy an REG_EH_REGION note to each insn that might throw beginning
1743 at FIRST and ending at LAST. NOTE_OR_INSN is either the source insn
1744 to look for a note, or the note itself. */
1747 copy_reg_eh_region_note_forward (rtx note_or_insn
, rtx_insn
*first
, rtx last
)
1750 rtx note
= note_or_insn
;
1752 if (INSN_P (note_or_insn
))
1754 note
= find_reg_note (note_or_insn
, REG_EH_REGION
, NULL_RTX
);
1758 note
= XEXP (note
, 0);
1760 for (insn
= first
; insn
!= last
; insn
= NEXT_INSN (insn
))
1761 if (!find_reg_note (insn
, REG_EH_REGION
, NULL_RTX
)
1762 && insn_could_throw_p (insn
))
1763 add_reg_note (insn
, REG_EH_REGION
, note
);
1766 /* Likewise, but iterate backward. */
1769 copy_reg_eh_region_note_backward (rtx note_or_insn
, rtx_insn
*last
, rtx first
)
1772 rtx note
= note_or_insn
;
1774 if (INSN_P (note_or_insn
))
1776 note
= find_reg_note (note_or_insn
, REG_EH_REGION
, NULL_RTX
);
1780 note
= XEXP (note
, 0);
1782 for (insn
= last
; insn
!= first
; insn
= PREV_INSN (insn
))
1783 if (insn_could_throw_p (insn
))
1784 add_reg_note (insn
, REG_EH_REGION
, note
);
1788 /* Extract all EH information from INSN. Return true if the insn
1789 was marked NOTHROW. */
1792 get_eh_region_and_lp_from_rtx (const_rtx insn
, eh_region
*pr
,
1793 eh_landing_pad
*plp
)
1795 eh_landing_pad lp
= NULL
;
1801 if (! INSN_P (insn
))
1804 if (NONJUMP_INSN_P (insn
)
1805 && GET_CODE (PATTERN (insn
)) == SEQUENCE
)
1806 insn
= XVECEXP (PATTERN (insn
), 0, 0);
1808 note
= find_reg_note (insn
, REG_EH_REGION
, NULL_RTX
);
1811 ret
= !insn_could_throw_p (insn
);
1815 lp_nr
= INTVAL (XEXP (note
, 0));
1816 if (lp_nr
== 0 || lp_nr
== INT_MIN
)
1823 r
= (*cfun
->eh
->region_array
)[-lp_nr
];
1826 lp
= (*cfun
->eh
->lp_array
)[lp_nr
];
1836 /* Return the landing pad to which INSN may go, or NULL if it does not
1837 have a reachable landing pad within this function. */
1840 get_eh_landing_pad_from_rtx (const_rtx insn
)
1845 get_eh_region_and_lp_from_rtx (insn
, &r
, &lp
);
1849 /* Return the region to which INSN may go, or NULL if it does not
1850 have a reachable region within this function. */
1853 get_eh_region_from_rtx (const_rtx insn
)
1858 get_eh_region_and_lp_from_rtx (insn
, &r
, &lp
);
1862 /* Return true if INSN throws and is caught by something in this function. */
1865 can_throw_internal (const_rtx insn
)
1867 return get_eh_landing_pad_from_rtx (insn
) != NULL
;
1870 /* Return true if INSN throws and escapes from the current function. */
1873 can_throw_external (const_rtx insn
)
1879 if (! INSN_P (insn
))
1882 if (NONJUMP_INSN_P (insn
)
1883 && GET_CODE (PATTERN (insn
)) == SEQUENCE
)
1885 rtx_sequence
*seq
= as_a
<rtx_sequence
*> (PATTERN (insn
));
1886 int i
, n
= seq
->len ();
1888 for (i
= 0; i
< n
; i
++)
1889 if (can_throw_external (seq
->element (i
)))
1895 nothrow
= get_eh_region_and_lp_from_rtx (insn
, &r
, &lp
);
1897 /* If we can't throw, we obviously can't throw external. */
1901 /* If we have an internal landing pad, then we're not external. */
1905 /* If we're not within an EH region, then we are external. */
1909 /* The only thing that ought to be left is MUST_NOT_THROW regions,
1910 which don't always have landing pads. */
1911 gcc_assert (r
->type
== ERT_MUST_NOT_THROW
);
1915 /* Return true if INSN cannot throw at all. */
1918 insn_nothrow_p (const_rtx insn
)
1923 if (! INSN_P (insn
))
1926 if (NONJUMP_INSN_P (insn
)
1927 && GET_CODE (PATTERN (insn
)) == SEQUENCE
)
1929 rtx_sequence
*seq
= as_a
<rtx_sequence
*> (PATTERN (insn
));
1930 int i
, n
= seq
->len ();
1932 for (i
= 0; i
< n
; i
++)
1933 if (!insn_nothrow_p (seq
->element (i
)))
1939 return get_eh_region_and_lp_from_rtx (insn
, &r
, &lp
);
1942 /* Return true if INSN can perform a non-local goto. */
1943 /* ??? This test is here in this file because it (ab)uses REG_EH_REGION. */
1946 can_nonlocal_goto (const rtx_insn
*insn
)
1948 if (nonlocal_goto_handler_labels
&& CALL_P (insn
))
1950 rtx note
= find_reg_note (insn
, REG_EH_REGION
, NULL_RTX
);
1951 if (!note
|| INTVAL (XEXP (note
, 0)) != INT_MIN
)
1957 /* Set TREE_NOTHROW and crtl->all_throwers_are_sibcalls. */
1960 set_nothrow_function_flags (void)
1966 /* Assume crtl->all_throwers_are_sibcalls until we encounter
1967 something that can throw an exception. We specifically exempt
1968 CALL_INSNs that are SIBLING_CALL_P, as these are really jumps,
1969 and can't throw. Most CALL_INSNs are not SIBLING_CALL_P, so this
1972 crtl
->all_throwers_are_sibcalls
= 1;
1974 /* If we don't know that this implementation of the function will
1975 actually be used, then we must not set TREE_NOTHROW, since
1976 callers must not assume that this function does not throw. */
1977 if (TREE_NOTHROW (current_function_decl
))
1980 if (! flag_exceptions
)
1983 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
1984 if (can_throw_external (insn
))
1988 if (!CALL_P (insn
) || !SIBLING_CALL_P (insn
))
1990 crtl
->all_throwers_are_sibcalls
= 0;
1996 && (cgraph_node::get (current_function_decl
)->get_availability ()
1997 >= AVAIL_AVAILABLE
))
1999 struct cgraph_node
*node
= cgraph_node::get (current_function_decl
);
2000 struct cgraph_edge
*e
;
2001 for (e
= node
->callers
; e
; e
= e
->next_caller
)
2002 e
->can_throw_external
= false;
2003 node
->set_nothrow_flag (true);
2006 fprintf (dump_file
, "Marking function nothrow: %s\n\n",
2007 current_function_name ());
2014 const pass_data pass_data_set_nothrow_function_flags
=
2016 RTL_PASS
, /* type */
2017 "nothrow", /* name */
2018 OPTGROUP_NONE
, /* optinfo_flags */
2019 TV_NONE
, /* tv_id */
2020 0, /* properties_required */
2021 0, /* properties_provided */
2022 0, /* properties_destroyed */
2023 0, /* todo_flags_start */
2024 0, /* todo_flags_finish */
2027 class pass_set_nothrow_function_flags
: public rtl_opt_pass
2030 pass_set_nothrow_function_flags (gcc::context
*ctxt
)
2031 : rtl_opt_pass (pass_data_set_nothrow_function_flags
, ctxt
)
2034 /* opt_pass methods: */
2035 virtual unsigned int execute (function
*)
2037 return set_nothrow_function_flags ();
2040 }; // class pass_set_nothrow_function_flags
2045 make_pass_set_nothrow_function_flags (gcc::context
*ctxt
)
2047 return new pass_set_nothrow_function_flags (ctxt
);
2051 /* Various hooks for unwind library. */
2053 /* Expand the EH support builtin functions:
2054 __builtin_eh_pointer and __builtin_eh_filter. */
2057 expand_builtin_eh_common (tree region_nr_t
)
2059 HOST_WIDE_INT region_nr
;
2062 gcc_assert (tree_fits_shwi_p (region_nr_t
));
2063 region_nr
= tree_to_shwi (region_nr_t
);
2065 region
= (*cfun
->eh
->region_array
)[region_nr
];
2067 /* ??? We shouldn't have been able to delete a eh region without
2068 deleting all the code that depended on it. */
2069 gcc_assert (region
!= NULL
);
2074 /* Expand to the exc_ptr value from the given eh region. */
2077 expand_builtin_eh_pointer (tree exp
)
2080 = expand_builtin_eh_common (CALL_EXPR_ARG (exp
, 0));
2081 if (region
->exc_ptr_reg
== NULL
)
2082 region
->exc_ptr_reg
= gen_reg_rtx (ptr_mode
);
2083 return region
->exc_ptr_reg
;
2086 /* Expand to the filter value from the given eh region. */
2089 expand_builtin_eh_filter (tree exp
)
2092 = expand_builtin_eh_common (CALL_EXPR_ARG (exp
, 0));
2093 if (region
->filter_reg
== NULL
)
2094 region
->filter_reg
= gen_reg_rtx (targetm
.eh_return_filter_mode ());
2095 return region
->filter_reg
;
2098 /* Copy the exc_ptr and filter values from one landing pad's registers
2099 to another. This is used to inline the resx statement. */
2102 expand_builtin_eh_copy_values (tree exp
)
2105 = expand_builtin_eh_common (CALL_EXPR_ARG (exp
, 0));
2107 = expand_builtin_eh_common (CALL_EXPR_ARG (exp
, 1));
2108 machine_mode fmode
= targetm
.eh_return_filter_mode ();
2110 if (dst
->exc_ptr_reg
== NULL
)
2111 dst
->exc_ptr_reg
= gen_reg_rtx (ptr_mode
);
2112 if (src
->exc_ptr_reg
== NULL
)
2113 src
->exc_ptr_reg
= gen_reg_rtx (ptr_mode
);
2115 if (dst
->filter_reg
== NULL
)
2116 dst
->filter_reg
= gen_reg_rtx (fmode
);
2117 if (src
->filter_reg
== NULL
)
2118 src
->filter_reg
= gen_reg_rtx (fmode
);
2120 emit_move_insn (dst
->exc_ptr_reg
, src
->exc_ptr_reg
);
2121 emit_move_insn (dst
->filter_reg
, src
->filter_reg
);
2126 /* Do any necessary initialization to access arbitrary stack frames.
2127 On the SPARC, this means flushing the register windows. */
2130 expand_builtin_unwind_init (void)
2132 /* Set this so all the registers get saved in our frame; we need to be
2133 able to copy the saved values for any registers from frames we unwind. */
2134 crtl
->saves_all_registers
= 1;
2136 #ifdef SETUP_FRAME_ADDRESSES
2137 SETUP_FRAME_ADDRESSES ();
2141 /* Map a non-negative number to an eh return data register number; expands
2142 to -1 if no return data register is associated with the input number.
2143 At least the inputs 0 and 1 must be mapped; the target may provide more. */
2146 expand_builtin_eh_return_data_regno (tree exp
)
2148 tree which
= CALL_EXPR_ARG (exp
, 0);
2149 unsigned HOST_WIDE_INT iwhich
;
2151 if (TREE_CODE (which
) != INTEGER_CST
)
2153 error ("argument of %<__builtin_eh_return_regno%> must be constant");
2157 iwhich
= tree_to_uhwi (which
);
2158 iwhich
= EH_RETURN_DATA_REGNO (iwhich
);
2159 if (iwhich
== INVALID_REGNUM
)
2162 #ifdef DWARF_FRAME_REGNUM
2163 iwhich
= DWARF_FRAME_REGNUM (iwhich
);
2165 iwhich
= DBX_REGISTER_NUMBER (iwhich
);
2168 return GEN_INT (iwhich
);
2171 /* Given a value extracted from the return address register or stack slot,
2172 return the actual address encoded in that value. */
2175 expand_builtin_extract_return_addr (tree addr_tree
)
2177 rtx addr
= expand_expr (addr_tree
, NULL_RTX
, Pmode
, EXPAND_NORMAL
);
2179 if (GET_MODE (addr
) != Pmode
2180 && GET_MODE (addr
) != VOIDmode
)
2182 #ifdef POINTERS_EXTEND_UNSIGNED
2183 addr
= convert_memory_address (Pmode
, addr
);
2185 addr
= convert_to_mode (Pmode
, addr
, 0);
2189 /* First mask out any unwanted bits. */
2190 rtx mask
= MASK_RETURN_ADDR
;
2192 expand_and (Pmode
, addr
, mask
, addr
);
2194 /* Then adjust to find the real return address. */
2195 if (RETURN_ADDR_OFFSET
)
2196 addr
= plus_constant (Pmode
, addr
, RETURN_ADDR_OFFSET
);
2201 /* Given an actual address in addr_tree, do any necessary encoding
2202 and return the value to be stored in the return address register or
2203 stack slot so the epilogue will return to that address. */
2206 expand_builtin_frob_return_addr (tree addr_tree
)
2208 rtx addr
= expand_expr (addr_tree
, NULL_RTX
, ptr_mode
, EXPAND_NORMAL
);
2210 addr
= convert_memory_address (Pmode
, addr
);
2212 if (RETURN_ADDR_OFFSET
)
2214 addr
= force_reg (Pmode
, addr
);
2215 addr
= plus_constant (Pmode
, addr
, -RETURN_ADDR_OFFSET
);
2221 /* Set up the epilogue with the magic bits we'll need to return to the
2222 exception handler. */
2225 expand_builtin_eh_return (tree stackadj_tree ATTRIBUTE_UNUSED
,
2230 #ifdef EH_RETURN_STACKADJ_RTX
2231 tmp
= expand_expr (stackadj_tree
, crtl
->eh
.ehr_stackadj
,
2232 VOIDmode
, EXPAND_NORMAL
);
2233 tmp
= convert_memory_address (Pmode
, tmp
);
2234 if (!crtl
->eh
.ehr_stackadj
)
2235 crtl
->eh
.ehr_stackadj
= copy_to_reg (tmp
);
2236 else if (tmp
!= crtl
->eh
.ehr_stackadj
)
2237 emit_move_insn (crtl
->eh
.ehr_stackadj
, tmp
);
2240 tmp
= expand_expr (handler_tree
, crtl
->eh
.ehr_handler
,
2241 VOIDmode
, EXPAND_NORMAL
);
2242 tmp
= convert_memory_address (Pmode
, tmp
);
2243 if (!crtl
->eh
.ehr_handler
)
2244 crtl
->eh
.ehr_handler
= copy_to_reg (tmp
);
2245 else if (tmp
!= crtl
->eh
.ehr_handler
)
2246 emit_move_insn (crtl
->eh
.ehr_handler
, tmp
);
2248 if (!crtl
->eh
.ehr_label
)
2249 crtl
->eh
.ehr_label
= gen_label_rtx ();
2250 emit_jump (crtl
->eh
.ehr_label
);
2253 /* Expand __builtin_eh_return. This exit path from the function loads up
2254 the eh return data registers, adjusts the stack, and branches to a
2255 given PC other than the normal return address. */
2258 expand_eh_return (void)
2260 rtx_code_label
*around_label
;
2262 if (! crtl
->eh
.ehr_label
)
2265 crtl
->calls_eh_return
= 1;
2267 #ifdef EH_RETURN_STACKADJ_RTX
2268 emit_move_insn (EH_RETURN_STACKADJ_RTX
, const0_rtx
);
2271 around_label
= gen_label_rtx ();
2272 emit_jump (around_label
);
2274 emit_label (crtl
->eh
.ehr_label
);
2275 clobber_return_register ();
2277 #ifdef EH_RETURN_STACKADJ_RTX
2278 emit_move_insn (EH_RETURN_STACKADJ_RTX
, crtl
->eh
.ehr_stackadj
);
2281 #ifdef HAVE_eh_return
2283 emit_insn (gen_eh_return (crtl
->eh
.ehr_handler
));
2287 #ifdef EH_RETURN_HANDLER_RTX
2288 emit_move_insn (EH_RETURN_HANDLER_RTX
, crtl
->eh
.ehr_handler
);
2290 error ("__builtin_eh_return not supported on this target");
2294 emit_label (around_label
);
2297 /* Convert a ptr_mode address ADDR_TREE to a Pmode address controlled by
2298 POINTERS_EXTEND_UNSIGNED and return it. */
2301 expand_builtin_extend_pointer (tree addr_tree
)
2303 rtx addr
= expand_expr (addr_tree
, NULL_RTX
, ptr_mode
, EXPAND_NORMAL
);
2306 #ifdef POINTERS_EXTEND_UNSIGNED
2307 extend
= POINTERS_EXTEND_UNSIGNED
;
2309 /* The previous EH code did an unsigned extend by default, so we do this also
2314 return convert_modes (targetm
.unwind_word_mode (), ptr_mode
, addr
, extend
);
2318 add_action_record (action_hash_type
*ar_hash
, int filter
, int next
)
2320 struct action_record
**slot
, *new_ar
, tmp
;
2322 tmp
.filter
= filter
;
2324 slot
= ar_hash
->find_slot (&tmp
, INSERT
);
2326 if ((new_ar
= *slot
) == NULL
)
2328 new_ar
= XNEW (struct action_record
);
2329 new_ar
->offset
= crtl
->eh
.action_record_data
->length () + 1;
2330 new_ar
->filter
= filter
;
2331 new_ar
->next
= next
;
2334 /* The filter value goes in untouched. The link to the next
2335 record is a "self-relative" byte offset, or zero to indicate
2336 that there is no next record. So convert the absolute 1 based
2337 indices we've been carrying around into a displacement. */
2339 push_sleb128 (&crtl
->eh
.action_record_data
, filter
);
2341 next
-= crtl
->eh
.action_record_data
->length () + 1;
2342 push_sleb128 (&crtl
->eh
.action_record_data
, next
);
2345 return new_ar
->offset
;
2349 collect_one_action_chain (action_hash_type
*ar_hash
, eh_region region
)
2353 /* If we've reached the top of the region chain, then we have
2354 no actions, and require no landing pad. */
2358 switch (region
->type
)
2363 /* A cleanup adds a zero filter to the beginning of the chain, but
2364 there are special cases to look out for. If there are *only*
2365 cleanups along a path, then it compresses to a zero action.
2366 Further, if there are multiple cleanups along a path, we only
2367 need to represent one of them, as that is enough to trigger
2368 entry to the landing pad at runtime. */
2369 next
= collect_one_action_chain (ar_hash
, region
->outer
);
2372 for (r
= region
->outer
; r
; r
= r
->outer
)
2373 if (r
->type
== ERT_CLEANUP
)
2375 return add_action_record (ar_hash
, 0, next
);
2382 /* Process the associated catch regions in reverse order.
2383 If there's a catch-all handler, then we don't need to
2384 search outer regions. Use a magic -3 value to record
2385 that we haven't done the outer search. */
2387 for (c
= region
->u
.eh_try
.last_catch
; c
; c
= c
->prev_catch
)
2389 if (c
->type_list
== NULL
)
2391 /* Retrieve the filter from the head of the filter list
2392 where we have stored it (see assign_filter_values). */
2393 int filter
= TREE_INT_CST_LOW (TREE_VALUE (c
->filter_list
));
2394 next
= add_action_record (ar_hash
, filter
, 0);
2398 /* Once the outer search is done, trigger an action record for
2399 each filter we have. */
2404 next
= collect_one_action_chain (ar_hash
, region
->outer
);
2406 /* If there is no next action, terminate the chain. */
2409 /* If all outer actions are cleanups or must_not_throw,
2410 we'll have no action record for it, since we had wanted
2411 to encode these states in the call-site record directly.
2412 Add a cleanup action to the chain to catch these. */
2414 next
= add_action_record (ar_hash
, 0, 0);
2417 flt_node
= c
->filter_list
;
2418 for (; flt_node
; flt_node
= TREE_CHAIN (flt_node
))
2420 int filter
= TREE_INT_CST_LOW (TREE_VALUE (flt_node
));
2421 next
= add_action_record (ar_hash
, filter
, next
);
2428 case ERT_ALLOWED_EXCEPTIONS
:
2429 /* An exception specification adds its filter to the
2430 beginning of the chain. */
2431 next
= collect_one_action_chain (ar_hash
, region
->outer
);
2433 /* If there is no next action, terminate the chain. */
2436 /* If all outer actions are cleanups or must_not_throw,
2437 we'll have no action record for it, since we had wanted
2438 to encode these states in the call-site record directly.
2439 Add a cleanup action to the chain to catch these. */
2441 next
= add_action_record (ar_hash
, 0, 0);
2443 return add_action_record (ar_hash
, region
->u
.allowed
.filter
, next
);
2445 case ERT_MUST_NOT_THROW
:
2446 /* A must-not-throw region with no inner handlers or cleanups
2447 requires no call-site entry. Note that this differs from
2448 the no handler or cleanup case in that we do require an lsda
2449 to be generated. Return a magic -2 value to record this. */
2457 add_call_site (rtx landing_pad
, int action
, int section
)
2459 call_site_record record
;
2461 record
= ggc_alloc
<call_site_record_d
> ();
2462 record
->landing_pad
= landing_pad
;
2463 record
->action
= action
;
2465 vec_safe_push (crtl
->eh
.call_site_record_v
[section
], record
);
2467 return call_site_base
+ crtl
->eh
.call_site_record_v
[section
]->length () - 1;
2471 emit_note_eh_region_end (rtx_insn
*insn
)
2473 rtx_insn
*next
= NEXT_INSN (insn
);
2475 /* Make sure we do not split a call and its corresponding
2476 CALL_ARG_LOCATION note. */
2477 if (next
&& NOTE_P (next
)
2478 && NOTE_KIND (next
) == NOTE_INSN_CALL_ARG_LOCATION
)
2481 return emit_note_after (NOTE_INSN_EH_REGION_END
, insn
);
2484 /* Turn REG_EH_REGION notes back into NOTE_INSN_EH_REGION notes.
2485 The new note numbers will not refer to region numbers, but
2486 instead to call site entries. */
2489 convert_to_eh_region_ranges (void)
2494 action_hash_type
ar_hash (31);
2495 int last_action
= -3;
2496 rtx_insn
*last_action_insn
= NULL
;
2497 rtx last_landing_pad
= NULL_RTX
;
2498 rtx_insn
*first_no_action_insn
= NULL
;
2501 rtx_insn
*section_switch_note
= NULL
;
2502 rtx_insn
*first_no_action_insn_before_switch
= NULL
;
2503 rtx_insn
*last_no_action_insn_before_switch
= NULL
;
2504 int saved_call_site_base
= call_site_base
;
2506 vec_alloc (crtl
->eh
.action_record_data
, 64);
2508 for (iter
= get_insns (); iter
; iter
= NEXT_INSN (iter
))
2515 rtx_code_label
*this_landing_pad
;
2518 if (NONJUMP_INSN_P (insn
)
2519 && GET_CODE (PATTERN (insn
)) == SEQUENCE
)
2520 insn
= XVECEXP (PATTERN (insn
), 0, 0);
2522 nothrow
= get_eh_region_and_lp_from_rtx (insn
, ®ion
, &lp
);
2526 this_action
= collect_one_action_chain (&ar_hash
, region
);
2530 /* Existence of catch handlers, or must-not-throw regions
2531 implies that an lsda is needed (even if empty). */
2532 if (this_action
!= -1)
2533 crtl
->uses_eh_lsda
= 1;
2535 /* Delay creation of region notes for no-action regions
2536 until we're sure that an lsda will be required. */
2537 else if (last_action
== -3)
2539 first_no_action_insn
= iter
;
2543 if (this_action
>= 0)
2544 this_landing_pad
= lp
->landing_pad
;
2546 this_landing_pad
= NULL
;
2548 /* Differing actions or landing pads implies a change in call-site
2549 info, which implies some EH_REGION note should be emitted. */
2550 if (last_action
!= this_action
2551 || last_landing_pad
!= this_landing_pad
)
2553 /* If there is a queued no-action region in the other section
2554 with hot/cold partitioning, emit it now. */
2555 if (first_no_action_insn_before_switch
)
2557 gcc_assert (this_action
!= -1
2558 && last_action
== (first_no_action_insn
2560 call_site
= add_call_site (NULL_RTX
, 0, 0);
2561 note
= emit_note_before (NOTE_INSN_EH_REGION_BEG
,
2562 first_no_action_insn_before_switch
);
2563 NOTE_EH_HANDLER (note
) = call_site
;
2565 = emit_note_eh_region_end (last_no_action_insn_before_switch
);
2566 NOTE_EH_HANDLER (note
) = call_site
;
2567 gcc_assert (last_action
!= -3
2568 || (last_action_insn
2569 == last_no_action_insn_before_switch
));
2570 first_no_action_insn_before_switch
= NULL
;
2571 last_no_action_insn_before_switch
= NULL
;
2574 /* If we'd not seen a previous action (-3) or the previous
2575 action was must-not-throw (-2), then we do not need an
2577 if (last_action
>= -1)
2579 /* If we delayed the creation of the begin, do it now. */
2580 if (first_no_action_insn
)
2582 call_site
= add_call_site (NULL_RTX
, 0, cur_sec
);
2583 note
= emit_note_before (NOTE_INSN_EH_REGION_BEG
,
2584 first_no_action_insn
);
2585 NOTE_EH_HANDLER (note
) = call_site
;
2586 first_no_action_insn
= NULL
;
2589 note
= emit_note_eh_region_end (last_action_insn
);
2590 NOTE_EH_HANDLER (note
) = call_site
;
2593 /* If the new action is must-not-throw, then no region notes
2595 if (this_action
>= -1)
2597 call_site
= add_call_site (this_landing_pad
,
2598 this_action
< 0 ? 0 : this_action
,
2600 note
= emit_note_before (NOTE_INSN_EH_REGION_BEG
, iter
);
2601 NOTE_EH_HANDLER (note
) = call_site
;
2604 last_action
= this_action
;
2605 last_landing_pad
= this_landing_pad
;
2607 last_action_insn
= iter
;
2609 else if (NOTE_P (iter
)
2610 && NOTE_KIND (iter
) == NOTE_INSN_SWITCH_TEXT_SECTIONS
)
2612 gcc_assert (section_switch_note
== NULL_RTX
);
2613 gcc_assert (flag_reorder_blocks_and_partition
);
2614 section_switch_note
= iter
;
2615 if (first_no_action_insn
)
2617 first_no_action_insn_before_switch
= first_no_action_insn
;
2618 last_no_action_insn_before_switch
= last_action_insn
;
2619 first_no_action_insn
= NULL
;
2620 gcc_assert (last_action
== -1);
2623 /* Force closing of current EH region before section switch and
2624 opening a new one afterwards. */
2625 else if (last_action
!= -3)
2626 last_landing_pad
= pc_rtx
;
2627 if (crtl
->eh
.call_site_record_v
[cur_sec
])
2628 call_site_base
+= crtl
->eh
.call_site_record_v
[cur_sec
]->length ();
2630 gcc_assert (crtl
->eh
.call_site_record_v
[cur_sec
] == NULL
);
2631 vec_alloc (crtl
->eh
.call_site_record_v
[cur_sec
], 10);
2634 if (last_action
>= -1 && ! first_no_action_insn
)
2636 note
= emit_note_eh_region_end (last_action_insn
);
2637 NOTE_EH_HANDLER (note
) = call_site
;
2640 call_site_base
= saved_call_site_base
;
2647 const pass_data pass_data_convert_to_eh_region_ranges
=
2649 RTL_PASS
, /* type */
2650 "eh_ranges", /* name */
2651 OPTGROUP_NONE
, /* optinfo_flags */
2652 TV_NONE
, /* tv_id */
2653 0, /* properties_required */
2654 0, /* properties_provided */
2655 0, /* properties_destroyed */
2656 0, /* todo_flags_start */
2657 0, /* todo_flags_finish */
2660 class pass_convert_to_eh_region_ranges
: public rtl_opt_pass
2663 pass_convert_to_eh_region_ranges (gcc::context
*ctxt
)
2664 : rtl_opt_pass (pass_data_convert_to_eh_region_ranges
, ctxt
)
2667 /* opt_pass methods: */
2668 virtual bool gate (function
*);
2669 virtual unsigned int execute (function
*)
2671 return convert_to_eh_region_ranges ();
2674 }; // class pass_convert_to_eh_region_ranges
2677 pass_convert_to_eh_region_ranges::gate (function
*)
2679 /* Nothing to do for SJLJ exceptions or if no regions created. */
2680 if (cfun
->eh
->region_tree
== NULL
)
2682 if (targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
)
2690 make_pass_convert_to_eh_region_ranges (gcc::context
*ctxt
)
2692 return new pass_convert_to_eh_region_ranges (ctxt
);
2696 push_uleb128 (vec
<uchar
, va_gc
> **data_area
, unsigned int value
)
2700 unsigned char byte
= value
& 0x7f;
2704 vec_safe_push (*data_area
, byte
);
2710 push_sleb128 (vec
<uchar
, va_gc
> **data_area
, int value
)
2717 byte
= value
& 0x7f;
2719 more
= ! ((value
== 0 && (byte
& 0x40) == 0)
2720 || (value
== -1 && (byte
& 0x40) != 0));
2723 vec_safe_push (*data_area
, byte
);
2729 #ifndef HAVE_AS_LEB128
2731 dw2_size_of_call_site_table (int section
)
2733 int n
= vec_safe_length (crtl
->eh
.call_site_record_v
[section
]);
2734 int size
= n
* (4 + 4 + 4);
2737 for (i
= 0; i
< n
; ++i
)
2739 struct call_site_record_d
*cs
=
2740 (*crtl
->eh
.call_site_record_v
[section
])[i
];
2741 size
+= size_of_uleb128 (cs
->action
);
2748 sjlj_size_of_call_site_table (void)
2750 int n
= vec_safe_length (crtl
->eh
.call_site_record_v
[0]);
2754 for (i
= 0; i
< n
; ++i
)
2756 struct call_site_record_d
*cs
=
2757 (*crtl
->eh
.call_site_record_v
[0])[i
];
2758 size
+= size_of_uleb128 (INTVAL (cs
->landing_pad
));
2759 size
+= size_of_uleb128 (cs
->action
);
2767 dw2_output_call_site_table (int cs_format
, int section
)
2769 int n
= vec_safe_length (crtl
->eh
.call_site_record_v
[section
]);
2774 begin
= current_function_func_begin_label
;
2775 else if (first_function_block_is_cold
)
2776 begin
= crtl
->subsections
.hot_section_label
;
2778 begin
= crtl
->subsections
.cold_section_label
;
2780 for (i
= 0; i
< n
; ++i
)
2782 struct call_site_record_d
*cs
= (*crtl
->eh
.call_site_record_v
[section
])[i
];
2783 char reg_start_lab
[32];
2784 char reg_end_lab
[32];
2785 char landing_pad_lab
[32];
2787 ASM_GENERATE_INTERNAL_LABEL (reg_start_lab
, "LEHB", call_site_base
+ i
);
2788 ASM_GENERATE_INTERNAL_LABEL (reg_end_lab
, "LEHE", call_site_base
+ i
);
2790 if (cs
->landing_pad
)
2791 ASM_GENERATE_INTERNAL_LABEL (landing_pad_lab
, "L",
2792 CODE_LABEL_NUMBER (cs
->landing_pad
));
2794 /* ??? Perhaps use insn length scaling if the assembler supports
2795 generic arithmetic. */
2796 /* ??? Perhaps use attr_length to choose data1 or data2 instead of
2797 data4 if the function is small enough. */
2798 if (cs_format
== DW_EH_PE_uleb128
)
2800 dw2_asm_output_delta_uleb128 (reg_start_lab
, begin
,
2801 "region %d start", i
);
2802 dw2_asm_output_delta_uleb128 (reg_end_lab
, reg_start_lab
,
2804 if (cs
->landing_pad
)
2805 dw2_asm_output_delta_uleb128 (landing_pad_lab
, begin
,
2808 dw2_asm_output_data_uleb128 (0, "landing pad");
2812 dw2_asm_output_delta (4, reg_start_lab
, begin
,
2813 "region %d start", i
);
2814 dw2_asm_output_delta (4, reg_end_lab
, reg_start_lab
, "length");
2815 if (cs
->landing_pad
)
2816 dw2_asm_output_delta (4, landing_pad_lab
, begin
,
2819 dw2_asm_output_data (4, 0, "landing pad");
2821 dw2_asm_output_data_uleb128 (cs
->action
, "action");
2824 call_site_base
+= n
;
2828 sjlj_output_call_site_table (void)
2830 int n
= vec_safe_length (crtl
->eh
.call_site_record_v
[0]);
2833 for (i
= 0; i
< n
; ++i
)
2835 struct call_site_record_d
*cs
= (*crtl
->eh
.call_site_record_v
[0])[i
];
2837 dw2_asm_output_data_uleb128 (INTVAL (cs
->landing_pad
),
2838 "region %d landing pad", i
);
2839 dw2_asm_output_data_uleb128 (cs
->action
, "action");
2842 call_site_base
+= n
;
2845 /* Switch to the section that should be used for exception tables. */
2848 switch_to_exception_section (const char * ARG_UNUSED (fnname
))
2852 if (exception_section
)
2853 s
= exception_section
;
2856 /* Compute the section and cache it into exception_section,
2857 unless it depends on the function name. */
2858 if (targetm_common
.have_named_sections
)
2862 if (EH_TABLES_CAN_BE_READ_ONLY
)
2865 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/1);
2866 flags
= ((! flag_pic
2867 || ((tt_format
& 0x70) != DW_EH_PE_absptr
2868 && (tt_format
& 0x70) != DW_EH_PE_aligned
))
2869 ? 0 : SECTION_WRITE
);
2872 flags
= SECTION_WRITE
;
2874 #ifdef HAVE_LD_EH_GC_SECTIONS
2875 if (flag_function_sections
2876 || (DECL_COMDAT_GROUP (current_function_decl
) && HAVE_COMDAT_GROUP
))
2878 char *section_name
= XNEWVEC (char, strlen (fnname
) + 32);
2879 /* The EH table must match the code section, so only mark
2880 it linkonce if we have COMDAT groups to tie them together. */
2881 if (DECL_COMDAT_GROUP (current_function_decl
) && HAVE_COMDAT_GROUP
)
2882 flags
|= SECTION_LINKONCE
;
2883 sprintf (section_name
, ".gcc_except_table.%s", fnname
);
2884 s
= get_section (section_name
, flags
, current_function_decl
);
2885 free (section_name
);
2890 = s
= get_section (".gcc_except_table", flags
, NULL
);
2894 = s
= flag_pic
? data_section
: readonly_data_section
;
2897 switch_to_section (s
);
2901 /* Output a reference from an exception table to the type_info object TYPE.
2902 TT_FORMAT and TT_FORMAT_SIZE describe the DWARF encoding method used for
2906 output_ttype (tree type
, int tt_format
, int tt_format_size
)
2909 bool is_public
= true;
2911 if (type
== NULL_TREE
)
2915 /* FIXME lto. pass_ipa_free_lang_data changes all types to
2916 runtime types so TYPE should already be a runtime type
2917 reference. When pass_ipa_free_lang data is made a default
2918 pass, we can then remove the call to lookup_type_for_runtime
2921 type
= lookup_type_for_runtime (type
);
2923 value
= expand_expr (type
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
2925 /* Let cgraph know that the rtti decl is used. Not all of the
2926 paths below go through assemble_integer, which would take
2927 care of this for us. */
2929 if (TREE_CODE (type
) == ADDR_EXPR
)
2931 type
= TREE_OPERAND (type
, 0);
2932 if (TREE_CODE (type
) == VAR_DECL
)
2933 is_public
= TREE_PUBLIC (type
);
2936 gcc_assert (TREE_CODE (type
) == INTEGER_CST
);
2939 /* Allow the target to override the type table entry format. */
2940 if (targetm
.asm_out
.ttype (value
))
2943 if (tt_format
== DW_EH_PE_absptr
|| tt_format
== DW_EH_PE_aligned
)
2944 assemble_integer (value
, tt_format_size
,
2945 tt_format_size
* BITS_PER_UNIT
, 1);
2947 dw2_asm_output_encoded_addr_rtx (tt_format
, value
, is_public
, NULL
);
2951 output_one_function_exception_table (int section
)
2953 int tt_format
, cs_format
, lp_format
, i
;
2954 #ifdef HAVE_AS_LEB128
2955 char ttype_label
[32];
2956 char cs_after_size_label
[32];
2957 char cs_end_label
[32];
2962 int tt_format_size
= 0;
2964 have_tt_data
= (vec_safe_length (cfun
->eh
->ttype_data
)
2965 || (targetm
.arm_eabi_unwinder
2966 ? vec_safe_length (cfun
->eh
->ehspec_data
.arm_eabi
)
2967 : vec_safe_length (cfun
->eh
->ehspec_data
.other
)));
2969 /* Indicate the format of the @TType entries. */
2971 tt_format
= DW_EH_PE_omit
;
2974 tt_format
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/1);
2975 #ifdef HAVE_AS_LEB128
2976 ASM_GENERATE_INTERNAL_LABEL (ttype_label
,
2977 section
? "LLSDATTC" : "LLSDATT",
2978 current_function_funcdef_no
);
2980 tt_format_size
= size_of_encoded_value (tt_format
);
2982 assemble_align (tt_format_size
* BITS_PER_UNIT
);
2985 targetm
.asm_out
.internal_label (asm_out_file
, section
? "LLSDAC" : "LLSDA",
2986 current_function_funcdef_no
);
2988 /* The LSDA header. */
2990 /* Indicate the format of the landing pad start pointer. An omitted
2991 field implies @LPStart == @Start. */
2992 /* Currently we always put @LPStart == @Start. This field would
2993 be most useful in moving the landing pads completely out of
2994 line to another section, but it could also be used to minimize
2995 the size of uleb128 landing pad offsets. */
2996 lp_format
= DW_EH_PE_omit
;
2997 dw2_asm_output_data (1, lp_format
, "@LPStart format (%s)",
2998 eh_data_format_name (lp_format
));
3000 /* @LPStart pointer would go here. */
3002 dw2_asm_output_data (1, tt_format
, "@TType format (%s)",
3003 eh_data_format_name (tt_format
));
3005 #ifndef HAVE_AS_LEB128
3006 if (targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
)
3007 call_site_len
= sjlj_size_of_call_site_table ();
3009 call_site_len
= dw2_size_of_call_site_table (section
);
3012 /* A pc-relative 4-byte displacement to the @TType data. */
3015 #ifdef HAVE_AS_LEB128
3016 char ttype_after_disp_label
[32];
3017 ASM_GENERATE_INTERNAL_LABEL (ttype_after_disp_label
,
3018 section
? "LLSDATTDC" : "LLSDATTD",
3019 current_function_funcdef_no
);
3020 dw2_asm_output_delta_uleb128 (ttype_label
, ttype_after_disp_label
,
3021 "@TType base offset");
3022 ASM_OUTPUT_LABEL (asm_out_file
, ttype_after_disp_label
);
3024 /* Ug. Alignment queers things. */
3025 unsigned int before_disp
, after_disp
, last_disp
, disp
;
3027 before_disp
= 1 + 1;
3028 after_disp
= (1 + size_of_uleb128 (call_site_len
)
3030 + vec_safe_length (crtl
->eh
.action_record_data
)
3031 + (vec_safe_length (cfun
->eh
->ttype_data
)
3037 unsigned int disp_size
, pad
;
3040 disp_size
= size_of_uleb128 (disp
);
3041 pad
= before_disp
+ disp_size
+ after_disp
;
3042 if (pad
% tt_format_size
)
3043 pad
= tt_format_size
- (pad
% tt_format_size
);
3046 disp
= after_disp
+ pad
;
3048 while (disp
!= last_disp
);
3050 dw2_asm_output_data_uleb128 (disp
, "@TType base offset");
3054 /* Indicate the format of the call-site offsets. */
3055 #ifdef HAVE_AS_LEB128
3056 cs_format
= DW_EH_PE_uleb128
;
3058 cs_format
= DW_EH_PE_udata4
;
3060 dw2_asm_output_data (1, cs_format
, "call-site format (%s)",
3061 eh_data_format_name (cs_format
));
3063 #ifdef HAVE_AS_LEB128
3064 ASM_GENERATE_INTERNAL_LABEL (cs_after_size_label
,
3065 section
? "LLSDACSBC" : "LLSDACSB",
3066 current_function_funcdef_no
);
3067 ASM_GENERATE_INTERNAL_LABEL (cs_end_label
,
3068 section
? "LLSDACSEC" : "LLSDACSE",
3069 current_function_funcdef_no
);
3070 dw2_asm_output_delta_uleb128 (cs_end_label
, cs_after_size_label
,
3071 "Call-site table length");
3072 ASM_OUTPUT_LABEL (asm_out_file
, cs_after_size_label
);
3073 if (targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
)
3074 sjlj_output_call_site_table ();
3076 dw2_output_call_site_table (cs_format
, section
);
3077 ASM_OUTPUT_LABEL (asm_out_file
, cs_end_label
);
3079 dw2_asm_output_data_uleb128 (call_site_len
, "Call-site table length");
3080 if (targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
)
3081 sjlj_output_call_site_table ();
3083 dw2_output_call_site_table (cs_format
, section
);
3086 /* ??? Decode and interpret the data for flag_debug_asm. */
3089 FOR_EACH_VEC_ELT (*crtl
->eh
.action_record_data
, i
, uc
)
3090 dw2_asm_output_data (1, uc
, i
? NULL
: "Action record table");
3094 assemble_align (tt_format_size
* BITS_PER_UNIT
);
3096 i
= vec_safe_length (cfun
->eh
->ttype_data
);
3099 tree type
= (*cfun
->eh
->ttype_data
)[i
];
3100 output_ttype (type
, tt_format
, tt_format_size
);
3103 #ifdef HAVE_AS_LEB128
3105 ASM_OUTPUT_LABEL (asm_out_file
, ttype_label
);
3108 /* ??? Decode and interpret the data for flag_debug_asm. */
3109 if (targetm
.arm_eabi_unwinder
)
3113 vec_safe_iterate (cfun
->eh
->ehspec_data
.arm_eabi
, i
, &type
); ++i
)
3114 output_ttype (type
, tt_format
, tt_format_size
);
3120 vec_safe_iterate (cfun
->eh
->ehspec_data
.other
, i
, &uc
); ++i
)
3121 dw2_asm_output_data (1, uc
,
3122 i
? NULL
: "Exception specification table");
3127 output_function_exception_table (const char *fnname
)
3129 rtx personality
= get_personality_function (current_function_decl
);
3131 /* Not all functions need anything. */
3132 if (! crtl
->uses_eh_lsda
)
3137 assemble_external_libcall (personality
);
3139 if (targetm
.asm_out
.emit_except_personality
)
3140 targetm
.asm_out
.emit_except_personality (personality
);
3143 switch_to_exception_section (fnname
);
3145 /* If the target wants a label to begin the table, emit it here. */
3146 targetm
.asm_out
.emit_except_table_label (asm_out_file
);
3148 output_one_function_exception_table (0);
3149 if (crtl
->eh
.call_site_record_v
[1])
3150 output_one_function_exception_table (1);
3152 switch_to_section (current_function_section ());
3156 set_eh_throw_stmt_table (function
*fun
, hash_map
<gimple
, int> *table
)
3158 fun
->eh
->throw_stmt_table
= table
;
3161 hash_map
<gimple
, int> *
3162 get_eh_throw_stmt_table (struct function
*fun
)
3164 return fun
->eh
->throw_stmt_table
;
3167 /* Determine if the function needs an EH personality function. */
3169 enum eh_personality_kind
3170 function_needs_eh_personality (struct function
*fn
)
3172 enum eh_personality_kind kind
= eh_personality_none
;
3175 FOR_ALL_EH_REGION_FN (i
, fn
)
3180 /* Can do with any personality including the generic C one. */
3181 kind
= eh_personality_any
;
3185 case ERT_ALLOWED_EXCEPTIONS
:
3186 /* Always needs a EH personality function. The generic C
3187 personality doesn't handle these even for empty type lists. */
3188 return eh_personality_lang
;
3190 case ERT_MUST_NOT_THROW
:
3191 /* Always needs a EH personality function. The language may specify
3192 what abort routine that must be used, e.g. std::terminate. */
3193 return eh_personality_lang
;
3200 /* Dump EH information to OUT. */
3203 dump_eh_tree (FILE * out
, struct function
*fun
)
3207 static const char *const type_name
[] = {
3208 "cleanup", "try", "allowed_exceptions", "must_not_throw"
3211 i
= fun
->eh
->region_tree
;
3215 fprintf (out
, "Eh tree:\n");
3218 fprintf (out
, " %*s %i %s", depth
* 2, "",
3219 i
->index
, type_name
[(int) i
->type
]);
3221 if (i
->landing_pads
)
3225 fprintf (out
, " land:");
3226 if (current_ir_type () == IR_GIMPLE
)
3228 for (lp
= i
->landing_pads
; lp
; lp
= lp
->next_lp
)
3230 fprintf (out
, "{%i,", lp
->index
);
3231 print_generic_expr (out
, lp
->post_landing_pad
, 0);
3239 for (lp
= i
->landing_pads
; lp
; lp
= lp
->next_lp
)
3241 fprintf (out
, "{%i,", lp
->index
);
3242 if (lp
->landing_pad
)
3243 fprintf (out
, "%i%s,", INSN_UID (lp
->landing_pad
),
3244 NOTE_P (lp
->landing_pad
) ? "(del)" : "");
3246 fprintf (out
, "(nil),");
3247 if (lp
->post_landing_pad
)
3249 rtx_insn
*lab
= label_rtx (lp
->post_landing_pad
);
3250 fprintf (out
, "%i%s}", INSN_UID (lab
),
3251 NOTE_P (lab
) ? "(del)" : "");
3254 fprintf (out
, "(nil)}");
3264 case ERT_MUST_NOT_THROW
:
3270 fprintf (out
, " catch:");
3271 for (c
= i
->u
.eh_try
.first_catch
; c
; c
= c
->next_catch
)
3276 fprintf (out
, "lab:");
3277 print_generic_expr (out
, c
->label
, 0);
3280 print_generic_expr (out
, c
->type_list
, 0);
3288 case ERT_ALLOWED_EXCEPTIONS
:
3289 fprintf (out
, " filter :%i types:", i
->u
.allowed
.filter
);
3290 print_generic_expr (out
, i
->u
.allowed
.type_list
, 0);
3295 /* If there are sub-regions, process them. */
3297 i
= i
->inner
, depth
++;
3298 /* If there are peers, process them. */
3299 else if (i
->next_peer
)
3301 /* Otherwise, step back up the tree to the next peer. */
3311 while (i
->next_peer
== NULL
);
3317 /* Dump the EH tree for FN on stderr. */
3320 debug_eh_tree (struct function
*fn
)
3322 dump_eh_tree (stderr
, fn
);
3325 /* Verify invariants on EH datastructures. */
3328 verify_eh_tree (struct function
*fun
)
3331 int nvisited_lp
, nvisited_r
;
3332 int count_lp
, count_r
, depth
, i
;
3336 if (!fun
->eh
->region_tree
)
3340 for (i
= 1; vec_safe_iterate (fun
->eh
->region_array
, i
, &r
); ++i
)
3347 error ("region_array is corrupted for region %i", r
->index
);
3353 for (i
= 1; vec_safe_iterate (fun
->eh
->lp_array
, i
, &lp
); ++i
)
3360 error ("lp_array is corrupted for lp %i", lp
->index
);
3365 depth
= nvisited_lp
= nvisited_r
= 0;
3367 r
= fun
->eh
->region_tree
;
3370 if ((*fun
->eh
->region_array
)[r
->index
] != r
)
3372 error ("region_array is corrupted for region %i", r
->index
);
3375 if (r
->outer
!= outer
)
3377 error ("outer block of region %i is wrong", r
->index
);
3382 error ("negative nesting depth of region %i", r
->index
);
3387 for (lp
= r
->landing_pads
; lp
; lp
= lp
->next_lp
)
3389 if ((*fun
->eh
->lp_array
)[lp
->index
] != lp
)
3391 error ("lp_array is corrupted for lp %i", lp
->index
);
3394 if (lp
->region
!= r
)
3396 error ("region of lp %i is wrong", lp
->index
);
3403 outer
= r
, r
= r
->inner
, depth
++;
3404 else if (r
->next_peer
)
3416 while (r
->next_peer
== NULL
);
3423 error ("tree list ends on depth %i", depth
);
3426 if (count_r
!= nvisited_r
)
3428 error ("region_array does not match region_tree");
3431 if (count_lp
!= nvisited_lp
)
3433 error ("lp_array does not match region_tree");
3439 dump_eh_tree (stderr
, fun
);
3440 internal_error ("verify_eh_tree failed");
3444 #include "gt-except.h"