1 /* Implements exception handling.
2 Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
4 Contributed by Mike Stump <mrs@cygnus.com>.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
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
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 /* An exception is an event that can be signaled from within a
25 function. This event can then be "caught" or "trapped" by the
26 callers of this function. This potentially allows program flow to
27 be transferred to any arbitrary code associated with a function call
28 several levels up the stack.
30 The intended use for this mechanism is for signaling "exceptional
31 events" in an out-of-band fashion, hence its name. The C++ language
32 (and many other OO-styled or functional languages) practically
33 requires such a mechanism, as otherwise it becomes very difficult
34 or even impossible to signal failure conditions in complex
35 situations. The traditional C++ example is when an error occurs in
36 the process of constructing an object; without such a mechanism, it
37 is impossible to signal that the error occurs without adding global
38 state variables and error checks around every object construction.
40 The act of causing this event to occur is referred to as "throwing
41 an exception". (Alternate terms include "raising an exception" or
42 "signaling an exception".) The term "throw" is used because control
43 is returned to the callers of the function that is signaling the
44 exception, and thus there is the concept of "throwing" the
45 exception up the call stack.
47 [ Add updated documentation on how to use this. ] */
58 #include "insn-config.h"
60 #include "integrate.h"
61 #include "hard-reg-set.h"
62 #include "basic-block.h"
64 #include "dwarf2asm.h"
65 #include "dwarf2out.h"
73 #include "langhooks.h"
75 /* Provide defaults for stuff that may not be defined when using
77 #ifndef EH_RETURN_STACKADJ_RTX
78 #define EH_RETURN_STACKADJ_RTX 0
80 #ifndef EH_RETURN_HANDLER_RTX
81 #define EH_RETURN_HANDLER_RTX 0
83 #ifndef EH_RETURN_DATA_REGNO
84 #define EH_RETURN_DATA_REGNO(N) INVALID_REGNUM
88 /* Nonzero means enable synchronous exceptions for non-call instructions. */
89 int flag_non_call_exceptions;
91 /* Protect cleanup actions with must-not-throw regions, with a call
92 to the given failure handler. */
93 tree (*lang_protect_cleanup_actions) PARAMS ((void));
95 /* Return true if type A catches type B. */
96 int (*lang_eh_type_covers) PARAMS ((tree a, tree b));
98 /* Map a type to a runtime object to match type. */
99 tree (*lang_eh_runtime_type) PARAMS ((tree));
101 /* A list of labels used for exception handlers. */
102 rtx exception_handler_labels;
104 static int call_site_base;
105 static unsigned int sjlj_funcdef_number;
106 static htab_t type_to_runtime_map;
108 /* Describe the SjLj_Function_Context structure. */
109 static tree sjlj_fc_type_node;
110 static int sjlj_fc_call_site_ofs;
111 static int sjlj_fc_data_ofs;
112 static int sjlj_fc_personality_ofs;
113 static int sjlj_fc_lsda_ofs;
114 static int sjlj_fc_jbuf_ofs;
116 /* Describes one exception region. */
119 /* The immediately surrounding region. */
120 struct eh_region *outer;
122 /* The list of immediately contained regions. */
123 struct eh_region *inner;
124 struct eh_region *next_peer;
126 /* An identifier for this region. */
129 /* Each region does exactly one thing. */
136 ERT_ALLOWED_EXCEPTIONS,
142 /* Holds the action to perform based on the preceding type. */
144 /* A list of catch blocks, a surrounding try block,
145 and the label for continuing after a catch. */
147 struct eh_region *catch;
148 struct eh_region *last_catch;
149 struct eh_region *prev_try;
153 /* The list through the catch handlers, the list of type objects
154 matched, and the list of associated filters. */
156 struct eh_region *next_catch;
157 struct eh_region *prev_catch;
162 /* A tree_list of allowed types. */
168 /* The type given by a call to "throw foo();", or discovered
174 /* Retain the cleanup expression even after expansion so that
175 we can match up fixup regions. */
180 /* The real region (by expression and by pointer) that fixup code
184 struct eh_region *real_region;
188 /* Entry point for this region's handler before landing pads are built. */
191 /* Entry point for this region's handler from the runtime eh library. */
194 /* Entry point for this region's handler from an inner region. */
195 rtx post_landing_pad;
197 /* The RESX insn for handing off control to the next outermost handler,
202 /* Used to save exception status for each function. */
205 /* The tree of all regions for this function. */
206 struct eh_region *region_tree;
208 /* The same information as an indexable array. */
209 struct eh_region **region_array;
211 /* The most recently open region. */
212 struct eh_region *cur_region;
214 /* This is the region for which we are processing catch blocks. */
215 struct eh_region *try_region;
220 int built_landing_pads;
221 int last_region_number;
223 varray_type ttype_data;
224 varray_type ehspec_data;
225 varray_type action_record_data;
227 struct call_site_record
232 int call_site_data_used;
233 int call_site_data_size;
244 static void mark_eh_region PARAMS ((struct eh_region *));
246 static int t2r_eq PARAMS ((const PTR,
248 static hashval_t t2r_hash PARAMS ((const PTR));
249 static int t2r_mark_1 PARAMS ((PTR *, PTR));
250 static void t2r_mark PARAMS ((PTR));
251 static void add_type_for_runtime PARAMS ((tree));
252 static tree lookup_type_for_runtime PARAMS ((tree));
254 static struct eh_region *expand_eh_region_end PARAMS ((void));
256 static rtx get_exception_filter PARAMS ((struct function *));
258 static void collect_eh_region_array PARAMS ((void));
259 static void resolve_fixup_regions PARAMS ((void));
260 static void remove_fixup_regions PARAMS ((void));
261 static void remove_unreachable_regions PARAMS ((rtx));
262 static void convert_from_eh_region_ranges_1 PARAMS ((rtx *, int *, int));
264 static struct eh_region *duplicate_eh_region_1 PARAMS ((struct eh_region *,
265 struct inline_remap *));
266 static void duplicate_eh_region_2 PARAMS ((struct eh_region *,
267 struct eh_region **));
268 static int ttypes_filter_eq PARAMS ((const PTR,
270 static hashval_t ttypes_filter_hash PARAMS ((const PTR));
271 static int ehspec_filter_eq PARAMS ((const PTR,
273 static hashval_t ehspec_filter_hash PARAMS ((const PTR));
274 static int add_ttypes_entry PARAMS ((htab_t, tree));
275 static int add_ehspec_entry PARAMS ((htab_t, htab_t,
277 static void assign_filter_values PARAMS ((void));
278 static void build_post_landing_pads PARAMS ((void));
279 static void connect_post_landing_pads PARAMS ((void));
280 static void dw2_build_landing_pads PARAMS ((void));
283 static bool sjlj_find_directly_reachable_regions
284 PARAMS ((struct sjlj_lp_info *));
285 static void sjlj_assign_call_site_values
286 PARAMS ((rtx, struct sjlj_lp_info *));
287 static void sjlj_mark_call_sites
288 PARAMS ((struct sjlj_lp_info *));
289 static void sjlj_emit_function_enter PARAMS ((rtx));
290 static void sjlj_emit_function_exit PARAMS ((void));
291 static void sjlj_emit_dispatch_table
292 PARAMS ((rtx, struct sjlj_lp_info *));
293 static void sjlj_build_landing_pads PARAMS ((void));
295 static void remove_exception_handler_label PARAMS ((rtx));
296 static void remove_eh_handler PARAMS ((struct eh_region *));
298 struct reachable_info;
300 /* The return value of reachable_next_level. */
303 /* The given exception is not processed by the given region. */
305 /* The given exception may need processing by the given region. */
307 /* The given exception is completely processed by the given region. */
309 /* The given exception is completely processed by the runtime. */
313 static int check_handled PARAMS ((tree, tree));
314 static void add_reachable_handler
315 PARAMS ((struct reachable_info *, struct eh_region *,
316 struct eh_region *));
317 static enum reachable_code reachable_next_level
318 PARAMS ((struct eh_region *, tree, struct reachable_info *));
320 static int action_record_eq PARAMS ((const PTR,
322 static hashval_t action_record_hash PARAMS ((const PTR));
323 static int add_action_record PARAMS ((htab_t, int, int));
324 static int collect_one_action_chain PARAMS ((htab_t,
325 struct eh_region *));
326 static int add_call_site PARAMS ((rtx, int));
328 static void push_uleb128 PARAMS ((varray_type *,
330 static void push_sleb128 PARAMS ((varray_type *, int));
331 #ifndef HAVE_AS_LEB128
332 static int dw2_size_of_call_site_table PARAMS ((void));
333 static int sjlj_size_of_call_site_table PARAMS ((void));
335 static void dw2_output_call_site_table PARAMS ((void));
336 static void sjlj_output_call_site_table PARAMS ((void));
339 /* Routine to see if exception handling is turned on.
340 DO_WARN is non-zero if we want to inform the user that exception
341 handling is turned off.
343 This is used to ensure that -fexceptions has been specified if the
344 compiler tries to use any exception-specific functions. */
350 if (! flag_exceptions)
352 static int warned = 0;
353 if (! warned && do_warn)
355 error ("exception handling disabled, use -fexceptions to enable");
367 ggc_add_rtx_root (&exception_handler_labels, 1);
369 if (! flag_exceptions)
372 type_to_runtime_map = htab_create (31, t2r_hash, t2r_eq, NULL);
373 ggc_add_root (&type_to_runtime_map, 1, sizeof (htab_t), t2r_mark);
375 /* Create the SjLj_Function_Context structure. This should match
376 the definition in unwind-sjlj.c. */
377 if (USING_SJLJ_EXCEPTIONS)
379 tree f_jbuf, f_per, f_lsda, f_prev, f_cs, f_data, tmp;
381 sjlj_fc_type_node = (*lang_hooks.types.make_type) (RECORD_TYPE);
382 ggc_add_tree_root (&sjlj_fc_type_node, 1);
384 f_prev = build_decl (FIELD_DECL, get_identifier ("__prev"),
385 build_pointer_type (sjlj_fc_type_node));
386 DECL_FIELD_CONTEXT (f_prev) = sjlj_fc_type_node;
388 f_cs = build_decl (FIELD_DECL, get_identifier ("__call_site"),
390 DECL_FIELD_CONTEXT (f_cs) = sjlj_fc_type_node;
392 tmp = build_index_type (build_int_2 (4 - 1, 0));
393 tmp = build_array_type ((*lang_hooks.types.type_for_mode) (word_mode, 1),
395 f_data = build_decl (FIELD_DECL, get_identifier ("__data"), tmp);
396 DECL_FIELD_CONTEXT (f_data) = sjlj_fc_type_node;
398 f_per = build_decl (FIELD_DECL, get_identifier ("__personality"),
400 DECL_FIELD_CONTEXT (f_per) = sjlj_fc_type_node;
402 f_lsda = build_decl (FIELD_DECL, get_identifier ("__lsda"),
404 DECL_FIELD_CONTEXT (f_lsda) = sjlj_fc_type_node;
406 #ifdef DONT_USE_BUILTIN_SETJMP
408 tmp = build_int_2 (JMP_BUF_SIZE - 1, 0);
410 /* Should be large enough for most systems, if it is not,
411 JMP_BUF_SIZE should be defined with the proper value. It will
412 also tend to be larger than necessary for most systems, a more
413 optimal port will define JMP_BUF_SIZE. */
414 tmp = build_int_2 (FIRST_PSEUDO_REGISTER + 2 - 1, 0);
417 /* This is 2 for builtin_setjmp, plus whatever the target requires
418 via STACK_SAVEAREA_MODE (SAVE_NONLOCAL). */
419 tmp = build_int_2 ((GET_MODE_SIZE (STACK_SAVEAREA_MODE (SAVE_NONLOCAL))
420 / GET_MODE_SIZE (Pmode)) + 2 - 1, 0);
422 tmp = build_index_type (tmp);
423 tmp = build_array_type (ptr_type_node, tmp);
424 f_jbuf = build_decl (FIELD_DECL, get_identifier ("__jbuf"), tmp);
425 #ifdef DONT_USE_BUILTIN_SETJMP
426 /* We don't know what the alignment requirements of the
427 runtime's jmp_buf has. Overestimate. */
428 DECL_ALIGN (f_jbuf) = BIGGEST_ALIGNMENT;
429 DECL_USER_ALIGN (f_jbuf) = 1;
431 DECL_FIELD_CONTEXT (f_jbuf) = sjlj_fc_type_node;
433 TYPE_FIELDS (sjlj_fc_type_node) = f_prev;
434 TREE_CHAIN (f_prev) = f_cs;
435 TREE_CHAIN (f_cs) = f_data;
436 TREE_CHAIN (f_data) = f_per;
437 TREE_CHAIN (f_per) = f_lsda;
438 TREE_CHAIN (f_lsda) = f_jbuf;
440 layout_type (sjlj_fc_type_node);
442 /* Cache the interesting field offsets so that we have
443 easy access from rtl. */
444 sjlj_fc_call_site_ofs
445 = (tree_low_cst (DECL_FIELD_OFFSET (f_cs), 1)
446 + tree_low_cst (DECL_FIELD_BIT_OFFSET (f_cs), 1) / BITS_PER_UNIT);
448 = (tree_low_cst (DECL_FIELD_OFFSET (f_data), 1)
449 + tree_low_cst (DECL_FIELD_BIT_OFFSET (f_data), 1) / BITS_PER_UNIT);
450 sjlj_fc_personality_ofs
451 = (tree_low_cst (DECL_FIELD_OFFSET (f_per), 1)
452 + tree_low_cst (DECL_FIELD_BIT_OFFSET (f_per), 1) / BITS_PER_UNIT);
454 = (tree_low_cst (DECL_FIELD_OFFSET (f_lsda), 1)
455 + tree_low_cst (DECL_FIELD_BIT_OFFSET (f_lsda), 1) / BITS_PER_UNIT);
457 = (tree_low_cst (DECL_FIELD_OFFSET (f_jbuf), 1)
458 + tree_low_cst (DECL_FIELD_BIT_OFFSET (f_jbuf), 1) / BITS_PER_UNIT);
463 init_eh_for_function ()
465 cfun->eh = (struct eh_status *) xcalloc (1, sizeof (struct eh_status));
468 /* Mark EH for GC. */
471 mark_eh_region (region)
472 struct eh_region *region;
477 switch (region->type)
480 /* This can happen if a nested function is inside the body of a region
481 and we do a GC as part of processing it. */
484 ggc_mark_tree (region->u.cleanup.exp);
487 ggc_mark_rtx (region->u.try.continue_label);
490 ggc_mark_tree (region->u.catch.type_list);
491 ggc_mark_tree (region->u.catch.filter_list);
493 case ERT_ALLOWED_EXCEPTIONS:
494 ggc_mark_tree (region->u.allowed.type_list);
496 case ERT_MUST_NOT_THROW:
499 ggc_mark_tree (region->u.throw.type);
502 ggc_mark_tree (region->u.fixup.cleanup_exp);
508 ggc_mark_rtx (region->label);
509 ggc_mark_rtx (region->resume);
510 ggc_mark_rtx (region->landing_pad);
511 ggc_mark_rtx (region->post_landing_pad);
516 struct eh_status *eh;
523 /* If we've called collect_eh_region_array, use it. Otherwise walk
524 the tree non-recursively. */
525 if (eh->region_array)
527 for (i = eh->last_region_number; i > 0; --i)
529 struct eh_region *r = eh->region_array[i];
530 if (r && r->region_number == i)
534 else if (eh->region_tree)
536 struct eh_region *r = eh->region_tree;
542 else if (r->next_peer)
550 } while (r->next_peer == NULL);
557 ggc_mark_rtx (eh->filter);
558 ggc_mark_rtx (eh->exc_ptr);
559 ggc_mark_tree_varray (eh->ttype_data);
561 if (eh->call_site_data)
563 for (i = eh->call_site_data_used - 1; i >= 0; --i)
564 ggc_mark_rtx (eh->call_site_data[i].landing_pad);
567 ggc_mark_rtx (eh->ehr_stackadj);
568 ggc_mark_rtx (eh->ehr_handler);
569 ggc_mark_rtx (eh->ehr_label);
571 ggc_mark_rtx (eh->sjlj_fc);
572 ggc_mark_rtx (eh->sjlj_exit_after);
579 struct eh_status *eh = f->eh;
581 if (eh->region_array)
584 for (i = eh->last_region_number; i > 0; --i)
586 struct eh_region *r = eh->region_array[i];
587 /* Mind we don't free a region struct more than once. */
588 if (r && r->region_number == i)
591 free (eh->region_array);
593 else if (eh->region_tree)
595 struct eh_region *next, *r = eh->region_tree;
600 else if (r->next_peer)
614 } while (r->next_peer == NULL);
623 VARRAY_FREE (eh->ttype_data);
624 VARRAY_FREE (eh->ehspec_data);
625 VARRAY_FREE (eh->action_record_data);
626 if (eh->call_site_data)
627 free (eh->call_site_data);
631 exception_handler_labels = NULL;
635 /* Start an exception handling region. All instructions emitted
636 after this point are considered to be part of the region until
637 expand_eh_region_end is invoked. */
640 expand_eh_region_start ()
642 struct eh_region *new_region;
643 struct eh_region *cur_region;
649 /* Insert a new blank region as a leaf in the tree. */
650 new_region = (struct eh_region *) xcalloc (1, sizeof (*new_region));
651 cur_region = cfun->eh->cur_region;
652 new_region->outer = cur_region;
655 new_region->next_peer = cur_region->inner;
656 cur_region->inner = new_region;
660 new_region->next_peer = cfun->eh->region_tree;
661 cfun->eh->region_tree = new_region;
663 cfun->eh->cur_region = new_region;
665 /* Create a note marking the start of this region. */
666 new_region->region_number = ++cfun->eh->last_region_number;
667 note = emit_note (NULL, NOTE_INSN_EH_REGION_BEG);
668 NOTE_EH_HANDLER (note) = new_region->region_number;
671 /* Common code to end a region. Returns the region just ended. */
673 static struct eh_region *
674 expand_eh_region_end ()
676 struct eh_region *cur_region = cfun->eh->cur_region;
679 /* Create a note marking the end of this region. */
680 note = emit_note (NULL, NOTE_INSN_EH_REGION_END);
681 NOTE_EH_HANDLER (note) = cur_region->region_number;
684 cfun->eh->cur_region = cur_region->outer;
689 /* End an exception handling region for a cleanup. HANDLER is an
690 expression to expand for the cleanup. */
693 expand_eh_region_end_cleanup (handler)
696 struct eh_region *region;
697 tree protect_cleanup_actions;
704 region = expand_eh_region_end ();
705 region->type = ERT_CLEANUP;
706 region->label = gen_label_rtx ();
707 region->u.cleanup.exp = handler;
709 around_label = gen_label_rtx ();
710 emit_jump (around_label);
712 emit_label (region->label);
714 /* Give the language a chance to specify an action to be taken if an
715 exception is thrown that would propagate out of the HANDLER. */
716 protect_cleanup_actions
717 = (lang_protect_cleanup_actions
718 ? (*lang_protect_cleanup_actions) ()
721 if (protect_cleanup_actions)
722 expand_eh_region_start ();
724 /* In case this cleanup involves an inline destructor with a try block in
725 it, we need to save the EH return data registers around it. */
726 data_save[0] = gen_reg_rtx (Pmode);
727 emit_move_insn (data_save[0], get_exception_pointer (cfun));
728 data_save[1] = gen_reg_rtx (word_mode);
729 emit_move_insn (data_save[1], get_exception_filter (cfun));
731 expand_expr (handler, const0_rtx, VOIDmode, 0);
733 emit_move_insn (cfun->eh->exc_ptr, data_save[0]);
734 emit_move_insn (cfun->eh->filter, data_save[1]);
736 if (protect_cleanup_actions)
737 expand_eh_region_end_must_not_throw (protect_cleanup_actions);
739 /* We need any stack adjustment complete before the around_label. */
740 do_pending_stack_adjust ();
742 /* We delay the generation of the _Unwind_Resume until we generate
743 landing pads. We emit a marker here so as to get good control
744 flow data in the meantime. */
746 = emit_jump_insn (gen_rtx_RESX (VOIDmode, region->region_number));
749 emit_label (around_label);
752 /* End an exception handling region for a try block, and prepares
753 for subsequent calls to expand_start_catch. */
756 expand_start_all_catch ()
758 struct eh_region *region;
763 region = expand_eh_region_end ();
764 region->type = ERT_TRY;
765 region->u.try.prev_try = cfun->eh->try_region;
766 region->u.try.continue_label = gen_label_rtx ();
768 cfun->eh->try_region = region;
770 emit_jump (region->u.try.continue_label);
773 /* Begin a catch clause. TYPE is the type caught, a list of such types, or
774 null if this is a catch-all clause. Providing a type list enables to
775 associate the catch region with potentially several exception types, which
776 is useful e.g. for Ada. */
779 expand_start_catch (type_or_list)
782 struct eh_region *t, *c, *l;
788 type_list = type_or_list;
792 /* Ensure to always end up with a type list to normalize further
793 processing, then register each type against the runtime types
797 if (TREE_CODE (type_or_list) != TREE_LIST)
798 type_list = tree_cons (NULL_TREE, type_or_list, NULL_TREE);
800 type_node = type_list;
801 for (; type_node; type_node = TREE_CHAIN (type_node))
802 add_type_for_runtime (TREE_VALUE (type_node));
805 expand_eh_region_start ();
807 t = cfun->eh->try_region;
808 c = cfun->eh->cur_region;
810 c->u.catch.type_list = type_list;
811 c->label = gen_label_rtx ();
813 l = t->u.try.last_catch;
814 c->u.catch.prev_catch = l;
816 l->u.catch.next_catch = c;
819 t->u.try.last_catch = c;
821 emit_label (c->label);
824 /* End a catch clause. Control will resume after the try/catch block. */
829 struct eh_region *try_region, *catch_region;
834 catch_region = expand_eh_region_end ();
835 try_region = cfun->eh->try_region;
837 emit_jump (try_region->u.try.continue_label);
840 /* End a sequence of catch handlers for a try block. */
843 expand_end_all_catch ()
845 struct eh_region *try_region;
850 try_region = cfun->eh->try_region;
851 cfun->eh->try_region = try_region->u.try.prev_try;
853 emit_label (try_region->u.try.continue_label);
856 /* End an exception region for an exception type filter. ALLOWED is a
857 TREE_LIST of types to be matched by the runtime. FAILURE is an
858 expression to invoke if a mismatch occurs.
860 ??? We could use these semantics for calls to rethrow, too; if we can
861 see the surrounding catch clause, we know that the exception we're
862 rethrowing satisfies the "filter" of the catch type. */
865 expand_eh_region_end_allowed (allowed, failure)
866 tree allowed, failure;
868 struct eh_region *region;
874 region = expand_eh_region_end ();
875 region->type = ERT_ALLOWED_EXCEPTIONS;
876 region->u.allowed.type_list = allowed;
877 region->label = gen_label_rtx ();
879 for (; allowed ; allowed = TREE_CHAIN (allowed))
880 add_type_for_runtime (TREE_VALUE (allowed));
882 /* We must emit the call to FAILURE here, so that if this function
883 throws a different exception, that it will be processed by the
886 around_label = gen_label_rtx ();
887 emit_jump (around_label);
889 emit_label (region->label);
890 expand_expr (failure, const0_rtx, VOIDmode, EXPAND_NORMAL);
891 /* We must adjust the stack before we reach the AROUND_LABEL because
892 the call to FAILURE does not occur on all paths to the
894 do_pending_stack_adjust ();
896 emit_label (around_label);
899 /* End an exception region for a must-not-throw filter. FAILURE is an
900 expression invoke if an uncaught exception propagates this far.
902 This is conceptually identical to expand_eh_region_end_allowed with
903 an empty allowed list (if you passed "std::terminate" instead of
904 "__cxa_call_unexpected"), but they are represented differently in
908 expand_eh_region_end_must_not_throw (failure)
911 struct eh_region *region;
917 region = expand_eh_region_end ();
918 region->type = ERT_MUST_NOT_THROW;
919 region->label = gen_label_rtx ();
921 /* We must emit the call to FAILURE here, so that if this function
922 throws a different exception, that it will be processed by the
925 around_label = gen_label_rtx ();
926 emit_jump (around_label);
928 emit_label (region->label);
929 expand_expr (failure, const0_rtx, VOIDmode, EXPAND_NORMAL);
931 emit_label (around_label);
934 /* End an exception region for a throw. No handling goes on here,
935 but it's the easiest way for the front-end to indicate what type
939 expand_eh_region_end_throw (type)
942 struct eh_region *region;
947 region = expand_eh_region_end ();
948 region->type = ERT_THROW;
949 region->u.throw.type = type;
952 /* End a fixup region. Within this region the cleanups for the immediately
953 enclosing region are _not_ run. This is used for goto cleanup to avoid
954 destroying an object twice.
956 This would be an extraordinarily simple prospect, were it not for the
957 fact that we don't actually know what the immediately enclosing region
958 is. This surprising fact is because expand_cleanups is currently
959 generating a sequence that it will insert somewhere else. We collect
960 the proper notion of "enclosing" in convert_from_eh_region_ranges. */
963 expand_eh_region_end_fixup (handler)
966 struct eh_region *fixup;
971 fixup = expand_eh_region_end ();
972 fixup->type = ERT_FIXUP;
973 fixup->u.fixup.cleanup_exp = handler;
976 /* Return an rtl expression for a pointer to the exception object
980 get_exception_pointer (fun)
981 struct function *fun;
983 rtx exc_ptr = fun->eh->exc_ptr;
984 if (fun == cfun && ! exc_ptr)
986 exc_ptr = gen_reg_rtx (Pmode);
987 fun->eh->exc_ptr = exc_ptr;
992 /* Return an rtl expression for the exception dispatch filter
996 get_exception_filter (fun)
997 struct function *fun;
999 rtx filter = fun->eh->filter;
1000 if (fun == cfun && ! filter)
1002 filter = gen_reg_rtx (word_mode);
1003 fun->eh->filter = filter;
1008 /* This section is for the exception handling specific optimization pass. */
1010 /* Random access the exception region tree. It's just as simple to
1011 collect the regions this way as in expand_eh_region_start, but
1012 without having to realloc memory. */
1015 collect_eh_region_array ()
1017 struct eh_region **array, *i;
1019 i = cfun->eh->region_tree;
1023 array = xcalloc (cfun->eh->last_region_number + 1, sizeof (*array));
1024 cfun->eh->region_array = array;
1028 array[i->region_number] = i;
1030 /* If there are sub-regions, process them. */
1033 /* If there are peers, process them. */
1034 else if (i->next_peer)
1036 /* Otherwise, step back up the tree to the next peer. */
1043 } while (i->next_peer == NULL);
1050 resolve_fixup_regions ()
1052 int i, j, n = cfun->eh->last_region_number;
1054 for (i = 1; i <= n; ++i)
1056 struct eh_region *fixup = cfun->eh->region_array[i];
1057 struct eh_region *cleanup = 0;
1059 if (! fixup || fixup->type != ERT_FIXUP)
1062 for (j = 1; j <= n; ++j)
1064 cleanup = cfun->eh->region_array[j];
1065 if (cleanup->type == ERT_CLEANUP
1066 && cleanup->u.cleanup.exp == fixup->u.fixup.cleanup_exp)
1072 fixup->u.fixup.real_region = cleanup->outer;
1076 /* Now that we've discovered what region actually encloses a fixup,
1077 we can shuffle pointers and remove them from the tree. */
1080 remove_fixup_regions ()
1084 struct eh_region *fixup;
1086 /* Walk the insn chain and adjust the REG_EH_REGION numbers
1087 for instructions referencing fixup regions. This is only
1088 strictly necessary for fixup regions with no parent, but
1089 doesn't hurt to do it for all regions. */
1090 for (insn = get_insns(); insn ; insn = NEXT_INSN (insn))
1092 && (note = find_reg_note (insn, REG_EH_REGION, NULL))
1093 && INTVAL (XEXP (note, 0)) > 0
1094 && (fixup = cfun->eh->region_array[INTVAL (XEXP (note, 0))])
1095 && fixup->type == ERT_FIXUP)
1097 if (fixup->u.fixup.real_region)
1098 XEXP (note, 0) = GEN_INT (fixup->u.fixup.real_region->region_number);
1100 remove_note (insn, note);
1103 /* Remove the fixup regions from the tree. */
1104 for (i = cfun->eh->last_region_number; i > 0; --i)
1106 fixup = cfun->eh->region_array[i];
1110 /* Allow GC to maybe free some memory. */
1111 if (fixup->type == ERT_CLEANUP)
1112 fixup->u.cleanup.exp = NULL_TREE;
1114 if (fixup->type != ERT_FIXUP)
1119 struct eh_region *parent, *p, **pp;
1121 parent = fixup->u.fixup.real_region;
1123 /* Fix up the children's parent pointers; find the end of
1125 for (p = fixup->inner; ; p = p->next_peer)
1132 /* In the tree of cleanups, only outer-inner ordering matters.
1133 So link the children back in anywhere at the correct level. */
1135 pp = &parent->inner;
1137 pp = &cfun->eh->region_tree;
1140 fixup->inner = NULL;
1143 remove_eh_handler (fixup);
1147 /* Remove all regions whose labels are not reachable from insns. */
1150 remove_unreachable_regions (insns)
1153 int i, *uid_region_num;
1155 struct eh_region *r;
1158 uid_region_num = xcalloc (get_max_uid (), sizeof(int));
1159 reachable = xcalloc (cfun->eh->last_region_number + 1, sizeof(bool));
1161 for (i = cfun->eh->last_region_number; i > 0; --i)
1163 r = cfun->eh->region_array[i];
1164 if (!r || r->region_number != i)
1169 if (uid_region_num[INSN_UID (r->resume)])
1171 uid_region_num[INSN_UID (r->resume)] = i;
1175 if (uid_region_num[INSN_UID (r->label)])
1177 uid_region_num[INSN_UID (r->label)] = i;
1179 if (r->type == ERT_TRY && r->u.try.continue_label)
1181 if (uid_region_num[INSN_UID (r->u.try.continue_label)])
1183 uid_region_num[INSN_UID (r->u.try.continue_label)] = i;
1187 for (insn = insns; insn; insn = NEXT_INSN (insn))
1188 reachable[uid_region_num[INSN_UID (insn)]] = true;
1190 for (i = cfun->eh->last_region_number; i > 0; --i)
1192 r = cfun->eh->region_array[i];
1193 if (r && r->region_number == i && !reachable[i])
1195 /* Don't remove ERT_THROW regions if their outer region
1197 if (r->type == ERT_THROW
1199 && reachable[r->outer->region_number])
1202 remove_eh_handler (r);
1207 free (uid_region_num);
1210 /* Turn NOTE_INSN_EH_REGION notes into REG_EH_REGION notes for each
1211 can_throw instruction in the region. */
1214 convert_from_eh_region_ranges_1 (pinsns, orig_sp, cur)
1222 for (insn = *pinsns; insn ; insn = next)
1224 next = NEXT_INSN (insn);
1225 if (GET_CODE (insn) == NOTE)
1227 int kind = NOTE_LINE_NUMBER (insn);
1228 if (kind == NOTE_INSN_EH_REGION_BEG
1229 || kind == NOTE_INSN_EH_REGION_END)
1231 if (kind == NOTE_INSN_EH_REGION_BEG)
1233 struct eh_region *r;
1236 cur = NOTE_EH_HANDLER (insn);
1238 r = cfun->eh->region_array[cur];
1239 if (r->type == ERT_FIXUP)
1241 r = r->u.fixup.real_region;
1242 cur = r ? r->region_number : 0;
1244 else if (r->type == ERT_CATCH)
1247 cur = r ? r->region_number : 0;
1253 /* Removing the first insn of a CALL_PLACEHOLDER sequence
1254 requires extra care to adjust sequence start. */
1255 if (insn == *pinsns)
1261 else if (INSN_P (insn))
1264 && ! find_reg_note (insn, REG_EH_REGION, NULL_RTX)
1265 /* Calls can always potentially throw exceptions, unless
1266 they have a REG_EH_REGION note with a value of 0 or less.
1267 Which should be the only possible kind so far. */
1268 && (GET_CODE (insn) == CALL_INSN
1269 /* If we wanted exceptions for non-call insns, then
1270 any may_trap_p instruction could throw. */
1271 || (flag_non_call_exceptions
1272 && GET_CODE (PATTERN (insn)) != CLOBBER
1273 && GET_CODE (PATTERN (insn)) != USE
1274 && may_trap_p (PATTERN (insn)))))
1276 REG_NOTES (insn) = alloc_EXPR_LIST (REG_EH_REGION, GEN_INT (cur),
1280 if (GET_CODE (insn) == CALL_INSN
1281 && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
1283 convert_from_eh_region_ranges_1 (&XEXP (PATTERN (insn), 0),
1285 convert_from_eh_region_ranges_1 (&XEXP (PATTERN (insn), 1),
1287 convert_from_eh_region_ranges_1 (&XEXP (PATTERN (insn), 2),
1298 convert_from_eh_region_ranges ()
1303 collect_eh_region_array ();
1304 resolve_fixup_regions ();
1306 stack = xmalloc (sizeof (int) * (cfun->eh->last_region_number + 1));
1307 insns = get_insns ();
1308 convert_from_eh_region_ranges_1 (&insns, stack, 0);
1311 remove_fixup_regions ();
1312 remove_unreachable_regions (insns);
1316 find_exception_handler_labels ()
1318 rtx list = NULL_RTX;
1321 free_EXPR_LIST_list (&exception_handler_labels);
1323 if (cfun->eh->region_tree == NULL)
1326 for (i = cfun->eh->last_region_number; i > 0; --i)
1328 struct eh_region *region = cfun->eh->region_array[i];
1331 if (! region || region->region_number != i)
1333 if (cfun->eh->built_landing_pads)
1334 lab = region->landing_pad;
1336 lab = region->label;
1339 list = alloc_EXPR_LIST (0, lab, list);
1342 /* For sjlj exceptions, need the return label to remain live until
1343 after landing pad generation. */
1344 if (USING_SJLJ_EXCEPTIONS && ! cfun->eh->built_landing_pads)
1345 list = alloc_EXPR_LIST (0, return_label, list);
1347 exception_handler_labels = list;
1351 current_function_has_exception_handlers ()
1355 for (i = cfun->eh->last_region_number; i > 0; --i)
1357 struct eh_region *region = cfun->eh->region_array[i];
1359 if (! region || region->region_number != i)
1361 if (region->type != ERT_THROW)
1368 static struct eh_region *
1369 duplicate_eh_region_1 (o, map)
1370 struct eh_region *o;
1371 struct inline_remap *map;
1374 = (struct eh_region *) xcalloc (1, sizeof (struct eh_region));
1376 n->region_number = o->region_number + cfun->eh->last_region_number;
1382 case ERT_MUST_NOT_THROW:
1386 if (o->u.try.continue_label)
1387 n->u.try.continue_label
1388 = get_label_from_map (map,
1389 CODE_LABEL_NUMBER (o->u.try.continue_label));
1393 n->u.catch.type_list = o->u.catch.type_list;
1396 case ERT_ALLOWED_EXCEPTIONS:
1397 n->u.allowed.type_list = o->u.allowed.type_list;
1401 n->u.throw.type = o->u.throw.type;
1408 n->label = get_label_from_map (map, CODE_LABEL_NUMBER (o->label));
1411 n->resume = map->insn_map[INSN_UID (o->resume)];
1412 if (n->resume == NULL)
1420 duplicate_eh_region_2 (o, n_array)
1421 struct eh_region *o;
1422 struct eh_region **n_array;
1424 struct eh_region *n = n_array[o->region_number];
1429 n->u.try.catch = n_array[o->u.try.catch->region_number];
1430 n->u.try.last_catch = n_array[o->u.try.last_catch->region_number];
1434 if (o->u.catch.next_catch)
1435 n->u.catch.next_catch = n_array[o->u.catch.next_catch->region_number];
1436 if (o->u.catch.prev_catch)
1437 n->u.catch.prev_catch = n_array[o->u.catch.prev_catch->region_number];
1445 n->outer = n_array[o->outer->region_number];
1447 n->inner = n_array[o->inner->region_number];
1449 n->next_peer = n_array[o->next_peer->region_number];
1453 duplicate_eh_regions (ifun, map)
1454 struct function *ifun;
1455 struct inline_remap *map;
1457 int ifun_last_region_number = ifun->eh->last_region_number;
1458 struct eh_region **n_array, *root, *cur;
1461 if (ifun_last_region_number == 0)
1464 n_array = xcalloc (ifun_last_region_number + 1, sizeof (*n_array));
1466 for (i = 1; i <= ifun_last_region_number; ++i)
1468 cur = ifun->eh->region_array[i];
1469 if (!cur || cur->region_number != i)
1471 n_array[i] = duplicate_eh_region_1 (cur, map);
1473 for (i = 1; i <= ifun_last_region_number; ++i)
1475 cur = ifun->eh->region_array[i];
1476 if (!cur || cur->region_number != i)
1478 duplicate_eh_region_2 (cur, n_array);
1481 root = n_array[ifun->eh->region_tree->region_number];
1482 cur = cfun->eh->cur_region;
1485 struct eh_region *p = cur->inner;
1488 while (p->next_peer)
1490 p->next_peer = root;
1495 for (i = 1; i <= ifun_last_region_number; ++i)
1496 if (n_array[i] && n_array[i]->outer == NULL)
1497 n_array[i]->outer = cur;
1501 struct eh_region *p = cfun->eh->region_tree;
1504 while (p->next_peer)
1506 p->next_peer = root;
1509 cfun->eh->region_tree = root;
1514 i = cfun->eh->last_region_number;
1515 cfun->eh->last_region_number = i + ifun_last_region_number;
1521 t2r_eq (pentry, pdata)
1525 tree entry = (tree) pentry;
1526 tree data = (tree) pdata;
1528 return TREE_PURPOSE (entry) == data;
1535 tree entry = (tree) pentry;
1536 return TYPE_HASH (TREE_PURPOSE (entry));
1540 t2r_mark_1 (slot, data)
1542 PTR data ATTRIBUTE_UNUSED;
1544 tree contents = (tree) *slot;
1545 ggc_mark_tree (contents);
1553 htab_traverse (*(htab_t *)addr, t2r_mark_1, NULL);
1557 add_type_for_runtime (type)
1562 slot = (tree *) htab_find_slot_with_hash (type_to_runtime_map, type,
1563 TYPE_HASH (type), INSERT);
1566 tree runtime = (*lang_eh_runtime_type) (type);
1567 *slot = tree_cons (type, runtime, NULL_TREE);
1572 lookup_type_for_runtime (type)
1577 slot = (tree *) htab_find_slot_with_hash (type_to_runtime_map, type,
1578 TYPE_HASH (type), NO_INSERT);
1580 /* We should have always inserted the data earlier. */
1581 return TREE_VALUE (*slot);
1585 /* Represent an entry in @TTypes for either catch actions
1586 or exception filter actions. */
1587 struct ttypes_filter
1593 /* Compare ENTRY (a ttypes_filter entry in the hash table) with DATA
1594 (a tree) for a @TTypes type node we are thinking about adding. */
1597 ttypes_filter_eq (pentry, pdata)
1601 const struct ttypes_filter *entry = (const struct ttypes_filter *) pentry;
1602 tree data = (tree) pdata;
1604 return entry->t == data;
1608 ttypes_filter_hash (pentry)
1611 const struct ttypes_filter *entry = (const struct ttypes_filter *) pentry;
1612 return TYPE_HASH (entry->t);
1615 /* Compare ENTRY with DATA (both struct ttypes_filter) for a @TTypes
1616 exception specification list we are thinking about adding. */
1617 /* ??? Currently we use the type lists in the order given. Someone
1618 should put these in some canonical order. */
1621 ehspec_filter_eq (pentry, pdata)
1625 const struct ttypes_filter *entry = (const struct ttypes_filter *) pentry;
1626 const struct ttypes_filter *data = (const struct ttypes_filter *) pdata;
1628 return type_list_equal (entry->t, data->t);
1631 /* Hash function for exception specification lists. */
1634 ehspec_filter_hash (pentry)
1637 const struct ttypes_filter *entry = (const struct ttypes_filter *) pentry;
1641 for (list = entry->t; list ; list = TREE_CHAIN (list))
1642 h = (h << 5) + (h >> 27) + TYPE_HASH (TREE_VALUE (list));
1646 /* Add TYPE to cfun->eh->ttype_data, using TYPES_HASH to speed
1647 up the search. Return the filter value to be used. */
1650 add_ttypes_entry (ttypes_hash, type)
1654 struct ttypes_filter **slot, *n;
1656 slot = (struct ttypes_filter **)
1657 htab_find_slot_with_hash (ttypes_hash, type, TYPE_HASH (type), INSERT);
1659 if ((n = *slot) == NULL)
1661 /* Filter value is a 1 based table index. */
1663 n = (struct ttypes_filter *) xmalloc (sizeof (*n));
1665 n->filter = VARRAY_ACTIVE_SIZE (cfun->eh->ttype_data) + 1;
1668 VARRAY_PUSH_TREE (cfun->eh->ttype_data, type);
1674 /* Add LIST to cfun->eh->ehspec_data, using EHSPEC_HASH and TYPES_HASH
1675 to speed up the search. Return the filter value to be used. */
1678 add_ehspec_entry (ehspec_hash, ttypes_hash, list)
1683 struct ttypes_filter **slot, *n;
1684 struct ttypes_filter dummy;
1687 slot = (struct ttypes_filter **)
1688 htab_find_slot (ehspec_hash, &dummy, INSERT);
1690 if ((n = *slot) == NULL)
1692 /* Filter value is a -1 based byte index into a uleb128 buffer. */
1694 n = (struct ttypes_filter *) xmalloc (sizeof (*n));
1696 n->filter = -(VARRAY_ACTIVE_SIZE (cfun->eh->ehspec_data) + 1);
1699 /* Look up each type in the list and encode its filter
1700 value as a uleb128. Terminate the list with 0. */
1701 for (; list ; list = TREE_CHAIN (list))
1702 push_uleb128 (&cfun->eh->ehspec_data,
1703 add_ttypes_entry (ttypes_hash, TREE_VALUE (list)));
1704 VARRAY_PUSH_UCHAR (cfun->eh->ehspec_data, 0);
1710 /* Generate the action filter values to be used for CATCH and
1711 ALLOWED_EXCEPTIONS regions. When using dwarf2 exception regions,
1712 we use lots of landing pads, and so every type or list can share
1713 the same filter value, which saves table space. */
1716 assign_filter_values ()
1719 htab_t ttypes, ehspec;
1721 VARRAY_TREE_INIT (cfun->eh->ttype_data, 16, "ttype_data");
1722 VARRAY_UCHAR_INIT (cfun->eh->ehspec_data, 64, "ehspec_data");
1724 ttypes = htab_create (31, ttypes_filter_hash, ttypes_filter_eq, free);
1725 ehspec = htab_create (31, ehspec_filter_hash, ehspec_filter_eq, free);
1727 for (i = cfun->eh->last_region_number; i > 0; --i)
1729 struct eh_region *r = cfun->eh->region_array[i];
1731 /* Mind we don't process a region more than once. */
1732 if (!r || r->region_number != i)
1738 /* Whatever type_list is (NULL or true list), we build a list
1739 of filters for the region. */
1740 r->u.catch.filter_list = NULL_TREE;
1742 if (r->u.catch.type_list != NULL)
1744 /* Get a filter value for each of the types caught and store
1745 them in the region's dedicated list. */
1746 tree tp_node = r->u.catch.type_list;
1748 for (;tp_node; tp_node = TREE_CHAIN (tp_node))
1750 int flt = add_ttypes_entry (ttypes, TREE_VALUE (tp_node));
1751 tree flt_node = build_int_2 (flt, 0);
1753 r->u.catch.filter_list
1754 = tree_cons (NULL_TREE, flt_node, r->u.catch.filter_list);
1759 /* Get a filter value for the NULL list also since it will need
1760 an action record anyway. */
1761 int flt = add_ttypes_entry (ttypes, NULL);
1762 tree flt_node = build_int_2 (flt, 0);
1764 r->u.catch.filter_list
1765 = tree_cons (NULL_TREE, flt_node, r->u.catch.filter_list);
1770 case ERT_ALLOWED_EXCEPTIONS:
1772 = add_ehspec_entry (ehspec, ttypes, r->u.allowed.type_list);
1780 htab_delete (ttypes);
1781 htab_delete (ehspec);
1785 build_post_landing_pads ()
1789 for (i = cfun->eh->last_region_number; i > 0; --i)
1791 struct eh_region *region = cfun->eh->region_array[i];
1794 /* Mind we don't process a region more than once. */
1795 if (!region || region->region_number != i)
1798 switch (region->type)
1801 /* ??? Collect the set of all non-overlapping catch handlers
1802 all the way up the chain until blocked by a cleanup. */
1803 /* ??? Outer try regions can share landing pads with inner
1804 try regions if the types are completely non-overlapping,
1805 and there are no intervening cleanups. */
1807 region->post_landing_pad = gen_label_rtx ();
1811 emit_label (region->post_landing_pad);
1813 /* ??? It is mighty inconvenient to call back into the
1814 switch statement generation code in expand_end_case.
1815 Rapid prototyping sez a sequence of ifs. */
1817 struct eh_region *c;
1818 for (c = region->u.try.catch; c ; c = c->u.catch.next_catch)
1820 /* ??? _Unwind_ForcedUnwind wants no match here. */
1821 if (c->u.catch.type_list == NULL)
1822 emit_jump (c->label);
1825 /* Need for one cmp/jump per type caught. Each type
1826 list entry has a matching entry in the filter list
1827 (see assign_filter_values). */
1828 tree tp_node = c->u.catch.type_list;
1829 tree flt_node = c->u.catch.filter_list;
1833 emit_cmp_and_jump_insns
1835 GEN_INT (tree_low_cst (TREE_VALUE (flt_node), 0)),
1836 EQ, NULL_RTX, word_mode, 0, c->label);
1838 tp_node = TREE_CHAIN (tp_node);
1839 flt_node = TREE_CHAIN (flt_node);
1845 /* We delay the generation of the _Unwind_Resume until we generate
1846 landing pads. We emit a marker here so as to get good control
1847 flow data in the meantime. */
1849 = emit_jump_insn (gen_rtx_RESX (VOIDmode, region->region_number));
1855 emit_insns_before (seq, region->u.try.catch->label);
1858 case ERT_ALLOWED_EXCEPTIONS:
1859 region->post_landing_pad = gen_label_rtx ();
1863 emit_label (region->post_landing_pad);
1865 emit_cmp_and_jump_insns (cfun->eh->filter,
1866 GEN_INT (region->u.allowed.filter),
1867 EQ, NULL_RTX, word_mode, 0, region->label);
1869 /* We delay the generation of the _Unwind_Resume until we generate
1870 landing pads. We emit a marker here so as to get good control
1871 flow data in the meantime. */
1873 = emit_jump_insn (gen_rtx_RESX (VOIDmode, region->region_number));
1879 emit_insns_before (seq, region->label);
1883 case ERT_MUST_NOT_THROW:
1884 region->post_landing_pad = region->label;
1889 /* Nothing to do. */
1898 /* Replace RESX patterns with jumps to the next handler if any, or calls to
1899 _Unwind_Resume otherwise. */
1902 connect_post_landing_pads ()
1906 for (i = cfun->eh->last_region_number; i > 0; --i)
1908 struct eh_region *region = cfun->eh->region_array[i];
1909 struct eh_region *outer;
1912 /* Mind we don't process a region more than once. */
1913 if (!region || region->region_number != i)
1916 /* If there is no RESX, or it has been deleted by flow, there's
1917 nothing to fix up. */
1918 if (! region->resume || INSN_DELETED_P (region->resume))
1921 /* Search for another landing pad in this function. */
1922 for (outer = region->outer; outer ; outer = outer->outer)
1923 if (outer->post_landing_pad)
1929 emit_jump (outer->post_landing_pad);
1931 emit_library_call (unwind_resume_libfunc, LCT_THROW,
1932 VOIDmode, 1, cfun->eh->exc_ptr, Pmode);
1936 emit_insns_before (seq, region->resume);
1937 delete_insn (region->resume);
1943 dw2_build_landing_pads ()
1948 for (i = cfun->eh->last_region_number; i > 0; --i)
1950 struct eh_region *region = cfun->eh->region_array[i];
1952 bool clobbers_hard_regs = false;
1954 /* Mind we don't process a region more than once. */
1955 if (!region || region->region_number != i)
1958 if (region->type != ERT_CLEANUP
1959 && region->type != ERT_TRY
1960 && region->type != ERT_ALLOWED_EXCEPTIONS)
1965 region->landing_pad = gen_label_rtx ();
1966 emit_label (region->landing_pad);
1968 #ifdef HAVE_exception_receiver
1969 if (HAVE_exception_receiver)
1970 emit_insn (gen_exception_receiver ());
1973 #ifdef HAVE_nonlocal_goto_receiver
1974 if (HAVE_nonlocal_goto_receiver)
1975 emit_insn (gen_nonlocal_goto_receiver ());
1980 /* If the eh_return data registers are call-saved, then we
1981 won't have considered them clobbered from the call that
1982 threw. Kill them now. */
1985 unsigned r = EH_RETURN_DATA_REGNO (j);
1986 if (r == INVALID_REGNUM)
1988 if (! call_used_regs[r])
1990 emit_insn (gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (Pmode, r)));
1991 clobbers_hard_regs = true;
1995 if (clobbers_hard_regs)
1997 /* @@@ This is a kludge. Not all machine descriptions define a
1998 blockage insn, but we must not allow the code we just generated
1999 to be reordered by scheduling. So emit an ASM_INPUT to act as
2001 emit_insn (gen_rtx_ASM_INPUT (VOIDmode, ""));
2004 emit_move_insn (cfun->eh->exc_ptr,
2005 gen_rtx_REG (Pmode, EH_RETURN_DATA_REGNO (0)));
2006 emit_move_insn (cfun->eh->filter,
2007 gen_rtx_REG (word_mode, EH_RETURN_DATA_REGNO (1)));
2012 emit_insns_before (seq, region->post_landing_pad);
2019 int directly_reachable;
2022 int call_site_index;
2026 sjlj_find_directly_reachable_regions (lp_info)
2027 struct sjlj_lp_info *lp_info;
2030 bool found_one = false;
2032 for (insn = get_insns (); insn ; insn = NEXT_INSN (insn))
2034 struct eh_region *region;
2035 enum reachable_code rc;
2039 if (! INSN_P (insn))
2042 note = find_reg_note (insn, REG_EH_REGION, NULL_RTX);
2043 if (!note || INTVAL (XEXP (note, 0)) <= 0)
2046 region = cfun->eh->region_array[INTVAL (XEXP (note, 0))];
2048 type_thrown = NULL_TREE;
2049 if (region->type == ERT_THROW)
2051 type_thrown = region->u.throw.type;
2052 region = region->outer;
2055 /* Find the first containing region that might handle the exception.
2056 That's the landing pad to which we will transfer control. */
2057 rc = RNL_NOT_CAUGHT;
2058 for (; region; region = region->outer)
2060 rc = reachable_next_level (region, type_thrown, 0);
2061 if (rc != RNL_NOT_CAUGHT)
2064 if (rc == RNL_MAYBE_CAUGHT || rc == RNL_CAUGHT)
2066 lp_info[region->region_number].directly_reachable = 1;
2075 sjlj_assign_call_site_values (dispatch_label, lp_info)
2077 struct sjlj_lp_info *lp_info;
2082 /* First task: build the action table. */
2084 VARRAY_UCHAR_INIT (cfun->eh->action_record_data, 64, "action_record_data");
2085 ar_hash = htab_create (31, action_record_hash, action_record_eq, free);
2087 for (i = cfun->eh->last_region_number; i > 0; --i)
2088 if (lp_info[i].directly_reachable)
2090 struct eh_region *r = cfun->eh->region_array[i];
2091 r->landing_pad = dispatch_label;
2092 lp_info[i].action_index = collect_one_action_chain (ar_hash, r);
2093 if (lp_info[i].action_index != -1)
2094 cfun->uses_eh_lsda = 1;
2097 htab_delete (ar_hash);
2099 /* Next: assign dispatch values. In dwarf2 terms, this would be the
2100 landing pad label for the region. For sjlj though, there is one
2101 common landing pad from which we dispatch to the post-landing pads.
2103 A region receives a dispatch index if it is directly reachable
2104 and requires in-function processing. Regions that share post-landing
2105 pads may share dispatch indices. */
2106 /* ??? Post-landing pad sharing doesn't actually happen at the moment
2107 (see build_post_landing_pads) so we don't bother checking for it. */
2110 for (i = cfun->eh->last_region_number; i > 0; --i)
2111 if (lp_info[i].directly_reachable)
2112 lp_info[i].dispatch_index = index++;
2114 /* Finally: assign call-site values. If dwarf2 terms, this would be
2115 the region number assigned by convert_to_eh_region_ranges, but
2116 handles no-action and must-not-throw differently. */
2119 for (i = cfun->eh->last_region_number; i > 0; --i)
2120 if (lp_info[i].directly_reachable)
2122 int action = lp_info[i].action_index;
2124 /* Map must-not-throw to otherwise unused call-site index 0. */
2127 /* Map no-action to otherwise unused call-site index -1. */
2128 else if (action == -1)
2130 /* Otherwise, look it up in the table. */
2132 index = add_call_site (GEN_INT (lp_info[i].dispatch_index), action);
2134 lp_info[i].call_site_index = index;
2139 sjlj_mark_call_sites (lp_info)
2140 struct sjlj_lp_info *lp_info;
2142 int last_call_site = -2;
2145 for (insn = get_insns (); insn ; insn = NEXT_INSN (insn))
2147 struct eh_region *region;
2149 rtx note, before, p;
2151 /* Reset value tracking at extended basic block boundaries. */
2152 if (GET_CODE (insn) == CODE_LABEL)
2153 last_call_site = -2;
2155 if (! INSN_P (insn))
2158 note = find_reg_note (insn, REG_EH_REGION, NULL_RTX);
2161 /* Calls (and trapping insns) without notes are outside any
2162 exception handling region in this function. Mark them as
2164 if (GET_CODE (insn) == CALL_INSN
2165 || (flag_non_call_exceptions
2166 && may_trap_p (PATTERN (insn))))
2167 this_call_site = -1;
2173 /* Calls that are known to not throw need not be marked. */
2174 if (INTVAL (XEXP (note, 0)) <= 0)
2177 region = cfun->eh->region_array[INTVAL (XEXP (note, 0))];
2178 this_call_site = lp_info[region->region_number].call_site_index;
2181 if (this_call_site == last_call_site)
2184 /* Don't separate a call from it's argument loads. */
2186 if (GET_CODE (insn) == CALL_INSN)
2187 before = find_first_parameter_load (insn, NULL_RTX);
2190 mem = adjust_address (cfun->eh->sjlj_fc, TYPE_MODE (integer_type_node),
2191 sjlj_fc_call_site_ofs);
2192 emit_move_insn (mem, GEN_INT (this_call_site));
2196 emit_insns_before (p, before);
2197 last_call_site = this_call_site;
2201 /* Construct the SjLj_Function_Context. */
2204 sjlj_emit_function_enter (dispatch_label)
2207 rtx fn_begin, fc, mem, seq;
2209 fc = cfun->eh->sjlj_fc;
2213 /* We're storing this libcall's address into memory instead of
2214 calling it directly. Thus, we must call assemble_external_libcall
2215 here, as we can not depend on emit_library_call to do it for us. */
2216 assemble_external_libcall (eh_personality_libfunc);
2217 mem = adjust_address (fc, Pmode, sjlj_fc_personality_ofs);
2218 emit_move_insn (mem, eh_personality_libfunc);
2220 mem = adjust_address (fc, Pmode, sjlj_fc_lsda_ofs);
2221 if (cfun->uses_eh_lsda)
2224 ASM_GENERATE_INTERNAL_LABEL (buf, "LLSDA", sjlj_funcdef_number);
2225 emit_move_insn (mem, gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf)));
2228 emit_move_insn (mem, const0_rtx);
2230 #ifdef DONT_USE_BUILTIN_SETJMP
2233 x = emit_library_call_value (setjmp_libfunc, NULL_RTX, LCT_RETURNS_TWICE,
2234 TYPE_MODE (integer_type_node), 1,
2235 plus_constant (XEXP (fc, 0),
2236 sjlj_fc_jbuf_ofs), Pmode);
2238 note = emit_note (NULL, NOTE_INSN_EXPECTED_VALUE);
2239 NOTE_EXPECTED_VALUE (note) = gen_rtx_EQ (VOIDmode, x, const0_rtx);
2241 emit_cmp_and_jump_insns (x, const0_rtx, NE, 0,
2242 TYPE_MODE (integer_type_node), 0, dispatch_label);
2245 expand_builtin_setjmp_setup (plus_constant (XEXP (fc, 0), sjlj_fc_jbuf_ofs),
2249 emit_library_call (unwind_sjlj_register_libfunc, LCT_NORMAL, VOIDmode,
2250 1, XEXP (fc, 0), Pmode);
2255 /* ??? Instead of doing this at the beginning of the function,
2256 do this in a block that is at loop level 0 and dominates all
2257 can_throw_internal instructions. */
2259 for (fn_begin = get_insns (); ; fn_begin = NEXT_INSN (fn_begin))
2260 if (GET_CODE (fn_begin) == NOTE
2261 && NOTE_LINE_NUMBER (fn_begin) == NOTE_INSN_FUNCTION_BEG)
2263 emit_insns_after (seq, fn_begin);
2266 /* Call back from expand_function_end to know where we should put
2267 the call to unwind_sjlj_unregister_libfunc if needed. */
2270 sjlj_emit_function_exit_after (after)
2273 cfun->eh->sjlj_exit_after = after;
2277 sjlj_emit_function_exit ()
2283 emit_library_call (unwind_sjlj_unregister_libfunc, LCT_NORMAL, VOIDmode,
2284 1, XEXP (cfun->eh->sjlj_fc, 0), Pmode);
2289 /* ??? Really this can be done in any block at loop level 0 that
2290 post-dominates all can_throw_internal instructions. This is
2291 the last possible moment. */
2293 emit_insns_after (seq, cfun->eh->sjlj_exit_after);
2297 sjlj_emit_dispatch_table (dispatch_label, lp_info)
2299 struct sjlj_lp_info *lp_info;
2301 int i, first_reachable;
2302 rtx mem, dispatch, seq, fc;
2304 fc = cfun->eh->sjlj_fc;
2308 emit_label (dispatch_label);
2310 #ifndef DONT_USE_BUILTIN_SETJMP
2311 expand_builtin_setjmp_receiver (dispatch_label);
2314 /* Load up dispatch index, exc_ptr and filter values from the
2315 function context. */
2316 mem = adjust_address (fc, TYPE_MODE (integer_type_node),
2317 sjlj_fc_call_site_ofs);
2318 dispatch = copy_to_reg (mem);
2320 mem = adjust_address (fc, word_mode, sjlj_fc_data_ofs);
2321 if (word_mode != Pmode)
2323 #ifdef POINTERS_EXTEND_UNSIGNED
2324 mem = convert_memory_address (Pmode, mem);
2326 mem = convert_to_mode (Pmode, mem, 0);
2329 emit_move_insn (cfun->eh->exc_ptr, mem);
2331 mem = adjust_address (fc, word_mode, sjlj_fc_data_ofs + UNITS_PER_WORD);
2332 emit_move_insn (cfun->eh->filter, mem);
2334 /* Jump to one of the directly reachable regions. */
2335 /* ??? This really ought to be using a switch statement. */
2337 first_reachable = 0;
2338 for (i = cfun->eh->last_region_number; i > 0; --i)
2340 if (! lp_info[i].directly_reachable)
2343 if (! first_reachable)
2345 first_reachable = i;
2349 emit_cmp_and_jump_insns (dispatch, GEN_INT (lp_info[i].dispatch_index),
2350 EQ, NULL_RTX, TYPE_MODE (integer_type_node), 0,
2351 cfun->eh->region_array[i]->post_landing_pad);
2357 emit_insns_before (seq, (cfun->eh->region_array[first_reachable]
2358 ->post_landing_pad));
2362 sjlj_build_landing_pads ()
2364 struct sjlj_lp_info *lp_info;
2366 lp_info = (struct sjlj_lp_info *) xcalloc (cfun->eh->last_region_number + 1,
2367 sizeof (struct sjlj_lp_info));
2369 if (sjlj_find_directly_reachable_regions (lp_info))
2371 rtx dispatch_label = gen_label_rtx ();
2374 = assign_stack_local (TYPE_MODE (sjlj_fc_type_node),
2375 int_size_in_bytes (sjlj_fc_type_node),
2376 TYPE_ALIGN (sjlj_fc_type_node));
2378 sjlj_assign_call_site_values (dispatch_label, lp_info);
2379 sjlj_mark_call_sites (lp_info);
2381 sjlj_emit_function_enter (dispatch_label);
2382 sjlj_emit_dispatch_table (dispatch_label, lp_info);
2383 sjlj_emit_function_exit ();
2390 finish_eh_generation ()
2392 /* Nothing to do if no regions created. */
2393 if (cfun->eh->region_tree == NULL)
2396 /* The object here is to provide find_basic_blocks with detailed
2397 information (via reachable_handlers) on how exception control
2398 flows within the function. In this first pass, we can include
2399 type information garnered from ERT_THROW and ERT_ALLOWED_EXCEPTIONS
2400 regions, and hope that it will be useful in deleting unreachable
2401 handlers. Subsequently, we will generate landing pads which will
2402 connect many of the handlers, and then type information will not
2403 be effective. Still, this is a win over previous implementations. */
2405 rebuild_jump_labels (get_insns ());
2406 find_basic_blocks (get_insns (), max_reg_num (), 0);
2407 cleanup_cfg (CLEANUP_PRE_LOOP);
2409 /* These registers are used by the landing pads. Make sure they
2410 have been generated. */
2411 get_exception_pointer (cfun);
2412 get_exception_filter (cfun);
2414 /* Construct the landing pads. */
2416 assign_filter_values ();
2417 build_post_landing_pads ();
2418 connect_post_landing_pads ();
2419 if (USING_SJLJ_EXCEPTIONS)
2420 sjlj_build_landing_pads ();
2422 dw2_build_landing_pads ();
2424 cfun->eh->built_landing_pads = 1;
2426 /* We've totally changed the CFG. Start over. */
2427 find_exception_handler_labels ();
2428 rebuild_jump_labels (get_insns ());
2429 find_basic_blocks (get_insns (), max_reg_num (), 0);
2430 cleanup_cfg (CLEANUP_PRE_LOOP);
2433 /* This section handles removing dead code for flow. */
2435 /* Remove LABEL from the exception_handler_labels list. */
2438 remove_exception_handler_label (label)
2443 /* If exception_handler_labels was not built yet,
2444 there is nothing to do. */
2445 if (exception_handler_labels == NULL)
2448 for (pl = &exception_handler_labels, l = *pl;
2449 XEXP (l, 0) != label;
2450 pl = &XEXP (l, 1), l = *pl)
2454 free_EXPR_LIST_node (l);
2457 /* Splice REGION from the region tree etc. */
2460 remove_eh_handler (region)
2461 struct eh_region *region;
2463 struct eh_region **pp, *p;
2467 /* For the benefit of efficiently handling REG_EH_REGION notes,
2468 replace this region in the region array with its containing
2469 region. Note that previous region deletions may result in
2470 multiple copies of this region in the array, so we have to
2471 search the whole thing. */
2472 for (i = cfun->eh->last_region_number; i > 0; --i)
2473 if (cfun->eh->region_array[i] == region)
2474 cfun->eh->region_array[i] = region->outer;
2476 if (cfun->eh->built_landing_pads)
2477 lab = region->landing_pad;
2479 lab = region->label;
2481 remove_exception_handler_label (lab);
2484 pp = ®ion->outer->inner;
2486 pp = &cfun->eh->region_tree;
2487 for (p = *pp; p != region; pp = &p->next_peer, p = *pp)
2492 for (p = region->inner; p->next_peer ; p = p->next_peer)
2493 p->outer = region->outer;
2494 p->next_peer = region->next_peer;
2495 p->outer = region->outer;
2496 *pp = region->inner;
2499 *pp = region->next_peer;
2501 if (region->type == ERT_CATCH)
2503 struct eh_region *try, *next, *prev;
2505 for (try = region->next_peer;
2506 try->type == ERT_CATCH;
2507 try = try->next_peer)
2509 if (try->type != ERT_TRY)
2512 next = region->u.catch.next_catch;
2513 prev = region->u.catch.prev_catch;
2516 next->u.catch.prev_catch = prev;
2518 try->u.try.last_catch = prev;
2520 prev->u.catch.next_catch = next;
2523 try->u.try.catch = next;
2525 remove_eh_handler (try);
2532 /* LABEL heads a basic block that is about to be deleted. If this
2533 label corresponds to an exception region, we may be able to
2534 delete the region. */
2537 maybe_remove_eh_handler (label)
2542 /* ??? After generating landing pads, it's not so simple to determine
2543 if the region data is completely unused. One must examine the
2544 landing pad and the post landing pad, and whether an inner try block
2545 is referencing the catch handlers directly. */
2546 if (cfun->eh->built_landing_pads)
2549 for (i = cfun->eh->last_region_number; i > 0; --i)
2551 struct eh_region *region = cfun->eh->region_array[i];
2552 if (region && region->label == label)
2554 /* Flow will want to remove MUST_NOT_THROW regions as unreachable
2555 because there is no path to the fallback call to terminate.
2556 But the region continues to affect call-site data until there
2557 are no more contained calls, which we don't see here. */
2558 if (region->type == ERT_MUST_NOT_THROW)
2560 remove_exception_handler_label (region->label);
2561 region->label = NULL_RTX;
2564 remove_eh_handler (region);
2571 /* This section describes CFG exception edges for flow. */
2573 /* For communicating between calls to reachable_next_level. */
2574 struct reachable_info
2581 /* A subroutine of reachable_next_level. Return true if TYPE, or a
2582 base class of TYPE, is in HANDLED. */
2585 check_handled (handled, type)
2590 /* We can check for exact matches without front-end help. */
2591 if (! lang_eh_type_covers)
2593 for (t = handled; t ; t = TREE_CHAIN (t))
2594 if (TREE_VALUE (t) == type)
2599 for (t = handled; t ; t = TREE_CHAIN (t))
2600 if ((*lang_eh_type_covers) (TREE_VALUE (t), type))
2607 /* A subroutine of reachable_next_level. If we are collecting a list
2608 of handlers, add one. After landing pad generation, reference
2609 it instead of the handlers themselves. Further, the handlers are
2610 all wired together, so by referencing one, we've got them all.
2611 Before landing pad generation we reference each handler individually.
2613 LP_REGION contains the landing pad; REGION is the handler. */
2616 add_reachable_handler (info, lp_region, region)
2617 struct reachable_info *info;
2618 struct eh_region *lp_region;
2619 struct eh_region *region;
2624 if (cfun->eh->built_landing_pads)
2626 if (! info->handlers)
2627 info->handlers = alloc_INSN_LIST (lp_region->landing_pad, NULL_RTX);
2630 info->handlers = alloc_INSN_LIST (region->label, info->handlers);
2633 /* Process one level of exception regions for reachability.
2634 If TYPE_THROWN is non-null, then it is the *exact* type being
2635 propagated. If INFO is non-null, then collect handler labels
2636 and caught/allowed type information between invocations. */
2638 static enum reachable_code
2639 reachable_next_level (region, type_thrown, info)
2640 struct eh_region *region;
2642 struct reachable_info *info;
2644 switch (region->type)
2647 /* Before landing-pad generation, we model control flow
2648 directly to the individual handlers. In this way we can
2649 see that catch handler types may shadow one another. */
2650 add_reachable_handler (info, region, region);
2651 return RNL_MAYBE_CAUGHT;
2655 struct eh_region *c;
2656 enum reachable_code ret = RNL_NOT_CAUGHT;
2658 for (c = region->u.try.catch; c ; c = c->u.catch.next_catch)
2660 /* A catch-all handler ends the search. */
2661 /* ??? _Unwind_ForcedUnwind will want outer cleanups
2662 to be run as well. */
2663 if (c->u.catch.type_list == NULL)
2665 add_reachable_handler (info, region, c);
2671 /* If we have at least one type match, end the search. */
2672 tree tp_node = c->u.catch.type_list;
2674 for (; tp_node; tp_node = TREE_CHAIN (tp_node))
2676 tree type = TREE_VALUE (tp_node);
2678 if (type == type_thrown
2679 || (lang_eh_type_covers
2680 && (*lang_eh_type_covers) (type, type_thrown)))
2682 add_reachable_handler (info, region, c);
2687 /* If we have definitive information of a match failure,
2688 the catch won't trigger. */
2689 if (lang_eh_type_covers)
2690 return RNL_NOT_CAUGHT;
2693 /* At this point, we either don't know what type is thrown or
2694 don't have front-end assistance to help deciding if it is
2695 covered by one of the types in the list for this region.
2697 We'd then like to add this region to the list of reachable
2698 handlers since it is indeed potentially reachable based on the
2699 information we have.
2701 Actually, this handler is for sure not reachable if all the
2702 types it matches have already been caught. That is, it is only
2703 potentially reachable if at least one of the types it catches
2704 has not been previously caught. */
2707 ret = RNL_MAYBE_CAUGHT;
2710 tree tp_node = c->u.catch.type_list;
2711 bool maybe_reachable = false;
2713 /* Compute the potential reachability of this handler and
2714 update the list of types caught at the same time. */
2715 for (; tp_node; tp_node = TREE_CHAIN (tp_node))
2717 tree type = TREE_VALUE (tp_node);
2719 if (! check_handled (info->types_caught, type))
2722 = tree_cons (NULL, type, info->types_caught);
2724 maybe_reachable = true;
2728 if (maybe_reachable)
2730 add_reachable_handler (info, region, c);
2732 /* ??? If the catch type is a base class of every allowed
2733 type, then we know we can stop the search. */
2734 ret = RNL_MAYBE_CAUGHT;
2742 case ERT_ALLOWED_EXCEPTIONS:
2743 /* An empty list of types definitely ends the search. */
2744 if (region->u.allowed.type_list == NULL_TREE)
2746 add_reachable_handler (info, region, region);
2750 /* Collect a list of lists of allowed types for use in detecting
2751 when a catch may be transformed into a catch-all. */
2753 info->types_allowed = tree_cons (NULL_TREE,
2754 region->u.allowed.type_list,
2755 info->types_allowed);
2757 /* If we have definitive information about the type hierarchy,
2758 then we can tell if the thrown type will pass through the
2760 if (type_thrown && lang_eh_type_covers)
2762 if (check_handled (region->u.allowed.type_list, type_thrown))
2763 return RNL_NOT_CAUGHT;
2766 add_reachable_handler (info, region, region);
2771 add_reachable_handler (info, region, region);
2772 return RNL_MAYBE_CAUGHT;
2775 /* Catch regions are handled by their controling try region. */
2776 return RNL_NOT_CAUGHT;
2778 case ERT_MUST_NOT_THROW:
2779 /* Here we end our search, since no exceptions may propagate.
2780 If we've touched down at some landing pad previous, then the
2781 explicit function call we generated may be used. Otherwise
2782 the call is made by the runtime. */
2783 if (info && info->handlers)
2785 add_reachable_handler (info, region, region);
2794 /* Shouldn't see these here. */
2801 /* Retrieve a list of labels of exception handlers which can be
2802 reached by a given insn. */
2805 reachable_handlers (insn)
2808 struct reachable_info info;
2809 struct eh_region *region;
2813 if (GET_CODE (insn) == JUMP_INSN
2814 && GET_CODE (PATTERN (insn)) == RESX)
2815 region_number = XINT (PATTERN (insn), 0);
2818 rtx note = find_reg_note (insn, REG_EH_REGION, NULL_RTX);
2819 if (!note || INTVAL (XEXP (note, 0)) <= 0)
2821 region_number = INTVAL (XEXP (note, 0));
2824 memset (&info, 0, sizeof (info));
2826 region = cfun->eh->region_array[region_number];
2828 type_thrown = NULL_TREE;
2829 if (GET_CODE (insn) == JUMP_INSN
2830 && GET_CODE (PATTERN (insn)) == RESX)
2832 /* A RESX leaves a region instead of entering it. Thus the
2833 region itself may have been deleted out from under us. */
2836 region = region->outer;
2838 else if (region->type == ERT_THROW)
2840 type_thrown = region->u.throw.type;
2841 region = region->outer;
2844 for (; region; region = region->outer)
2845 if (reachable_next_level (region, type_thrown, &info) >= RNL_CAUGHT)
2848 return info.handlers;
2851 /* Determine if the given INSN can throw an exception that is caught
2852 within the function. */
2855 can_throw_internal (insn)
2858 struct eh_region *region;
2862 if (! INSN_P (insn))
2865 if (GET_CODE (insn) == INSN
2866 && GET_CODE (PATTERN (insn)) == SEQUENCE)
2867 insn = XVECEXP (PATTERN (insn), 0, 0);
2869 if (GET_CODE (insn) == CALL_INSN
2870 && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
2873 for (i = 0; i < 3; ++i)
2875 rtx sub = XEXP (PATTERN (insn), i);
2876 for (; sub ; sub = NEXT_INSN (sub))
2877 if (can_throw_internal (sub))
2883 /* Every insn that might throw has an EH_REGION note. */
2884 note = find_reg_note (insn, REG_EH_REGION, NULL_RTX);
2885 if (!note || INTVAL (XEXP (note, 0)) <= 0)
2888 region = cfun->eh->region_array[INTVAL (XEXP (note, 0))];
2890 type_thrown = NULL_TREE;
2891 if (region->type == ERT_THROW)
2893 type_thrown = region->u.throw.type;
2894 region = region->outer;
2897 /* If this exception is ignored by each and every containing region,
2898 then control passes straight out. The runtime may handle some
2899 regions, which also do not require processing internally. */
2900 for (; region; region = region->outer)
2902 enum reachable_code how = reachable_next_level (region, type_thrown, 0);
2903 if (how == RNL_BLOCKED)
2905 if (how != RNL_NOT_CAUGHT)
2912 /* Determine if the given INSN can throw an exception that is
2913 visible outside the function. */
2916 can_throw_external (insn)
2919 struct eh_region *region;
2923 if (! INSN_P (insn))
2926 if (GET_CODE (insn) == INSN
2927 && GET_CODE (PATTERN (insn)) == SEQUENCE)
2928 insn = XVECEXP (PATTERN (insn), 0, 0);
2930 if (GET_CODE (insn) == CALL_INSN
2931 && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
2934 for (i = 0; i < 3; ++i)
2936 rtx sub = XEXP (PATTERN (insn), i);
2937 for (; sub ; sub = NEXT_INSN (sub))
2938 if (can_throw_external (sub))
2944 note = find_reg_note (insn, REG_EH_REGION, NULL_RTX);
2947 /* Calls (and trapping insns) without notes are outside any
2948 exception handling region in this function. We have to
2949 assume it might throw. Given that the front end and middle
2950 ends mark known NOTHROW functions, this isn't so wildly
2952 return (GET_CODE (insn) == CALL_INSN
2953 || (flag_non_call_exceptions
2954 && may_trap_p (PATTERN (insn))));
2956 if (INTVAL (XEXP (note, 0)) <= 0)
2959 region = cfun->eh->region_array[INTVAL (XEXP (note, 0))];
2961 type_thrown = NULL_TREE;
2962 if (region->type == ERT_THROW)
2964 type_thrown = region->u.throw.type;
2965 region = region->outer;
2968 /* If the exception is caught or blocked by any containing region,
2969 then it is not seen by any calling function. */
2970 for (; region ; region = region->outer)
2971 if (reachable_next_level (region, type_thrown, NULL) >= RNL_CAUGHT)
2977 /* True if nothing in this function can throw outside this function. */
2980 nothrow_function_p ()
2984 if (! flag_exceptions)
2987 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2988 if (can_throw_external (insn))
2990 for (insn = current_function_epilogue_delay_list; insn;
2991 insn = XEXP (insn, 1))
2992 if (can_throw_external (insn))
2999 /* Various hooks for unwind library. */
3001 /* Do any necessary initialization to access arbitrary stack frames.
3002 On the SPARC, this means flushing the register windows. */
3005 expand_builtin_unwind_init ()
3007 /* Set this so all the registers get saved in our frame; we need to be
3008 able to copy the saved values for any registers from frames we unwind. */
3009 current_function_has_nonlocal_label = 1;
3011 #ifdef SETUP_FRAME_ADDRESSES
3012 SETUP_FRAME_ADDRESSES ();
3017 expand_builtin_eh_return_data_regno (arglist)
3020 tree which = TREE_VALUE (arglist);
3021 unsigned HOST_WIDE_INT iwhich;
3023 if (TREE_CODE (which) != INTEGER_CST)
3025 error ("argument of `__builtin_eh_return_regno' must be constant");
3029 iwhich = tree_low_cst (which, 1);
3030 iwhich = EH_RETURN_DATA_REGNO (iwhich);
3031 if (iwhich == INVALID_REGNUM)
3034 #ifdef DWARF_FRAME_REGNUM
3035 iwhich = DWARF_FRAME_REGNUM (iwhich);
3037 iwhich = DBX_REGISTER_NUMBER (iwhich);
3040 return GEN_INT (iwhich);
3043 /* Given a value extracted from the return address register or stack slot,
3044 return the actual address encoded in that value. */
3047 expand_builtin_extract_return_addr (addr_tree)
3050 rtx addr = expand_expr (addr_tree, NULL_RTX, Pmode, 0);
3052 /* First mask out any unwanted bits. */
3053 #ifdef MASK_RETURN_ADDR
3054 expand_and (Pmode, addr, MASK_RETURN_ADDR, addr);
3057 /* Then adjust to find the real return address. */
3058 #if defined (RETURN_ADDR_OFFSET)
3059 addr = plus_constant (addr, RETURN_ADDR_OFFSET);
3065 /* Given an actual address in addr_tree, do any necessary encoding
3066 and return the value to be stored in the return address register or
3067 stack slot so the epilogue will return to that address. */
3070 expand_builtin_frob_return_addr (addr_tree)
3073 rtx addr = expand_expr (addr_tree, NULL_RTX, ptr_mode, 0);
3075 #ifdef POINTERS_EXTEND_UNSIGNED
3076 if (GET_MODE (addr) != Pmode)
3077 addr = convert_memory_address (Pmode, addr);
3080 #ifdef RETURN_ADDR_OFFSET
3081 addr = force_reg (Pmode, addr);
3082 addr = plus_constant (addr, -RETURN_ADDR_OFFSET);
3088 /* Set up the epilogue with the magic bits we'll need to return to the
3089 exception handler. */
3092 expand_builtin_eh_return (stackadj_tree, handler_tree)
3093 tree stackadj_tree, handler_tree;
3095 rtx stackadj, handler;
3097 stackadj = expand_expr (stackadj_tree, cfun->eh->ehr_stackadj, VOIDmode, 0);
3098 handler = expand_expr (handler_tree, cfun->eh->ehr_handler, VOIDmode, 0);
3100 #ifdef POINTERS_EXTEND_UNSIGNED
3101 if (GET_MODE (stackadj) != Pmode)
3102 stackadj = convert_memory_address (Pmode, stackadj);
3104 if (GET_MODE (handler) != Pmode)
3105 handler = convert_memory_address (Pmode, handler);
3108 if (! cfun->eh->ehr_label)
3110 cfun->eh->ehr_stackadj = copy_to_reg (stackadj);
3111 cfun->eh->ehr_handler = copy_to_reg (handler);
3112 cfun->eh->ehr_label = gen_label_rtx ();
3116 if (stackadj != cfun->eh->ehr_stackadj)
3117 emit_move_insn (cfun->eh->ehr_stackadj, stackadj);
3118 if (handler != cfun->eh->ehr_handler)
3119 emit_move_insn (cfun->eh->ehr_handler, handler);
3122 emit_jump (cfun->eh->ehr_label);
3128 rtx sa, ra, around_label;
3130 if (! cfun->eh->ehr_label)
3133 sa = EH_RETURN_STACKADJ_RTX;
3136 error ("__builtin_eh_return not supported on this target");
3140 current_function_calls_eh_return = 1;
3142 around_label = gen_label_rtx ();
3143 emit_move_insn (sa, const0_rtx);
3144 emit_jump (around_label);
3146 emit_label (cfun->eh->ehr_label);
3147 clobber_return_register ();
3149 #ifdef HAVE_eh_return
3151 emit_insn (gen_eh_return (cfun->eh->ehr_stackadj, cfun->eh->ehr_handler));
3155 ra = EH_RETURN_HANDLER_RTX;
3158 error ("__builtin_eh_return not supported on this target");
3159 ra = gen_reg_rtx (Pmode);
3162 emit_move_insn (sa, cfun->eh->ehr_stackadj);
3163 emit_move_insn (ra, cfun->eh->ehr_handler);
3166 emit_label (around_label);
3169 /* In the following functions, we represent entries in the action table
3170 as 1-based indices. Special cases are:
3172 0: null action record, non-null landing pad; implies cleanups
3173 -1: null action record, null landing pad; implies no action
3174 -2: no call-site entry; implies must_not_throw
3175 -3: we have yet to process outer regions
3177 Further, no special cases apply to the "next" field of the record.
3178 For next, 0 means end of list. */
3180 struct action_record
3188 action_record_eq (pentry, pdata)
3192 const struct action_record *entry = (const struct action_record *) pentry;
3193 const struct action_record *data = (const struct action_record *) pdata;
3194 return entry->filter == data->filter && entry->next == data->next;
3198 action_record_hash (pentry)
3201 const struct action_record *entry = (const struct action_record *) pentry;
3202 return entry->next * 1009 + entry->filter;
3206 add_action_record (ar_hash, filter, next)
3210 struct action_record **slot, *new, tmp;
3212 tmp.filter = filter;
3214 slot = (struct action_record **) htab_find_slot (ar_hash, &tmp, INSERT);
3216 if ((new = *slot) == NULL)
3218 new = (struct action_record *) xmalloc (sizeof (*new));
3219 new->offset = VARRAY_ACTIVE_SIZE (cfun->eh->action_record_data) + 1;
3220 new->filter = filter;
3224 /* The filter value goes in untouched. The link to the next
3225 record is a "self-relative" byte offset, or zero to indicate
3226 that there is no next record. So convert the absolute 1 based
3227 indices we've been carrying around into a displacement. */
3229 push_sleb128 (&cfun->eh->action_record_data, filter);
3231 next -= VARRAY_ACTIVE_SIZE (cfun->eh->action_record_data) + 1;
3232 push_sleb128 (&cfun->eh->action_record_data, next);
3239 collect_one_action_chain (ar_hash, region)
3241 struct eh_region *region;
3243 struct eh_region *c;
3246 /* If we've reached the top of the region chain, then we have
3247 no actions, and require no landing pad. */
3251 switch (region->type)
3254 /* A cleanup adds a zero filter to the beginning of the chain, but
3255 there are special cases to look out for. If there are *only*
3256 cleanups along a path, then it compresses to a zero action.
3257 Further, if there are multiple cleanups along a path, we only
3258 need to represent one of them, as that is enough to trigger
3259 entry to the landing pad at runtime. */
3260 next = collect_one_action_chain (ar_hash, region->outer);
3263 for (c = region->outer; c ; c = c->outer)
3264 if (c->type == ERT_CLEANUP)
3266 return add_action_record (ar_hash, 0, next);
3269 /* Process the associated catch regions in reverse order.
3270 If there's a catch-all handler, then we don't need to
3271 search outer regions. Use a magic -3 value to record
3272 that we haven't done the outer search. */
3274 for (c = region->u.try.last_catch; c ; c = c->u.catch.prev_catch)
3276 if (c->u.catch.type_list == NULL)
3278 /* Retrieve the filter from the head of the filter list
3279 where we have stored it (see assign_filter_values). */
3281 = TREE_INT_CST_LOW (TREE_VALUE (c->u.catch.filter_list));
3283 next = add_action_record (ar_hash, filter, 0);
3287 /* Once the outer search is done, trigger an action record for
3288 each filter we have. */
3293 next = collect_one_action_chain (ar_hash, region->outer);
3295 /* If there is no next action, terminate the chain. */
3298 /* If all outer actions are cleanups or must_not_throw,
3299 we'll have no action record for it, since we had wanted
3300 to encode these states in the call-site record directly.
3301 Add a cleanup action to the chain to catch these. */
3303 next = add_action_record (ar_hash, 0, 0);
3306 flt_node = c->u.catch.filter_list;
3307 for (; flt_node; flt_node = TREE_CHAIN (flt_node))
3309 int filter = TREE_INT_CST_LOW (TREE_VALUE (flt_node));
3310 next = add_action_record (ar_hash, filter, next);
3316 case ERT_ALLOWED_EXCEPTIONS:
3317 /* An exception specification adds its filter to the
3318 beginning of the chain. */
3319 next = collect_one_action_chain (ar_hash, region->outer);
3320 return add_action_record (ar_hash, region->u.allowed.filter,
3321 next < 0 ? 0 : next);
3323 case ERT_MUST_NOT_THROW:
3324 /* A must-not-throw region with no inner handlers or cleanups
3325 requires no call-site entry. Note that this differs from
3326 the no handler or cleanup case in that we do require an lsda
3327 to be generated. Return a magic -2 value to record this. */
3332 /* CATCH regions are handled in TRY above. THROW regions are
3333 for optimization information only and produce no output. */
3334 return collect_one_action_chain (ar_hash, region->outer);
3342 add_call_site (landing_pad, action)
3346 struct call_site_record *data = cfun->eh->call_site_data;
3347 int used = cfun->eh->call_site_data_used;
3348 int size = cfun->eh->call_site_data_size;
3352 size = (size ? size * 2 : 64);
3353 data = (struct call_site_record *)
3354 xrealloc (data, sizeof (*data) * size);
3355 cfun->eh->call_site_data = data;
3356 cfun->eh->call_site_data_size = size;
3359 data[used].landing_pad = landing_pad;
3360 data[used].action = action;
3362 cfun->eh->call_site_data_used = used + 1;
3364 return used + call_site_base;
3367 /* Turn REG_EH_REGION notes back into NOTE_INSN_EH_REGION notes.
3368 The new note numbers will not refer to region numbers, but
3369 instead to call site entries. */
3372 convert_to_eh_region_ranges ()
3374 rtx insn, iter, note;
3376 int last_action = -3;
3377 rtx last_action_insn = NULL_RTX;
3378 rtx last_landing_pad = NULL_RTX;
3379 rtx first_no_action_insn = NULL_RTX;
3382 if (USING_SJLJ_EXCEPTIONS || cfun->eh->region_tree == NULL)
3385 VARRAY_UCHAR_INIT (cfun->eh->action_record_data, 64, "action_record_data");
3387 ar_hash = htab_create (31, action_record_hash, action_record_eq, free);
3389 for (iter = get_insns (); iter ; iter = NEXT_INSN (iter))
3392 struct eh_region *region;
3394 rtx this_landing_pad;
3397 if (GET_CODE (insn) == INSN
3398 && GET_CODE (PATTERN (insn)) == SEQUENCE)
3399 insn = XVECEXP (PATTERN (insn), 0, 0);
3401 note = find_reg_note (insn, REG_EH_REGION, NULL_RTX);
3404 if (! (GET_CODE (insn) == CALL_INSN
3405 || (flag_non_call_exceptions
3406 && may_trap_p (PATTERN (insn)))))
3413 if (INTVAL (XEXP (note, 0)) <= 0)
3415 region = cfun->eh->region_array[INTVAL (XEXP (note, 0))];
3416 this_action = collect_one_action_chain (ar_hash, region);
3419 /* Existence of catch handlers, or must-not-throw regions
3420 implies that an lsda is needed (even if empty). */
3421 if (this_action != -1)
3422 cfun->uses_eh_lsda = 1;
3424 /* Delay creation of region notes for no-action regions
3425 until we're sure that an lsda will be required. */
3426 else if (last_action == -3)
3428 first_no_action_insn = iter;
3432 /* Cleanups and handlers may share action chains but not
3433 landing pads. Collect the landing pad for this region. */
3434 if (this_action >= 0)
3436 struct eh_region *o;
3437 for (o = region; ! o->landing_pad ; o = o->outer)
3439 this_landing_pad = o->landing_pad;
3442 this_landing_pad = NULL_RTX;
3444 /* Differing actions or landing pads implies a change in call-site
3445 info, which implies some EH_REGION note should be emitted. */
3446 if (last_action != this_action
3447 || last_landing_pad != this_landing_pad)
3449 /* If we'd not seen a previous action (-3) or the previous
3450 action was must-not-throw (-2), then we do not need an
3452 if (last_action >= -1)
3454 /* If we delayed the creation of the begin, do it now. */
3455 if (first_no_action_insn)
3457 call_site = add_call_site (NULL_RTX, 0);
3458 note = emit_note_before (NOTE_INSN_EH_REGION_BEG,
3459 first_no_action_insn);
3460 NOTE_EH_HANDLER (note) = call_site;
3461 first_no_action_insn = NULL_RTX;
3464 note = emit_note_after (NOTE_INSN_EH_REGION_END,
3466 NOTE_EH_HANDLER (note) = call_site;
3469 /* If the new action is must-not-throw, then no region notes
3471 if (this_action >= -1)
3473 call_site = add_call_site (this_landing_pad,
3474 this_action < 0 ? 0 : this_action);
3475 note = emit_note_before (NOTE_INSN_EH_REGION_BEG, iter);
3476 NOTE_EH_HANDLER (note) = call_site;
3479 last_action = this_action;
3480 last_landing_pad = this_landing_pad;
3482 last_action_insn = iter;
3485 if (last_action >= -1 && ! first_no_action_insn)
3487 note = emit_note_after (NOTE_INSN_EH_REGION_END, last_action_insn);
3488 NOTE_EH_HANDLER (note) = call_site;
3491 htab_delete (ar_hash);
3496 push_uleb128 (data_area, value)
3497 varray_type *data_area;
3502 unsigned char byte = value & 0x7f;
3506 VARRAY_PUSH_UCHAR (*data_area, byte);
3512 push_sleb128 (data_area, value)
3513 varray_type *data_area;
3521 byte = value & 0x7f;
3523 more = ! ((value == 0 && (byte & 0x40) == 0)
3524 || (value == -1 && (byte & 0x40) != 0));
3527 VARRAY_PUSH_UCHAR (*data_area, byte);
3533 #ifndef HAVE_AS_LEB128
3535 dw2_size_of_call_site_table ()
3537 int n = cfun->eh->call_site_data_used;
3538 int size = n * (4 + 4 + 4);
3541 for (i = 0; i < n; ++i)
3543 struct call_site_record *cs = &cfun->eh->call_site_data[i];
3544 size += size_of_uleb128 (cs->action);
3551 sjlj_size_of_call_site_table ()
3553 int n = cfun->eh->call_site_data_used;
3557 for (i = 0; i < n; ++i)
3559 struct call_site_record *cs = &cfun->eh->call_site_data[i];
3560 size += size_of_uleb128 (INTVAL (cs->landing_pad));
3561 size += size_of_uleb128 (cs->action);
3569 dw2_output_call_site_table ()
3571 const char *const function_start_lab
3572 = IDENTIFIER_POINTER (current_function_func_begin_label);
3573 int n = cfun->eh->call_site_data_used;
3576 for (i = 0; i < n; ++i)
3578 struct call_site_record *cs = &cfun->eh->call_site_data[i];
3579 char reg_start_lab[32];
3580 char reg_end_lab[32];
3581 char landing_pad_lab[32];
3583 ASM_GENERATE_INTERNAL_LABEL (reg_start_lab, "LEHB", call_site_base + i);
3584 ASM_GENERATE_INTERNAL_LABEL (reg_end_lab, "LEHE", call_site_base + i);
3586 if (cs->landing_pad)
3587 ASM_GENERATE_INTERNAL_LABEL (landing_pad_lab, "L",
3588 CODE_LABEL_NUMBER (cs->landing_pad));
3590 /* ??? Perhaps use insn length scaling if the assembler supports
3591 generic arithmetic. */
3592 /* ??? Perhaps use attr_length to choose data1 or data2 instead of
3593 data4 if the function is small enough. */
3594 #ifdef HAVE_AS_LEB128
3595 dw2_asm_output_delta_uleb128 (reg_start_lab, function_start_lab,
3596 "region %d start", i);
3597 dw2_asm_output_delta_uleb128 (reg_end_lab, reg_start_lab,
3599 if (cs->landing_pad)
3600 dw2_asm_output_delta_uleb128 (landing_pad_lab, function_start_lab,
3603 dw2_asm_output_data_uleb128 (0, "landing pad");
3605 dw2_asm_output_delta (4, reg_start_lab, function_start_lab,
3606 "region %d start", i);
3607 dw2_asm_output_delta (4, reg_end_lab, reg_start_lab, "length");
3608 if (cs->landing_pad)
3609 dw2_asm_output_delta (4, landing_pad_lab, function_start_lab,
3612 dw2_asm_output_data (4, 0, "landing pad");
3614 dw2_asm_output_data_uleb128 (cs->action, "action");
3617 call_site_base += n;
3621 sjlj_output_call_site_table ()
3623 int n = cfun->eh->call_site_data_used;
3626 for (i = 0; i < n; ++i)
3628 struct call_site_record *cs = &cfun->eh->call_site_data[i];
3630 dw2_asm_output_data_uleb128 (INTVAL (cs->landing_pad),
3631 "region %d landing pad", i);
3632 dw2_asm_output_data_uleb128 (cs->action, "action");
3635 call_site_base += n;
3639 output_function_exception_table ()
3641 int tt_format, cs_format, lp_format, i, n;
3642 #ifdef HAVE_AS_LEB128
3643 char ttype_label[32];
3644 char cs_after_size_label[32];
3645 char cs_end_label[32];
3651 int tt_format_size = 0;
3653 /* Not all functions need anything. */
3654 if (! cfun->uses_eh_lsda)
3657 funcdef_number = (USING_SJLJ_EXCEPTIONS
3658 ? sjlj_funcdef_number
3659 : current_funcdef_number);
3661 #ifdef IA64_UNWIND_INFO
3662 fputs ("\t.personality\t", asm_out_file);
3663 output_addr_const (asm_out_file, eh_personality_libfunc);
3664 fputs ("\n\t.handlerdata\n", asm_out_file);
3665 /* Note that varasm still thinks we're in the function's code section.
3666 The ".endp" directive that will immediately follow will take us back. */
3668 (*targetm.asm_out.exception_section) ();
3671 have_tt_data = (VARRAY_ACTIVE_SIZE (cfun->eh->ttype_data) > 0
3672 || VARRAY_ACTIVE_SIZE (cfun->eh->ehspec_data) > 0);
3674 /* Indicate the format of the @TType entries. */
3676 tt_format = DW_EH_PE_omit;
3679 tt_format = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/1);
3680 #ifdef HAVE_AS_LEB128
3681 ASM_GENERATE_INTERNAL_LABEL (ttype_label, "LLSDATT", funcdef_number);
3683 tt_format_size = size_of_encoded_value (tt_format);
3685 assemble_align (tt_format_size * BITS_PER_UNIT);
3688 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LLSDA", funcdef_number);
3690 /* The LSDA header. */
3692 /* Indicate the format of the landing pad start pointer. An omitted
3693 field implies @LPStart == @Start. */
3694 /* Currently we always put @LPStart == @Start. This field would
3695 be most useful in moving the landing pads completely out of
3696 line to another section, but it could also be used to minimize
3697 the size of uleb128 landing pad offsets. */
3698 lp_format = DW_EH_PE_omit;
3699 dw2_asm_output_data (1, lp_format, "@LPStart format (%s)",
3700 eh_data_format_name (lp_format));
3702 /* @LPStart pointer would go here. */
3704 dw2_asm_output_data (1, tt_format, "@TType format (%s)",
3705 eh_data_format_name (tt_format));
3707 #ifndef HAVE_AS_LEB128
3708 if (USING_SJLJ_EXCEPTIONS)
3709 call_site_len = sjlj_size_of_call_site_table ();
3711 call_site_len = dw2_size_of_call_site_table ();
3714 /* A pc-relative 4-byte displacement to the @TType data. */
3717 #ifdef HAVE_AS_LEB128
3718 char ttype_after_disp_label[32];
3719 ASM_GENERATE_INTERNAL_LABEL (ttype_after_disp_label, "LLSDATTD",
3721 dw2_asm_output_delta_uleb128 (ttype_label, ttype_after_disp_label,
3722 "@TType base offset");
3723 ASM_OUTPUT_LABEL (asm_out_file, ttype_after_disp_label);
3725 /* Ug. Alignment queers things. */
3726 unsigned int before_disp, after_disp, last_disp, disp;
3728 before_disp = 1 + 1;
3729 after_disp = (1 + size_of_uleb128 (call_site_len)
3731 + VARRAY_ACTIVE_SIZE (cfun->eh->action_record_data)
3732 + (VARRAY_ACTIVE_SIZE (cfun->eh->ttype_data)
3738 unsigned int disp_size, pad;
3741 disp_size = size_of_uleb128 (disp);
3742 pad = before_disp + disp_size + after_disp;
3743 if (pad % tt_format_size)
3744 pad = tt_format_size - (pad % tt_format_size);
3747 disp = after_disp + pad;
3749 while (disp != last_disp);
3751 dw2_asm_output_data_uleb128 (disp, "@TType base offset");
3755 /* Indicate the format of the call-site offsets. */
3756 #ifdef HAVE_AS_LEB128
3757 cs_format = DW_EH_PE_uleb128;
3759 cs_format = DW_EH_PE_udata4;
3761 dw2_asm_output_data (1, cs_format, "call-site format (%s)",
3762 eh_data_format_name (cs_format));
3764 #ifdef HAVE_AS_LEB128
3765 ASM_GENERATE_INTERNAL_LABEL (cs_after_size_label, "LLSDACSB",
3767 ASM_GENERATE_INTERNAL_LABEL (cs_end_label, "LLSDACSE",
3769 dw2_asm_output_delta_uleb128 (cs_end_label, cs_after_size_label,
3770 "Call-site table length");
3771 ASM_OUTPUT_LABEL (asm_out_file, cs_after_size_label);
3772 if (USING_SJLJ_EXCEPTIONS)
3773 sjlj_output_call_site_table ();
3775 dw2_output_call_site_table ();
3776 ASM_OUTPUT_LABEL (asm_out_file, cs_end_label);
3778 dw2_asm_output_data_uleb128 (call_site_len,"Call-site table length");
3779 if (USING_SJLJ_EXCEPTIONS)
3780 sjlj_output_call_site_table ();
3782 dw2_output_call_site_table ();
3785 /* ??? Decode and interpret the data for flag_debug_asm. */
3786 n = VARRAY_ACTIVE_SIZE (cfun->eh->action_record_data);
3787 for (i = 0; i < n; ++i)
3788 dw2_asm_output_data (1, VARRAY_UCHAR (cfun->eh->action_record_data, i),
3789 (i ? NULL : "Action record table"));
3792 assemble_align (tt_format_size * BITS_PER_UNIT);
3794 i = VARRAY_ACTIVE_SIZE (cfun->eh->ttype_data);
3797 tree type = VARRAY_TREE (cfun->eh->ttype_data, i);
3800 if (type == NULL_TREE)
3801 type = integer_zero_node;
3803 type = lookup_type_for_runtime (type);
3805 value = expand_expr (type, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
3806 if (tt_format == DW_EH_PE_absptr || tt_format == DW_EH_PE_aligned)
3807 assemble_integer (value, tt_format_size,
3808 tt_format_size * BITS_PER_UNIT, 1);
3810 dw2_asm_output_encoded_addr_rtx (tt_format, value, NULL);
3813 #ifdef HAVE_AS_LEB128
3815 ASM_OUTPUT_LABEL (asm_out_file, ttype_label);
3818 /* ??? Decode and interpret the data for flag_debug_asm. */
3819 n = VARRAY_ACTIVE_SIZE (cfun->eh->ehspec_data);
3820 for (i = 0; i < n; ++i)
3821 dw2_asm_output_data (1, VARRAY_UCHAR (cfun->eh->ehspec_data, i),
3822 (i ? NULL : "Exception specification table"));
3824 function_section (current_function_decl);
3826 if (USING_SJLJ_EXCEPTIONS)
3827 sjlj_funcdef_number += 1;