1 /* Implements exception handling.
2 Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001 Free Software Foundation, Inc.
4 Contributed by Mike Stump <mrs@cygnus.com>.
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
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. ] */
57 #include "insn-config.h"
59 #include "integrate.h"
60 #include "hard-reg-set.h"
61 #include "basic-block.h"
63 #include "dwarf2asm.h"
64 #include "dwarf2out.h"
73 /* Provide defaults for stuff that may not be defined when using
75 #ifndef EH_RETURN_STACKADJ_RTX
76 #define EH_RETURN_STACKADJ_RTX 0
78 #ifndef EH_RETURN_HANDLER_RTX
79 #define EH_RETURN_HANDLER_RTX 0
81 #ifndef EH_RETURN_DATA_REGNO
82 #define EH_RETURN_DATA_REGNO(N) INVALID_REGNUM
86 /* Nonzero means enable synchronous exceptions for non-call instructions. */
87 int flag_non_call_exceptions
;
89 /* Protect cleanup actions with must-not-throw regions, with a call
90 to the given failure handler. */
91 tree (*lang_protect_cleanup_actions
) PARAMS ((void));
93 /* Return true if type A catches type B. */
94 int (*lang_eh_type_covers
) PARAMS ((tree a
, tree b
));
96 /* Map a type to a runtime object to match type. */
97 tree (*lang_eh_runtime_type
) PARAMS ((tree
));
99 /* A list of labels used for exception handlers. */
100 rtx exception_handler_labels
;
102 static int call_site_base
;
103 static int sjlj_funcdef_number
;
104 static htab_t type_to_runtime_map
;
106 /* Describe the SjLj_Function_Context structure. */
107 static tree sjlj_fc_type_node
;
108 static int sjlj_fc_call_site_ofs
;
109 static int sjlj_fc_data_ofs
;
110 static int sjlj_fc_personality_ofs
;
111 static int sjlj_fc_lsda_ofs
;
112 static int sjlj_fc_jbuf_ofs
;
114 /* Describes one exception region. */
117 /* The immediately surrounding region. */
118 struct eh_region
*outer
;
120 /* The list of immediately contained regions. */
121 struct eh_region
*inner
;
122 struct eh_region
*next_peer
;
124 /* An identifier for this region. */
127 /* Each region does exactly one thing. */
133 ERT_ALLOWED_EXCEPTIONS
,
139 /* Holds the action to perform based on the preceeding type. */
141 /* A list of catch blocks, a surrounding try block,
142 and the label for continuing after a catch. */
144 struct eh_region
*catch;
145 struct eh_region
*last_catch
;
146 struct eh_region
*prev_try
;
150 /* The list through the catch handlers, the type object
151 matched, and a pointer to the generated code. */
153 struct eh_region
*next_catch
;
154 struct eh_region
*prev_catch
;
159 /* A tree_list of allowed types. */
165 /* The type given by a call to "throw foo();", or discovered
171 /* Retain the cleanup expression even after expansion so that
172 we can match up fixup regions. */
177 /* The real region (by expression and by pointer) that fixup code
181 struct eh_region
*real_region
;
185 /* Entry point for this region's handler before landing pads are built. */
188 /* Entry point for this region's handler from the runtime eh library. */
191 /* Entry point for this region's handler from an inner region. */
192 rtx post_landing_pad
;
194 /* The RESX insn for handing off control to the next outermost handler,
199 /* Used to save exception status for each function. */
202 /* The tree of all regions for this function. */
203 struct eh_region
*region_tree
;
205 /* The same information as an indexable array. */
206 struct eh_region
**region_array
;
208 /* The most recently open region. */
209 struct eh_region
*cur_region
;
211 /* This is the region for which we are processing catch blocks. */
212 struct eh_region
*try_region
;
214 /* A stack (TREE_LIST) of lists of handlers. The TREE_VALUE of each
215 node is itself a TREE_CHAINed list of handlers for regions that
216 are not yet closed. The TREE_VALUE of each entry contains the
217 handler for the corresponding entry on the ehstack. */
223 int built_landing_pads
;
224 int last_region_number
;
226 varray_type ttype_data
;
227 varray_type ehspec_data
;
228 varray_type action_record_data
;
230 struct call_site_record
235 int call_site_data_used
;
236 int call_site_data_size
;
247 static void mark_eh_region
PARAMS ((struct eh_region
*));
249 static int t2r_eq
PARAMS ((const PTR
,
251 static hashval_t t2r_hash
PARAMS ((const PTR
));
252 static int t2r_mark_1
PARAMS ((PTR
*, PTR
));
253 static void t2r_mark
PARAMS ((PTR
));
254 static void add_type_for_runtime
PARAMS ((tree
));
255 static tree lookup_type_for_runtime
PARAMS ((tree
));
257 static struct eh_region
*expand_eh_region_end
PARAMS ((void));
259 static rtx get_exception_filter
PARAMS ((struct function
*));
261 static void collect_eh_region_array
PARAMS ((void));
262 static void resolve_fixup_regions
PARAMS ((void));
263 static void remove_fixup_regions
PARAMS ((void));
264 static void convert_from_eh_region_ranges_1
PARAMS ((rtx
*, int *, int));
266 static struct eh_region
*duplicate_eh_region_1
PARAMS ((struct eh_region
*,
267 struct inline_remap
*));
268 static void duplicate_eh_region_2
PARAMS ((struct eh_region
*,
269 struct eh_region
**));
270 static int ttypes_filter_eq
PARAMS ((const PTR
,
272 static hashval_t ttypes_filter_hash
PARAMS ((const PTR
));
273 static int ehspec_filter_eq
PARAMS ((const PTR
,
275 static hashval_t ehspec_filter_hash
PARAMS ((const PTR
));
276 static int add_ttypes_entry
PARAMS ((htab_t
, tree
));
277 static int add_ehspec_entry
PARAMS ((htab_t
, htab_t
,
279 static void assign_filter_values
PARAMS ((void));
280 static void build_post_landing_pads
PARAMS ((void));
281 static void connect_post_landing_pads
PARAMS ((void));
282 static void dw2_build_landing_pads
PARAMS ((void));
285 static bool sjlj_find_directly_reachable_regions
286 PARAMS ((struct sjlj_lp_info
*));
287 static void sjlj_assign_call_site_values
288 PARAMS ((rtx
, struct sjlj_lp_info
*));
289 static void sjlj_mark_call_sites
290 PARAMS ((struct sjlj_lp_info
*));
291 static void sjlj_emit_function_enter
PARAMS ((rtx
));
292 static void sjlj_emit_function_exit
PARAMS ((void));
293 static void sjlj_emit_dispatch_table
294 PARAMS ((rtx
, struct sjlj_lp_info
*));
295 static void sjlj_build_landing_pads
PARAMS ((void));
297 static void remove_exception_handler_label
PARAMS ((rtx
));
298 static void remove_eh_handler
PARAMS ((struct eh_region
*));
300 struct reachable_info
;
302 /* The return value of reachable_next_level. */
305 /* The given exception is not processed by the given region. */
307 /* The given exception may need processing by the given region. */
309 /* The given exception is completely processed by the given region. */
311 /* The given exception is completely processed by the runtime. */
315 static int check_handled
PARAMS ((tree
, tree
));
316 static void add_reachable_handler
317 PARAMS ((struct reachable_info
*, struct eh_region
*,
318 struct eh_region
*));
319 static enum reachable_code reachable_next_level
320 PARAMS ((struct eh_region
*, tree
, struct reachable_info
*));
322 static int action_record_eq
PARAMS ((const PTR
,
324 static hashval_t action_record_hash
PARAMS ((const PTR
));
325 static int add_action_record
PARAMS ((htab_t
, int, int));
326 static int collect_one_action_chain
PARAMS ((htab_t
,
327 struct eh_region
*));
328 static int add_call_site
PARAMS ((rtx
, int));
330 static void push_uleb128
PARAMS ((varray_type
*,
332 static void push_sleb128
PARAMS ((varray_type
*, int));
333 #ifndef HAVE_AS_LEB128
334 static int dw2_size_of_call_site_table
PARAMS ((void));
335 static int sjlj_size_of_call_site_table
PARAMS ((void));
337 static void dw2_output_call_site_table
PARAMS ((void));
338 static void sjlj_output_call_site_table
PARAMS ((void));
341 /* Routine to see if exception handling is turned on.
342 DO_WARN is non-zero if we want to inform the user that exception
343 handling is turned off.
345 This is used to ensure that -fexceptions has been specified if the
346 compiler tries to use any exception-specific functions. */
352 if (! flag_exceptions
)
354 static int warned
= 0;
355 if (! warned
&& do_warn
)
357 error ("exception handling disabled, use -fexceptions to enable");
369 ggc_add_rtx_root (&exception_handler_labels
, 1);
371 if (! flag_exceptions
)
374 type_to_runtime_map
= htab_create (31, t2r_hash
, t2r_eq
, NULL
);
375 ggc_add_root (&type_to_runtime_map
, 1, sizeof (htab_t
), t2r_mark
);
377 /* Create the SjLj_Function_Context structure. This should match
378 the definition in unwind-sjlj.c. */
379 if (USING_SJLJ_EXCEPTIONS
)
381 tree f_jbuf
, f_per
, f_lsda
, f_prev
, f_cs
, f_data
, tmp
;
383 sjlj_fc_type_node
= make_lang_type (RECORD_TYPE
);
384 ggc_add_tree_root (&sjlj_fc_type_node
, 1);
386 f_prev
= build_decl (FIELD_DECL
, get_identifier ("__prev"),
387 build_pointer_type (sjlj_fc_type_node
));
388 DECL_FIELD_CONTEXT (f_prev
) = sjlj_fc_type_node
;
390 f_cs
= build_decl (FIELD_DECL
, get_identifier ("__call_site"),
392 DECL_FIELD_CONTEXT (f_cs
) = sjlj_fc_type_node
;
394 tmp
= build_index_type (build_int_2 (4 - 1, 0));
395 tmp
= build_array_type (type_for_mode (word_mode
, 1), tmp
);
396 f_data
= build_decl (FIELD_DECL
, get_identifier ("__data"), tmp
);
397 DECL_FIELD_CONTEXT (f_data
) = sjlj_fc_type_node
;
399 f_per
= build_decl (FIELD_DECL
, get_identifier ("__personality"),
401 DECL_FIELD_CONTEXT (f_per
) = sjlj_fc_type_node
;
403 f_lsda
= build_decl (FIELD_DECL
, get_identifier ("__lsda"),
405 DECL_FIELD_CONTEXT (f_lsda
) = sjlj_fc_type_node
;
407 #ifdef DONT_USE_BUILTIN_SETJMP
409 tmp
= build_int_2 (JMP_BUF_SIZE
- 1, 0);
411 /* Should be large enough for most systems, if it is not,
412 JMP_BUF_SIZE should be defined with the proper value. It will
413 also tend to be larger than necessary for most systems, a more
414 optimal port will define JMP_BUF_SIZE. */
415 tmp
= build_int_2 (FIRST_PSEUDO_REGISTER
+ 2 - 1, 0);
418 /* This is 2 for builtin_setjmp, plus whatever the target requires
419 via STACK_SAVEAREA_MODE (SAVE_NONLOCAL). */
420 tmp
= build_int_2 ((GET_MODE_SIZE (STACK_SAVEAREA_MODE (SAVE_NONLOCAL
))
421 / GET_MODE_SIZE (Pmode
)) + 2 - 1, 0);
423 tmp
= build_index_type (tmp
);
424 tmp
= build_array_type (ptr_type_node
, tmp
);
425 f_jbuf
= build_decl (FIELD_DECL
, get_identifier ("__jbuf"), tmp
);
426 #ifdef DONT_USE_BUILTIN_SETJMP
427 /* We don't know what the alignment requirements of the
428 runtime's jmp_buf has. Overestimate. */
429 DECL_ALIGN (f_jbuf
) = BIGGEST_ALIGNMENT
;
430 DECL_USER_ALIGN (f_jbuf
) = 1;
432 DECL_FIELD_CONTEXT (f_jbuf
) = sjlj_fc_type_node
;
434 TYPE_FIELDS (sjlj_fc_type_node
) = f_prev
;
435 TREE_CHAIN (f_prev
) = f_cs
;
436 TREE_CHAIN (f_cs
) = f_data
;
437 TREE_CHAIN (f_data
) = f_per
;
438 TREE_CHAIN (f_per
) = f_lsda
;
439 TREE_CHAIN (f_lsda
) = f_jbuf
;
441 layout_type (sjlj_fc_type_node
);
443 /* Cache the interesting field offsets so that we have
444 easy access from rtl. */
445 sjlj_fc_call_site_ofs
446 = (tree_low_cst (DECL_FIELD_OFFSET (f_cs
), 1)
447 + tree_low_cst (DECL_FIELD_BIT_OFFSET (f_cs
), 1) / BITS_PER_UNIT
);
449 = (tree_low_cst (DECL_FIELD_OFFSET (f_data
), 1)
450 + tree_low_cst (DECL_FIELD_BIT_OFFSET (f_data
), 1) / BITS_PER_UNIT
);
451 sjlj_fc_personality_ofs
452 = (tree_low_cst (DECL_FIELD_OFFSET (f_per
), 1)
453 + tree_low_cst (DECL_FIELD_BIT_OFFSET (f_per
), 1) / BITS_PER_UNIT
);
455 = (tree_low_cst (DECL_FIELD_OFFSET (f_lsda
), 1)
456 + tree_low_cst (DECL_FIELD_BIT_OFFSET (f_lsda
), 1) / BITS_PER_UNIT
);
458 = (tree_low_cst (DECL_FIELD_OFFSET (f_jbuf
), 1)
459 + tree_low_cst (DECL_FIELD_BIT_OFFSET (f_jbuf
), 1) / BITS_PER_UNIT
);
464 init_eh_for_function ()
466 cfun
->eh
= (struct eh_status
*) xcalloc (1, sizeof (struct eh_status
));
469 /* Mark EH for GC. */
472 mark_eh_region (region
)
473 struct eh_region
*region
;
478 switch (region
->type
)
481 ggc_mark_tree (region
->u
.cleanup
.exp
);
484 ggc_mark_rtx (region
->u
.try.continue_label
);
487 ggc_mark_tree (region
->u
.catch.type
);
489 case ERT_ALLOWED_EXCEPTIONS
:
490 ggc_mark_tree (region
->u
.allowed
.type_list
);
492 case ERT_MUST_NOT_THROW
:
495 ggc_mark_tree (region
->u
.throw.type
);
498 ggc_mark_tree (region
->u
.fixup
.cleanup_exp
);
504 ggc_mark_rtx (region
->label
);
505 ggc_mark_rtx (region
->resume
);
506 ggc_mark_rtx (region
->landing_pad
);
507 ggc_mark_rtx (region
->post_landing_pad
);
512 struct eh_status
*eh
;
519 /* If we've called collect_eh_region_array, use it. Otherwise walk
520 the tree non-recursively. */
521 if (eh
->region_array
)
523 for (i
= eh
->last_region_number
; i
> 0; --i
)
525 struct eh_region
*r
= eh
->region_array
[i
];
526 if (r
&& r
->region_number
== i
)
530 else if (eh
->region_tree
)
532 struct eh_region
*r
= eh
->region_tree
;
538 else if (r
->next_peer
)
546 } while (r
->next_peer
== NULL
);
553 ggc_mark_tree (eh
->protect_list
);
554 ggc_mark_rtx (eh
->filter
);
555 ggc_mark_rtx (eh
->exc_ptr
);
556 ggc_mark_tree_varray (eh
->ttype_data
);
558 if (eh
->call_site_data
)
560 for (i
= eh
->call_site_data_used
- 1; i
>= 0; --i
)
561 ggc_mark_rtx (eh
->call_site_data
[i
].landing_pad
);
564 ggc_mark_rtx (eh
->ehr_stackadj
);
565 ggc_mark_rtx (eh
->ehr_handler
);
566 ggc_mark_rtx (eh
->ehr_label
);
568 ggc_mark_rtx (eh
->sjlj_fc
);
569 ggc_mark_rtx (eh
->sjlj_exit_after
);
576 struct eh_status
*eh
= f
->eh
;
578 if (eh
->region_array
)
581 for (i
= eh
->last_region_number
; i
> 0; --i
)
583 struct eh_region
*r
= eh
->region_array
[i
];
584 /* Mind we don't free a region struct more than once. */
585 if (r
&& r
->region_number
== i
)
588 free (eh
->region_array
);
590 else if (eh
->region_tree
)
592 struct eh_region
*next
, *r
= eh
->region_tree
;
597 else if (r
->next_peer
)
611 } while (r
->next_peer
== NULL
);
620 VARRAY_FREE (eh
->ttype_data
);
621 VARRAY_FREE (eh
->ehspec_data
);
622 VARRAY_FREE (eh
->action_record_data
);
623 if (eh
->call_site_data
)
624 free (eh
->call_site_data
);
631 /* Start an exception handling region. All instructions emitted
632 after this point are considered to be part of the region until
633 expand_eh_region_end is invoked. */
636 expand_eh_region_start ()
638 struct eh_region
*new_region
;
639 struct eh_region
*cur_region
;
645 /* Insert a new blank region as a leaf in the tree. */
646 new_region
= (struct eh_region
*) xcalloc (1, sizeof (*new_region
));
647 cur_region
= cfun
->eh
->cur_region
;
648 new_region
->outer
= cur_region
;
651 new_region
->next_peer
= cur_region
->inner
;
652 cur_region
->inner
= new_region
;
656 new_region
->next_peer
= cfun
->eh
->region_tree
;
657 cfun
->eh
->region_tree
= new_region
;
659 cfun
->eh
->cur_region
= new_region
;
661 /* Create a note marking the start of this region. */
662 new_region
->region_number
= ++cfun
->eh
->last_region_number
;
663 note
= emit_note (NULL
, NOTE_INSN_EH_REGION_BEG
);
664 NOTE_EH_HANDLER (note
) = new_region
->region_number
;
667 /* Common code to end a region. Returns the region just ended. */
669 static struct eh_region
*
670 expand_eh_region_end ()
672 struct eh_region
*cur_region
= cfun
->eh
->cur_region
;
675 /* Create a nute marking the end of this region. */
676 note
= emit_note (NULL
, NOTE_INSN_EH_REGION_END
);
677 NOTE_EH_HANDLER (note
) = cur_region
->region_number
;
680 cfun
->eh
->cur_region
= cur_region
->outer
;
685 /* End an exception handling region for a cleanup. HANDLER is an
686 expression to expand for the cleanup. */
689 expand_eh_region_end_cleanup (handler
)
692 struct eh_region
*region
;
693 tree protect_cleanup_actions
;
700 region
= expand_eh_region_end ();
701 region
->type
= ERT_CLEANUP
;
702 region
->label
= gen_label_rtx ();
703 region
->u
.cleanup
.exp
= handler
;
705 around_label
= gen_label_rtx ();
706 emit_jump (around_label
);
708 emit_label (region
->label
);
710 /* Give the language a chance to specify an action to be taken if an
711 exception is thrown that would propogate out of the HANDLER. */
712 protect_cleanup_actions
713 = (lang_protect_cleanup_actions
714 ? (*lang_protect_cleanup_actions
) ()
717 if (protect_cleanup_actions
)
718 expand_eh_region_start ();
720 /* In case this cleanup involves an inline destructor with a try block in
721 it, we need to save the EH return data registers around it. */
722 data_save
[0] = gen_reg_rtx (Pmode
);
723 emit_move_insn (data_save
[0], get_exception_pointer (cfun
));
724 data_save
[1] = gen_reg_rtx (word_mode
);
725 emit_move_insn (data_save
[1], get_exception_filter (cfun
));
727 expand_expr (handler
, const0_rtx
, VOIDmode
, 0);
729 emit_move_insn (cfun
->eh
->exc_ptr
, data_save
[0]);
730 emit_move_insn (cfun
->eh
->filter
, data_save
[1]);
732 if (protect_cleanup_actions
)
733 expand_eh_region_end_must_not_throw (protect_cleanup_actions
);
735 /* We need any stack adjustment complete before the around_label. */
736 do_pending_stack_adjust ();
738 /* We delay the generation of the _Unwind_Resume until we generate
739 landing pads. We emit a marker here so as to get good control
740 flow data in the meantime. */
742 = emit_jump_insn (gen_rtx_RESX (VOIDmode
, region
->region_number
));
745 emit_label (around_label
);
748 /* End an exception handling region for a try block, and prepares
749 for subsequent calls to expand_start_catch. */
752 expand_start_all_catch ()
754 struct eh_region
*region
;
759 region
= expand_eh_region_end ();
760 region
->type
= ERT_TRY
;
761 region
->u
.try.prev_try
= cfun
->eh
->try_region
;
762 region
->u
.try.continue_label
= gen_label_rtx ();
764 cfun
->eh
->try_region
= region
;
766 emit_jump (region
->u
.try.continue_label
);
769 /* Begin a catch clause. TYPE is the type caught, or null if this is
770 a catch-all clause. */
773 expand_start_catch (type
)
776 struct eh_region
*t
, *c
, *l
;
782 add_type_for_runtime (type
);
783 expand_eh_region_start ();
785 t
= cfun
->eh
->try_region
;
786 c
= cfun
->eh
->cur_region
;
788 c
->u
.catch.type
= type
;
789 c
->label
= gen_label_rtx ();
791 l
= t
->u
.try.last_catch
;
792 c
->u
.catch.prev_catch
= l
;
794 l
->u
.catch.next_catch
= c
;
797 t
->u
.try.last_catch
= c
;
799 emit_label (c
->label
);
802 /* End a catch clause. Control will resume after the try/catch block. */
807 struct eh_region
*try_region
, *catch_region
;
812 catch_region
= expand_eh_region_end ();
813 try_region
= cfun
->eh
->try_region
;
815 emit_jump (try_region
->u
.try.continue_label
);
818 /* End a sequence of catch handlers for a try block. */
821 expand_end_all_catch ()
823 struct eh_region
*try_region
;
828 try_region
= cfun
->eh
->try_region
;
829 cfun
->eh
->try_region
= try_region
->u
.try.prev_try
;
831 emit_label (try_region
->u
.try.continue_label
);
834 /* End an exception region for an exception type filter. ALLOWED is a
835 TREE_LIST of types to be matched by the runtime. FAILURE is an
836 expression to invoke if a mismatch ocurrs. */
839 expand_eh_region_end_allowed (allowed
, failure
)
840 tree allowed
, failure
;
842 struct eh_region
*region
;
848 region
= expand_eh_region_end ();
849 region
->type
= ERT_ALLOWED_EXCEPTIONS
;
850 region
->u
.allowed
.type_list
= allowed
;
851 region
->label
= gen_label_rtx ();
853 for (; allowed
; allowed
= TREE_CHAIN (allowed
))
854 add_type_for_runtime (TREE_VALUE (allowed
));
856 /* We must emit the call to FAILURE here, so that if this function
857 throws a different exception, that it will be processed by the
860 around_label
= gen_label_rtx ();
861 emit_jump (around_label
);
863 emit_label (region
->label
);
864 expand_expr (failure
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
865 /* We must adjust the stack before we reach the AROUND_LABEL because
866 the call to FAILURE does not occur on all paths to the
868 do_pending_stack_adjust ();
870 emit_label (around_label
);
873 /* End an exception region for a must-not-throw filter. FAILURE is an
874 expression invoke if an uncaught exception propagates this far.
876 This is conceptually identical to expand_eh_region_end_allowed with
877 an empty allowed list (if you passed "std::terminate" instead of
878 "__cxa_call_unexpected"), but they are represented differently in
882 expand_eh_region_end_must_not_throw (failure
)
885 struct eh_region
*region
;
891 region
= expand_eh_region_end ();
892 region
->type
= ERT_MUST_NOT_THROW
;
893 region
->label
= gen_label_rtx ();
895 /* We must emit the call to FAILURE here, so that if this function
896 throws a different exception, that it will be processed by the
899 around_label
= gen_label_rtx ();
900 emit_jump (around_label
);
902 emit_label (region
->label
);
903 expand_expr (failure
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
905 emit_label (around_label
);
908 /* End an exception region for a throw. No handling goes on here,
909 but it's the easiest way for the front-end to indicate what type
913 expand_eh_region_end_throw (type
)
916 struct eh_region
*region
;
921 region
= expand_eh_region_end ();
922 region
->type
= ERT_THROW
;
923 region
->u
.throw.type
= type
;
926 /* End a fixup region. Within this region the cleanups for the immediately
927 enclosing region are _not_ run. This is used for goto cleanup to avoid
928 destroying an object twice.
930 This would be an extraordinarily simple prospect, were it not for the
931 fact that we don't actually know what the immediately enclosing region
932 is. This surprising fact is because expand_cleanups is currently
933 generating a sequence that it will insert somewhere else. We collect
934 the proper notion of "enclosing" in convert_from_eh_region_ranges. */
937 expand_eh_region_end_fixup (handler
)
940 struct eh_region
*fixup
;
945 fixup
= expand_eh_region_end ();
946 fixup
->type
= ERT_FIXUP
;
947 fixup
->u
.fixup
.cleanup_exp
= handler
;
950 /* Return an rtl expression for a pointer to the exception object
954 get_exception_pointer (fun
)
955 struct function
*fun
;
957 rtx exc_ptr
= fun
->eh
->exc_ptr
;
958 if (fun
== cfun
&& ! exc_ptr
)
960 exc_ptr
= gen_reg_rtx (Pmode
);
961 fun
->eh
->exc_ptr
= exc_ptr
;
966 /* Return an rtl expression for the exception dispatch filter
970 get_exception_filter (fun
)
971 struct function
*fun
;
973 rtx filter
= fun
->eh
->filter
;
974 if (fun
== cfun
&& ! filter
)
976 filter
= gen_reg_rtx (word_mode
);
977 fun
->eh
->filter
= filter
;
982 /* Begin a region that will contain entries created with
983 add_partial_entry. */
986 begin_protect_partials ()
988 /* Push room for a new list. */
989 cfun
->eh
->protect_list
990 = tree_cons (NULL_TREE
, NULL_TREE
, cfun
->eh
->protect_list
);
993 /* Start a new exception region for a region of code that has a
994 cleanup action and push the HANDLER for the region onto
995 protect_list. All of the regions created with add_partial_entry
996 will be ended when end_protect_partials is invoked. */
999 add_partial_entry (handler
)
1002 expand_eh_region_start ();
1004 /* ??? This comment was old before the most recent rewrite. We
1005 really ought to fix the callers at some point. */
1006 /* For backwards compatibility, we allow callers to omit calls to
1007 begin_protect_partials for the outermost region. So, we must
1008 explicitly do so here. */
1009 if (!cfun
->eh
->protect_list
)
1010 begin_protect_partials ();
1012 /* Add this entry to the front of the list. */
1013 TREE_VALUE (cfun
->eh
->protect_list
)
1014 = tree_cons (NULL_TREE
, handler
, TREE_VALUE (cfun
->eh
->protect_list
));
1017 /* End all the pending exception regions on protect_list. */
1020 end_protect_partials ()
1024 /* ??? This comment was old before the most recent rewrite. We
1025 really ought to fix the callers at some point. */
1026 /* For backwards compatibility, we allow callers to omit the call to
1027 begin_protect_partials for the outermost region. So,
1028 PROTECT_LIST may be NULL. */
1029 if (!cfun
->eh
->protect_list
)
1032 /* Pop the topmost entry. */
1033 t
= TREE_VALUE (cfun
->eh
->protect_list
);
1034 cfun
->eh
->protect_list
= TREE_CHAIN (cfun
->eh
->protect_list
);
1036 /* End all the exception regions. */
1037 for (; t
; t
= TREE_CHAIN (t
))
1038 expand_eh_region_end_cleanup (TREE_VALUE (t
));
1042 /* This section is for the exception handling specific optimization pass. */
1044 /* Random access the exception region tree. It's just as simple to
1045 collect the regions this way as in expand_eh_region_start, but
1046 without having to realloc memory. */
1049 collect_eh_region_array ()
1051 struct eh_region
**array
, *i
;
1053 i
= cfun
->eh
->region_tree
;
1057 array
= xcalloc (cfun
->eh
->last_region_number
+ 1, sizeof (*array
));
1058 cfun
->eh
->region_array
= array
;
1062 array
[i
->region_number
] = i
;
1064 /* If there are sub-regions, process them. */
1067 /* If there are peers, process them. */
1068 else if (i
->next_peer
)
1070 /* Otherwise, step back up the tree to the next peer. */
1077 } while (i
->next_peer
== NULL
);
1084 resolve_fixup_regions ()
1086 int i
, j
, n
= cfun
->eh
->last_region_number
;
1088 for (i
= 1; i
<= n
; ++i
)
1090 struct eh_region
*fixup
= cfun
->eh
->region_array
[i
];
1091 struct eh_region
*cleanup
;
1093 if (! fixup
|| fixup
->type
!= ERT_FIXUP
)
1096 for (j
= 1; j
<= n
; ++j
)
1098 cleanup
= cfun
->eh
->region_array
[j
];
1099 if (cleanup
->type
== ERT_CLEANUP
1100 && cleanup
->u
.cleanup
.exp
== fixup
->u
.fixup
.cleanup_exp
)
1106 fixup
->u
.fixup
.real_region
= cleanup
->outer
;
1110 /* Now that we've discovered what region actually encloses a fixup,
1111 we can shuffle pointers and remove them from the tree. */
1114 remove_fixup_regions ()
1118 struct eh_region
*fixup
;
1120 /* Walk the insn chain and adjust the REG_EH_REGION numbers
1121 for instructions referencing fixup regions. This is only
1122 strictly necessary for fixup regions with no parent, but
1123 doesn't hurt to do it for all regions. */
1124 for (insn
= get_insns(); insn
; insn
= NEXT_INSN (insn
))
1126 && (note
= find_reg_note (insn
, REG_EH_REGION
, NULL
))
1127 && INTVAL (XEXP (note
, 0)) > 0
1128 && (fixup
= cfun
->eh
->region_array
[INTVAL (XEXP (note
, 0))])
1129 && fixup
->type
== ERT_FIXUP
)
1131 if (fixup
->u
.fixup
.real_region
)
1132 XEXP (note
, 1) = GEN_INT (fixup
->u
.fixup
.real_region
->region_number
);
1134 remove_note (insn
, note
);
1137 /* Remove the fixup regions from the tree. */
1138 for (i
= cfun
->eh
->last_region_number
; i
> 0; --i
)
1140 fixup
= cfun
->eh
->region_array
[i
];
1144 /* Allow GC to maybe free some memory. */
1145 if (fixup
->type
== ERT_CLEANUP
)
1146 fixup
->u
.cleanup
.exp
= NULL_TREE
;
1148 if (fixup
->type
!= ERT_FIXUP
)
1153 struct eh_region
*parent
, *p
, **pp
;
1155 parent
= fixup
->u
.fixup
.real_region
;
1157 /* Fix up the children's parent pointers; find the end of
1159 for (p
= fixup
->inner
; ; p
= p
->next_peer
)
1166 /* In the tree of cleanups, only outer-inner ordering matters.
1167 So link the children back in anywhere at the correct level. */
1169 pp
= &parent
->inner
;
1171 pp
= &cfun
->eh
->region_tree
;
1174 fixup
->inner
= NULL
;
1177 remove_eh_handler (fixup
);
1181 /* Turn NOTE_INSN_EH_REGION notes into REG_EH_REGION notes for each
1182 can_throw instruction in the region. */
1185 convert_from_eh_region_ranges_1 (pinsns
, orig_sp
, cur
)
1193 for (insn
= *pinsns
; insn
; insn
= next
)
1195 next
= NEXT_INSN (insn
);
1196 if (GET_CODE (insn
) == NOTE
)
1198 int kind
= NOTE_LINE_NUMBER (insn
);
1199 if (kind
== NOTE_INSN_EH_REGION_BEG
1200 || kind
== NOTE_INSN_EH_REGION_END
)
1202 if (kind
== NOTE_INSN_EH_REGION_BEG
)
1204 struct eh_region
*r
;
1207 cur
= NOTE_EH_HANDLER (insn
);
1209 r
= cfun
->eh
->region_array
[cur
];
1210 if (r
->type
== ERT_FIXUP
)
1212 r
= r
->u
.fixup
.real_region
;
1213 cur
= r
? r
->region_number
: 0;
1215 else if (r
->type
== ERT_CATCH
)
1218 cur
= r
? r
->region_number
: 0;
1224 /* Removing the first insn of a CALL_PLACEHOLDER sequence
1225 requires extra care to adjust sequence start. */
1226 if (insn
== *pinsns
)
1232 else if (INSN_P (insn
))
1235 && ! find_reg_note (insn
, REG_EH_REGION
, NULL_RTX
)
1236 /* Calls can always potentially throw exceptions, unless
1237 they have a REG_EH_REGION note with a value of 0 or less.
1238 Which should be the only possible kind so far. */
1239 && (GET_CODE (insn
) == CALL_INSN
1240 /* If we wanted exceptions for non-call insns, then
1241 any may_trap_p instruction could throw. */
1242 || (flag_non_call_exceptions
1243 && may_trap_p (PATTERN (insn
)))))
1245 REG_NOTES (insn
) = alloc_EXPR_LIST (REG_EH_REGION
, GEN_INT (cur
),
1249 if (GET_CODE (insn
) == CALL_INSN
1250 && GET_CODE (PATTERN (insn
)) == CALL_PLACEHOLDER
)
1252 convert_from_eh_region_ranges_1 (&XEXP (PATTERN (insn
), 0),
1254 convert_from_eh_region_ranges_1 (&XEXP (PATTERN (insn
), 1),
1256 convert_from_eh_region_ranges_1 (&XEXP (PATTERN (insn
), 2),
1267 convert_from_eh_region_ranges ()
1272 collect_eh_region_array ();
1273 resolve_fixup_regions ();
1275 stack
= xmalloc (sizeof (int) * (cfun
->eh
->last_region_number
+ 1));
1276 insns
= get_insns ();
1277 convert_from_eh_region_ranges_1 (&insns
, stack
, 0);
1280 remove_fixup_regions ();
1284 find_exception_handler_labels ()
1286 rtx list
= NULL_RTX
;
1289 free_EXPR_LIST_list (&exception_handler_labels
);
1291 if (cfun
->eh
->region_tree
== NULL
)
1294 for (i
= cfun
->eh
->last_region_number
; i
> 0; --i
)
1296 struct eh_region
*region
= cfun
->eh
->region_array
[i
];
1301 if (cfun
->eh
->built_landing_pads
)
1302 lab
= region
->landing_pad
;
1304 lab
= region
->label
;
1307 list
= alloc_EXPR_LIST (0, lab
, list
);
1310 /* For sjlj exceptions, need the return label to remain live until
1311 after landing pad generation. */
1312 if (USING_SJLJ_EXCEPTIONS
&& ! cfun
->eh
->built_landing_pads
)
1313 list
= alloc_EXPR_LIST (0, return_label
, list
);
1315 exception_handler_labels
= list
;
1319 static struct eh_region
*
1320 duplicate_eh_region_1 (o
, map
)
1321 struct eh_region
*o
;
1322 struct inline_remap
*map
;
1325 = (struct eh_region
*) xcalloc (1, sizeof (struct eh_region
));
1327 n
->region_number
= o
->region_number
+ cfun
->eh
->last_region_number
;
1333 case ERT_MUST_NOT_THROW
:
1337 if (o
->u
.try.continue_label
)
1338 n
->u
.try.continue_label
1339 = get_label_from_map (map
,
1340 CODE_LABEL_NUMBER (o
->u
.try.continue_label
));
1344 n
->u
.catch.type
= o
->u
.catch.type
;
1347 case ERT_ALLOWED_EXCEPTIONS
:
1348 n
->u
.allowed
.type_list
= o
->u
.allowed
.type_list
;
1352 n
->u
.throw.type
= o
->u
.throw.type
;
1359 n
->label
= get_label_from_map (map
, CODE_LABEL_NUMBER (o
->label
));
1362 n
->resume
= map
->insn_map
[INSN_UID (o
->resume
)];
1363 if (n
->resume
== NULL
)
1371 duplicate_eh_region_2 (o
, n_array
)
1372 struct eh_region
*o
;
1373 struct eh_region
**n_array
;
1375 struct eh_region
*n
= n_array
[o
->region_number
];
1380 n
->u
.try.catch = n_array
[o
->u
.try.catch->region_number
];
1381 n
->u
.try.last_catch
= n_array
[o
->u
.try.last_catch
->region_number
];
1385 if (o
->u
.catch.next_catch
)
1386 n
->u
.catch.next_catch
= n_array
[o
->u
.catch.next_catch
->region_number
];
1387 if (o
->u
.catch.prev_catch
)
1388 n
->u
.catch.prev_catch
= n_array
[o
->u
.catch.prev_catch
->region_number
];
1396 n
->outer
= n_array
[o
->outer
->region_number
];
1398 n
->inner
= n_array
[o
->inner
->region_number
];
1400 n
->next_peer
= n_array
[o
->next_peer
->region_number
];
1404 duplicate_eh_regions (ifun
, map
)
1405 struct function
*ifun
;
1406 struct inline_remap
*map
;
1408 int ifun_last_region_number
= ifun
->eh
->last_region_number
;
1409 struct eh_region
**n_array
, *root
, *cur
;
1412 if (ifun_last_region_number
== 0)
1415 n_array
= xcalloc (ifun_last_region_number
+ 1, sizeof (*n_array
));
1417 for (i
= 1; i
<= ifun_last_region_number
; ++i
)
1419 cur
= ifun
->eh
->region_array
[i
];
1420 if (!cur
|| cur
->region_number
!= i
)
1422 n_array
[i
] = duplicate_eh_region_1 (cur
, map
);
1424 for (i
= 1; i
<= ifun_last_region_number
; ++i
)
1426 cur
= ifun
->eh
->region_array
[i
];
1427 if (!cur
|| cur
->region_number
!= i
)
1429 duplicate_eh_region_2 (cur
, n_array
);
1432 root
= n_array
[ifun
->eh
->region_tree
->region_number
];
1433 cur
= cfun
->eh
->cur_region
;
1436 struct eh_region
*p
= cur
->inner
;
1439 while (p
->next_peer
)
1441 p
->next_peer
= root
;
1446 for (i
= 1; i
<= ifun_last_region_number
; ++i
)
1447 if (n_array
[i
]->outer
== NULL
)
1448 n_array
[i
]->outer
= cur
;
1452 struct eh_region
*p
= cfun
->eh
->region_tree
;
1455 while (p
->next_peer
)
1457 p
->next_peer
= root
;
1460 cfun
->eh
->region_tree
= root
;
1465 i
= cfun
->eh
->last_region_number
;
1466 cfun
->eh
->last_region_number
= i
+ ifun_last_region_number
;
1471 /* ??? Move from tree.c to tree.h. */
1472 #define TYPE_HASH(TYPE) ((HOST_WIDE_INT) (TYPE) & 0777777)
1475 t2r_eq (pentry
, pdata
)
1479 tree entry
= (tree
) pentry
;
1480 tree data
= (tree
) pdata
;
1482 return TREE_PURPOSE (entry
) == data
;
1489 tree entry
= (tree
) pentry
;
1490 return TYPE_HASH (TREE_PURPOSE (entry
));
1494 t2r_mark_1 (slot
, data
)
1496 PTR data ATTRIBUTE_UNUSED
;
1498 tree contents
= (tree
) *slot
;
1499 ggc_mark_tree (contents
);
1507 htab_traverse (*(htab_t
*)addr
, t2r_mark_1
, NULL
);
1511 add_type_for_runtime (type
)
1516 slot
= (tree
*) htab_find_slot_with_hash (type_to_runtime_map
, type
,
1517 TYPE_HASH (type
), INSERT
);
1520 tree runtime
= (*lang_eh_runtime_type
) (type
);
1521 *slot
= tree_cons (type
, runtime
, NULL_TREE
);
1526 lookup_type_for_runtime (type
)
1531 slot
= (tree
*) htab_find_slot_with_hash (type_to_runtime_map
, type
,
1532 TYPE_HASH (type
), NO_INSERT
);
1534 /* We should have always inserrted the data earlier. */
1535 return TREE_VALUE (*slot
);
1539 /* Represent an entry in @TTypes for either catch actions
1540 or exception filter actions. */
1541 struct ttypes_filter
1547 /* Compare ENTRY (a ttypes_filter entry in the hash table) with DATA
1548 (a tree) for a @TTypes type node we are thinking about adding. */
1551 ttypes_filter_eq (pentry
, pdata
)
1555 const struct ttypes_filter
*entry
= (const struct ttypes_filter
*) pentry
;
1556 tree data
= (tree
) pdata
;
1558 return entry
->t
== data
;
1562 ttypes_filter_hash (pentry
)
1565 const struct ttypes_filter
*entry
= (const struct ttypes_filter
*) pentry
;
1566 return TYPE_HASH (entry
->t
);
1569 /* Compare ENTRY with DATA (both struct ttypes_filter) for a @TTypes
1570 exception specification list we are thinking about adding. */
1571 /* ??? Currently we use the type lists in the order given. Someone
1572 should put these in some canonical order. */
1575 ehspec_filter_eq (pentry
, pdata
)
1579 const struct ttypes_filter
*entry
= (const struct ttypes_filter
*) pentry
;
1580 const struct ttypes_filter
*data
= (const struct ttypes_filter
*) pdata
;
1582 return type_list_equal (entry
->t
, data
->t
);
1585 /* Hash function for exception specification lists. */
1588 ehspec_filter_hash (pentry
)
1591 const struct ttypes_filter
*entry
= (const struct ttypes_filter
*) pentry
;
1595 for (list
= entry
->t
; list
; list
= TREE_CHAIN (list
))
1596 h
= (h
<< 5) + (h
>> 27) + TYPE_HASH (TREE_VALUE (list
));
1600 /* Add TYPE to cfun->eh->ttype_data, using TYPES_HASH to speed
1601 up the search. Return the filter value to be used. */
1604 add_ttypes_entry (ttypes_hash
, type
)
1608 struct ttypes_filter
**slot
, *n
;
1610 slot
= (struct ttypes_filter
**)
1611 htab_find_slot_with_hash (ttypes_hash
, type
, TYPE_HASH (type
), INSERT
);
1613 if ((n
= *slot
) == NULL
)
1615 /* Filter value is a 1 based table index. */
1617 n
= (struct ttypes_filter
*) xmalloc (sizeof (*n
));
1619 n
->filter
= VARRAY_ACTIVE_SIZE (cfun
->eh
->ttype_data
) + 1;
1622 VARRAY_PUSH_TREE (cfun
->eh
->ttype_data
, type
);
1628 /* Add LIST to cfun->eh->ehspec_data, using EHSPEC_HASH and TYPES_HASH
1629 to speed up the search. Return the filter value to be used. */
1632 add_ehspec_entry (ehspec_hash
, ttypes_hash
, list
)
1637 struct ttypes_filter
**slot
, *n
;
1638 struct ttypes_filter dummy
;
1641 slot
= (struct ttypes_filter
**)
1642 htab_find_slot (ehspec_hash
, &dummy
, INSERT
);
1644 if ((n
= *slot
) == NULL
)
1646 /* Filter value is a -1 based byte index into a uleb128 buffer. */
1648 n
= (struct ttypes_filter
*) xmalloc (sizeof (*n
));
1650 n
->filter
= -(VARRAY_ACTIVE_SIZE (cfun
->eh
->ehspec_data
) + 1);
1653 /* Look up each type in the list and encode its filter
1654 value as a uleb128. Terminate the list with 0. */
1655 for (; list
; list
= TREE_CHAIN (list
))
1656 push_uleb128 (&cfun
->eh
->ehspec_data
,
1657 add_ttypes_entry (ttypes_hash
, TREE_VALUE (list
)));
1658 VARRAY_PUSH_UCHAR (cfun
->eh
->ehspec_data
, 0);
1664 /* Generate the action filter values to be used for CATCH and
1665 ALLOWED_EXCEPTIONS regions. When using dwarf2 exception regions,
1666 we use lots of landing pads, and so every type or list can share
1667 the same filter value, which saves table space. */
1670 assign_filter_values ()
1673 htab_t ttypes
, ehspec
;
1675 VARRAY_TREE_INIT (cfun
->eh
->ttype_data
, 16, "ttype_data");
1676 VARRAY_UCHAR_INIT (cfun
->eh
->ehspec_data
, 64, "ehspec_data");
1678 ttypes
= htab_create (31, ttypes_filter_hash
, ttypes_filter_eq
, free
);
1679 ehspec
= htab_create (31, ehspec_filter_hash
, ehspec_filter_eq
, free
);
1681 for (i
= cfun
->eh
->last_region_number
; i
> 0; --i
)
1683 struct eh_region
*r
= cfun
->eh
->region_array
[i
];
1685 /* Mind we don't process a region more than once. */
1686 if (!r
|| r
->region_number
!= i
)
1692 r
->u
.catch.filter
= add_ttypes_entry (ttypes
, r
->u
.catch.type
);
1695 case ERT_ALLOWED_EXCEPTIONS
:
1697 = add_ehspec_entry (ehspec
, ttypes
, r
->u
.allowed
.type_list
);
1705 htab_delete (ttypes
);
1706 htab_delete (ehspec
);
1710 build_post_landing_pads ()
1714 for (i
= cfun
->eh
->last_region_number
; i
> 0; --i
)
1716 struct eh_region
*region
= cfun
->eh
->region_array
[i
];
1719 /* Mind we don't process a region more than once. */
1720 if (!region
|| region
->region_number
!= i
)
1723 switch (region
->type
)
1726 /* ??? Collect the set of all non-overlapping catch handlers
1727 all the way up the chain until blocked by a cleanup. */
1728 /* ??? Outer try regions can share landing pads with inner
1729 try regions if the types are completely non-overlapping,
1730 and there are no interveaning cleanups. */
1732 region
->post_landing_pad
= gen_label_rtx ();
1736 emit_label (region
->post_landing_pad
);
1738 /* ??? It is mighty inconvenient to call back into the
1739 switch statement generation code in expand_end_case.
1740 Rapid prototyping sez a sequence of ifs. */
1742 struct eh_region
*c
;
1743 for (c
= region
->u
.try.catch; c
; c
= c
->u
.catch.next_catch
)
1745 /* ??? _Unwind_ForcedUnwind wants no match here. */
1746 if (c
->u
.catch.type
== NULL
)
1747 emit_jump (c
->label
);
1749 emit_cmp_and_jump_insns (cfun
->eh
->filter
,
1750 GEN_INT (c
->u
.catch.filter
),
1751 EQ
, NULL_RTX
, word_mode
,
1756 /* We delay the generation of the _Unwind_Resume until we generate
1757 landing pads. We emit a marker here so as to get good control
1758 flow data in the meantime. */
1760 = emit_jump_insn (gen_rtx_RESX (VOIDmode
, region
->region_number
));
1766 emit_insns_before (seq
, region
->u
.try.catch->label
);
1769 case ERT_ALLOWED_EXCEPTIONS
:
1770 region
->post_landing_pad
= gen_label_rtx ();
1774 emit_label (region
->post_landing_pad
);
1776 emit_cmp_and_jump_insns (cfun
->eh
->filter
,
1777 GEN_INT (region
->u
.allowed
.filter
),
1778 EQ
, NULL_RTX
, word_mode
, 0, 0,
1781 /* We delay the generation of the _Unwind_Resume until we generate
1782 landing pads. We emit a marker here so as to get good control
1783 flow data in the meantime. */
1785 = emit_jump_insn (gen_rtx_RESX (VOIDmode
, region
->region_number
));
1791 emit_insns_before (seq
, region
->label
);
1795 case ERT_MUST_NOT_THROW
:
1796 region
->post_landing_pad
= region
->label
;
1801 /* Nothing to do. */
1810 /* Replace RESX patterns with jumps to the next handler if any, or calls to
1811 _Unwind_Resume otherwise. */
1814 connect_post_landing_pads ()
1818 for (i
= cfun
->eh
->last_region_number
; i
> 0; --i
)
1820 struct eh_region
*region
= cfun
->eh
->region_array
[i
];
1821 struct eh_region
*outer
;
1824 /* Mind we don't process a region more than once. */
1825 if (!region
|| region
->region_number
!= i
)
1828 /* If there is no RESX, or it has been deleted by flow, there's
1829 nothing to fix up. */
1830 if (! region
->resume
|| INSN_DELETED_P (region
->resume
))
1833 /* Search for another landing pad in this function. */
1834 for (outer
= region
->outer
; outer
; outer
= outer
->outer
)
1835 if (outer
->post_landing_pad
)
1841 emit_jump (outer
->post_landing_pad
);
1843 emit_library_call (unwind_resume_libfunc
, LCT_THROW
,
1844 VOIDmode
, 1, cfun
->eh
->exc_ptr
, Pmode
);
1848 emit_insns_before (seq
, region
->resume
);
1850 /* Leave the RESX to be deleted by flow. */
1856 dw2_build_landing_pads ()
1860 for (i
= cfun
->eh
->last_region_number
; i
> 0; --i
)
1862 struct eh_region
*region
= cfun
->eh
->region_array
[i
];
1865 /* Mind we don't process a region more than once. */
1866 if (!region
|| region
->region_number
!= i
)
1869 if (region
->type
!= ERT_CLEANUP
1870 && region
->type
!= ERT_TRY
1871 && region
->type
!= ERT_ALLOWED_EXCEPTIONS
)
1876 region
->landing_pad
= gen_label_rtx ();
1877 emit_label (region
->landing_pad
);
1879 #ifdef HAVE_exception_receiver
1880 if (HAVE_exception_receiver
)
1881 emit_insn (gen_exception_receiver ());
1884 #ifdef HAVE_nonlocal_goto_receiver
1885 if (HAVE_nonlocal_goto_receiver
)
1886 emit_insn (gen_nonlocal_goto_receiver ());
1891 /* If the eh_return data registers are call-saved, then we
1892 won't have considered them clobbered from the call that
1893 threw. Kill them now. */
1896 unsigned r
= EH_RETURN_DATA_REGNO (j
);
1897 if (r
== INVALID_REGNUM
)
1899 if (! call_used_regs
[r
])
1900 emit_insn (gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (Pmode
, r
)));
1903 emit_move_insn (cfun
->eh
->exc_ptr
,
1904 gen_rtx_REG (Pmode
, EH_RETURN_DATA_REGNO (0)));
1905 emit_move_insn (cfun
->eh
->filter
,
1906 gen_rtx_REG (word_mode
, EH_RETURN_DATA_REGNO (1)));
1911 emit_insns_before (seq
, region
->post_landing_pad
);
1918 int directly_reachable
;
1921 int call_site_index
;
1925 sjlj_find_directly_reachable_regions (lp_info
)
1926 struct sjlj_lp_info
*lp_info
;
1929 bool found_one
= false;
1931 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
1933 struct eh_region
*region
;
1937 if (! INSN_P (insn
))
1940 note
= find_reg_note (insn
, REG_EH_REGION
, NULL_RTX
);
1941 if (!note
|| INTVAL (XEXP (note
, 0)) <= 0)
1944 region
= cfun
->eh
->region_array
[INTVAL (XEXP (note
, 0))];
1946 type_thrown
= NULL_TREE
;
1947 if (region
->type
== ERT_THROW
)
1949 type_thrown
= region
->u
.throw.type
;
1950 region
= region
->outer
;
1953 /* Find the first containing region that might handle the exception.
1954 That's the landing pad to which we will transfer control. */
1955 for (; region
; region
= region
->outer
)
1956 if (reachable_next_level (region
, type_thrown
, 0) != RNL_NOT_CAUGHT
)
1961 lp_info
[region
->region_number
].directly_reachable
= 1;
1970 sjlj_assign_call_site_values (dispatch_label
, lp_info
)
1972 struct sjlj_lp_info
*lp_info
;
1977 /* First task: build the action table. */
1979 VARRAY_UCHAR_INIT (cfun
->eh
->action_record_data
, 64, "action_record_data");
1980 ar_hash
= htab_create (31, action_record_hash
, action_record_eq
, free
);
1982 for (i
= cfun
->eh
->last_region_number
; i
> 0; --i
)
1983 if (lp_info
[i
].directly_reachable
)
1985 struct eh_region
*r
= cfun
->eh
->region_array
[i
];
1986 r
->landing_pad
= dispatch_label
;
1987 lp_info
[i
].action_index
= collect_one_action_chain (ar_hash
, r
);
1988 if (lp_info
[i
].action_index
!= -1)
1989 cfun
->uses_eh_lsda
= 1;
1992 htab_delete (ar_hash
);
1994 /* Next: assign dispatch values. In dwarf2 terms, this would be the
1995 landing pad label for the region. For sjlj though, there is one
1996 common landing pad from which we dispatch to the post-landing pads.
1998 A region receives a dispatch index if it is directly reachable
1999 and requires in-function processing. Regions that share post-landing
2000 pads may share dispatch indicies. */
2001 /* ??? Post-landing pad sharing doesn't actually happen at the moment
2002 (see build_post_landing_pads) so we don't bother checking for it. */
2005 for (i
= cfun
->eh
->last_region_number
; i
> 0; --i
)
2006 if (lp_info
[i
].directly_reachable
2007 && lp_info
[i
].action_index
>= 0)
2008 lp_info
[i
].dispatch_index
= index
++;
2010 /* Finally: assign call-site values. If dwarf2 terms, this would be
2011 the region number assigned by convert_to_eh_region_ranges, but
2012 handles no-action and must-not-throw differently. */
2015 for (i
= cfun
->eh
->last_region_number
; i
> 0; --i
)
2016 if (lp_info
[i
].directly_reachable
)
2018 int action
= lp_info
[i
].action_index
;
2020 /* Map must-not-throw to otherwise unused call-site index 0. */
2023 /* Map no-action to otherwise unused call-site index -1. */
2024 else if (action
== -1)
2026 /* Otherwise, look it up in the table. */
2028 index
= add_call_site (GEN_INT (lp_info
[i
].dispatch_index
), action
);
2030 lp_info
[i
].call_site_index
= index
;
2035 sjlj_mark_call_sites (lp_info
)
2036 struct sjlj_lp_info
*lp_info
;
2038 int last_call_site
= -2;
2041 mem
= change_address (cfun
->eh
->sjlj_fc
, TYPE_MODE (integer_type_node
),
2042 plus_constant (XEXP (cfun
->eh
->sjlj_fc
, 0),
2043 sjlj_fc_call_site_ofs
));
2045 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
2047 struct eh_region
*region
;
2049 rtx note
, before
, p
;
2051 /* Reset value tracking at extended basic block boundaries. */
2052 if (GET_CODE (insn
) == CODE_LABEL
)
2053 last_call_site
= -2;
2055 if (! INSN_P (insn
))
2058 note
= find_reg_note (insn
, REG_EH_REGION
, NULL_RTX
);
2061 /* Calls (and trapping insns) without notes are outside any
2062 exception handling region in this function. Mark them as
2064 if (GET_CODE (insn
) == CALL_INSN
2065 || (flag_non_call_exceptions
2066 && may_trap_p (PATTERN (insn
))))
2067 this_call_site
= -1;
2073 /* Calls that are known to not throw need not be marked. */
2074 if (INTVAL (XEXP (note
, 0)) <= 0)
2077 region
= cfun
->eh
->region_array
[INTVAL (XEXP (note
, 0))];
2078 this_call_site
= lp_info
[region
->region_number
].call_site_index
;
2081 if (this_call_site
== last_call_site
)
2084 /* Don't separate a call from it's argument loads. */
2086 if (GET_CODE (insn
) == CALL_INSN
)
2088 HARD_REG_SET parm_regs
;
2091 /* Since different machines initialize their parameter registers
2092 in different orders, assume nothing. Collect the set of all
2093 parameter registers. */
2094 CLEAR_HARD_REG_SET (parm_regs
);
2096 for (p
= CALL_INSN_FUNCTION_USAGE (insn
); p
; p
= XEXP (p
, 1))
2097 if (GET_CODE (XEXP (p
, 0)) == USE
2098 && GET_CODE (XEXP (XEXP (p
, 0), 0)) == REG
)
2100 if (REGNO (XEXP (XEXP (p
, 0), 0)) >= FIRST_PSEUDO_REGISTER
)
2103 /* We only care about registers which can hold function
2105 if (! FUNCTION_ARG_REGNO_P (REGNO (XEXP (XEXP (p
, 0), 0))))
2108 SET_HARD_REG_BIT (parm_regs
, REGNO (XEXP (XEXP (p
, 0), 0)));
2112 /* Search backward for the first set of a register in this set. */
2115 before
= PREV_INSN (before
);
2117 /* Given that we've done no other optimizations yet,
2118 the arguments should be immediately available. */
2119 if (GET_CODE (before
) == CODE_LABEL
)
2122 p
= single_set (before
);
2123 if (p
&& GET_CODE (SET_DEST (p
)) == REG
2124 && REGNO (SET_DEST (p
)) < FIRST_PSEUDO_REGISTER
2125 && TEST_HARD_REG_BIT (parm_regs
, REGNO (SET_DEST (p
))))
2127 CLEAR_HARD_REG_BIT (parm_regs
, REGNO (SET_DEST (p
)));
2134 emit_move_insn (mem
, GEN_INT (this_call_site
));
2138 emit_insns_before (p
, before
);
2139 last_call_site
= this_call_site
;
2143 /* Construct the SjLj_Function_Context. */
2146 sjlj_emit_function_enter (dispatch_label
)
2149 rtx fn_begin
, fc
, mem
, seq
;
2151 fc
= cfun
->eh
->sjlj_fc
;
2155 /* We're storing this libcall's address into memory instead of
2156 calling it directly. Thus, we must call assemble_external_libcall
2157 here, as we can not depend on emit_library_call to do it for us. */
2158 assemble_external_libcall (eh_personality_libfunc
);
2159 mem
= change_address (fc
, Pmode
,
2160 plus_constant (XEXP (fc
, 0), sjlj_fc_personality_ofs
));
2161 emit_move_insn (mem
, eh_personality_libfunc
);
2163 mem
= change_address (fc
, Pmode
,
2164 plus_constant (XEXP (fc
, 0), sjlj_fc_lsda_ofs
));
2165 if (cfun
->uses_eh_lsda
)
2168 ASM_GENERATE_INTERNAL_LABEL (buf
, "LLSDA", sjlj_funcdef_number
);
2169 emit_move_insn (mem
, gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (buf
)));
2172 emit_move_insn (mem
, const0_rtx
);
2174 #ifdef DONT_USE_BUILTIN_SETJMP
2177 x
= emit_library_call_value (setjmp_libfunc
, NULL_RTX
, LCT_NORMAL
,
2178 TYPE_MODE (integer_type_node
), 1,
2179 plus_constant (XEXP (fc
, 0),
2180 sjlj_fc_jbuf_ofs
), Pmode
);
2182 note
= emit_note (NULL
, NOTE_INSN_EXPECTED_VALUE
);
2183 NOTE_EXPECTED_VALUE (note
) = gen_rtx_EQ (VOIDmode
, x
, const0_rtx
);
2185 emit_cmp_and_jump_insns (x
, const0_rtx
, NE
, 0,
2186 TYPE_MODE (integer_type_node
), 0, 0,
2190 expand_builtin_setjmp_setup (plus_constant (XEXP (fc
, 0), sjlj_fc_jbuf_ofs
),
2194 emit_library_call (unwind_sjlj_register_libfunc
, LCT_NORMAL
, VOIDmode
,
2195 1, XEXP (fc
, 0), Pmode
);
2200 /* ??? Instead of doing this at the beginning of the function,
2201 do this in a block that is at loop level 0 and dominates all
2202 can_throw_internal instructions. */
2204 for (fn_begin
= get_insns (); ; fn_begin
= NEXT_INSN (fn_begin
))
2205 if (GET_CODE (fn_begin
) == NOTE
2206 && NOTE_LINE_NUMBER (fn_begin
) == NOTE_INSN_FUNCTION_BEG
)
2208 emit_insns_after (seq
, fn_begin
);
2211 /* Call back from expand_function_end to know where we should put
2212 the call to unwind_sjlj_unregister_libfunc if needed. */
2215 sjlj_emit_function_exit_after (after
)
2218 cfun
->eh
->sjlj_exit_after
= after
;
2222 sjlj_emit_function_exit ()
2228 emit_library_call (unwind_sjlj_unregister_libfunc
, LCT_NORMAL
, VOIDmode
,
2229 1, XEXP (cfun
->eh
->sjlj_fc
, 0), Pmode
);
2234 /* ??? Really this can be done in any block at loop level 0 that
2235 post-dominates all can_throw_internal instructions. This is
2236 the last possible moment. */
2238 emit_insns_after (seq
, cfun
->eh
->sjlj_exit_after
);
2242 sjlj_emit_dispatch_table (dispatch_label
, lp_info
)
2244 struct sjlj_lp_info
*lp_info
;
2246 int i
, first_reachable
;
2247 rtx mem
, dispatch
, seq
, fc
;
2249 fc
= cfun
->eh
->sjlj_fc
;
2253 emit_label (dispatch_label
);
2255 #ifndef DONT_USE_BUILTIN_SETJMP
2256 expand_builtin_setjmp_receiver (dispatch_label
);
2259 /* Load up dispatch index, exc_ptr and filter values from the
2260 function context. */
2261 mem
= change_address (fc
, TYPE_MODE (integer_type_node
),
2262 plus_constant (XEXP (fc
, 0), sjlj_fc_call_site_ofs
));
2263 dispatch
= copy_to_reg (mem
);
2265 mem
= change_address (fc
, word_mode
,
2266 plus_constant (XEXP (fc
, 0), sjlj_fc_data_ofs
));
2267 if (word_mode
!= Pmode
)
2269 #ifdef POINTERS_EXTEND_UNSIGNED
2270 mem
= convert_memory_address (Pmode
, mem
);
2272 mem
= convert_to_mode (Pmode
, mem
, 0);
2275 emit_move_insn (cfun
->eh
->exc_ptr
, mem
);
2277 mem
= change_address (fc
, word_mode
,
2278 plus_constant (XEXP (fc
, 0),
2279 sjlj_fc_data_ofs
+ UNITS_PER_WORD
));
2280 emit_move_insn (cfun
->eh
->filter
, mem
);
2282 /* Jump to one of the directly reachable regions. */
2283 /* ??? This really ought to be using a switch statement. */
2285 first_reachable
= 0;
2286 for (i
= cfun
->eh
->last_region_number
; i
> 0; --i
)
2288 if (! lp_info
[i
].directly_reachable
2289 || lp_info
[i
].action_index
< 0)
2292 if (! first_reachable
)
2294 first_reachable
= i
;
2298 emit_cmp_and_jump_insns (dispatch
,
2299 GEN_INT (lp_info
[i
].dispatch_index
), EQ
,
2300 NULL_RTX
, TYPE_MODE (integer_type_node
), 0, 0,
2301 cfun
->eh
->region_array
[i
]->post_landing_pad
);
2307 emit_insns_before (seq
, (cfun
->eh
->region_array
[first_reachable
]
2308 ->post_landing_pad
));
2312 sjlj_build_landing_pads ()
2314 struct sjlj_lp_info
*lp_info
;
2316 lp_info
= (struct sjlj_lp_info
*) xcalloc (cfun
->eh
->last_region_number
+ 1,
2317 sizeof (struct sjlj_lp_info
));
2319 if (sjlj_find_directly_reachable_regions (lp_info
))
2321 rtx dispatch_label
= gen_label_rtx ();
2324 = assign_stack_local (TYPE_MODE (sjlj_fc_type_node
),
2325 int_size_in_bytes (sjlj_fc_type_node
),
2326 TYPE_ALIGN (sjlj_fc_type_node
));
2328 sjlj_assign_call_site_values (dispatch_label
, lp_info
);
2329 sjlj_mark_call_sites (lp_info
);
2331 sjlj_emit_function_enter (dispatch_label
);
2332 sjlj_emit_dispatch_table (dispatch_label
, lp_info
);
2333 sjlj_emit_function_exit ();
2340 finish_eh_generation ()
2342 /* Nothing to do if no regions created. */
2343 if (cfun
->eh
->region_tree
== NULL
)
2346 /* The object here is to provide find_basic_blocks with detailed
2347 information (via reachable_handlers) on how exception control
2348 flows within the function. In this first pass, we can include
2349 type information garnered from ERT_THROW and ERT_ALLOWED_EXCEPTIONS
2350 regions, and hope that it will be useful in deleting unreachable
2351 handlers. Subsequently, we will generate landing pads which will
2352 connect many of the handlers, and then type information will not
2353 be effective. Still, this is a win over previous implementations. */
2355 jump_optimize_minimal (get_insns ());
2356 find_basic_blocks (get_insns (), max_reg_num (), 0);
2359 /* These registers are used by the landing pads. Make sure they
2360 have been generated. */
2361 get_exception_pointer (cfun
);
2362 get_exception_filter (cfun
);
2364 /* Construct the landing pads. */
2366 assign_filter_values ();
2367 build_post_landing_pads ();
2368 connect_post_landing_pads ();
2369 if (USING_SJLJ_EXCEPTIONS
)
2370 sjlj_build_landing_pads ();
2372 dw2_build_landing_pads ();
2374 cfun
->eh
->built_landing_pads
= 1;
2376 /* We've totally changed the CFG. Start over. */
2377 find_exception_handler_labels ();
2378 jump_optimize_minimal (get_insns ());
2379 find_basic_blocks (get_insns (), max_reg_num (), 0);
2383 /* This section handles removing dead code for flow. */
2385 /* Remove LABEL from the exception_handler_labels list. */
2388 remove_exception_handler_label (label
)
2393 for (pl
= &exception_handler_labels
, l
= *pl
;
2394 XEXP (l
, 0) != label
;
2395 pl
= &XEXP (l
, 1), l
= *pl
)
2399 free_EXPR_LIST_node (l
);
2402 /* Splice REGION from the region tree etc. */
2405 remove_eh_handler (region
)
2406 struct eh_region
*region
;
2408 struct eh_region
**pp
, *p
;
2412 /* For the benefit of efficiently handling REG_EH_REGION notes,
2413 replace this region in the region array with its containing
2414 region. Note that previous region deletions may result in
2415 multiple copies of this region in the array, so we have to
2416 search the whole thing. */
2417 for (i
= cfun
->eh
->last_region_number
; i
> 0; --i
)
2418 if (cfun
->eh
->region_array
[i
] == region
)
2419 cfun
->eh
->region_array
[i
] = region
->outer
;
2421 if (cfun
->eh
->built_landing_pads
)
2422 lab
= region
->landing_pad
;
2424 lab
= region
->label
;
2426 remove_exception_handler_label (lab
);
2429 pp
= ®ion
->outer
->inner
;
2431 pp
= &cfun
->eh
->region_tree
;
2432 for (p
= *pp
; p
!= region
; pp
= &p
->next_peer
, p
= *pp
)
2437 for (p
= region
->inner
; p
->next_peer
; p
= p
->next_peer
)
2438 p
->outer
= region
->outer
;
2439 p
->next_peer
= region
->next_peer
;
2440 p
->outer
= region
->outer
;
2441 *pp
= region
->inner
;
2444 *pp
= region
->next_peer
;
2446 if (region
->type
== ERT_CATCH
)
2448 struct eh_region
*try, *next
, *prev
;
2450 for (try = region
->next_peer
;
2451 try->type
== ERT_CATCH
;
2452 try = try->next_peer
)
2454 if (try->type
!= ERT_TRY
)
2457 next
= region
->u
.catch.next_catch
;
2458 prev
= region
->u
.catch.prev_catch
;
2461 next
->u
.catch.prev_catch
= prev
;
2463 try->u
.try.last_catch
= prev
;
2465 prev
->u
.catch.next_catch
= next
;
2468 try->u
.try.catch = next
;
2470 remove_eh_handler (try);
2477 /* LABEL heads a basic block that is about to be deleted. If this
2478 label corresponds to an exception region, we may be able to
2479 delete the region. */
2482 maybe_remove_eh_handler (label
)
2487 /* ??? After generating landing pads, it's not so simple to determine
2488 if the region data is completely unused. One must examine the
2489 landing pad and the post landing pad, and whether an inner try block
2490 is referencing the catch handlers directly. */
2491 if (cfun
->eh
->built_landing_pads
)
2494 for (i
= cfun
->eh
->last_region_number
; i
> 0; --i
)
2496 struct eh_region
*region
= cfun
->eh
->region_array
[i
];
2497 if (region
&& region
->label
== label
)
2499 /* Flow will want to remove MUST_NOT_THROW regions as unreachable
2500 because there is no path to the fallback call to terminate.
2501 But the region continues to affect call-site data until there
2502 are no more contained calls, which we don't see here. */
2503 if (region
->type
== ERT_MUST_NOT_THROW
)
2505 remove_exception_handler_label (region
->label
);
2506 region
->label
= NULL_RTX
;
2509 remove_eh_handler (region
);
2516 /* This section describes CFG exception edges for flow. */
2518 /* For communicating between calls to reachable_next_level. */
2519 struct reachable_info
2526 /* A subroutine of reachable_next_level. Return true if TYPE, or a
2527 base class of TYPE, is in HANDLED. */
2530 check_handled (handled
, type
)
2535 /* We can check for exact matches without front-end help. */
2536 if (! lang_eh_type_covers
)
2538 for (t
= handled
; t
; t
= TREE_CHAIN (t
))
2539 if (TREE_VALUE (t
) == type
)
2544 for (t
= handled
; t
; t
= TREE_CHAIN (t
))
2545 if ((*lang_eh_type_covers
) (TREE_VALUE (t
), type
))
2552 /* A subroutine of reachable_next_level. If we are collecting a list
2553 of handlers, add one. After landing pad generation, reference
2554 it instead of the handlers themselves. Further, the handlers are
2555 all wired together, so by referencing one, we've got them all.
2556 Before landing pad generation we reference each handler individually.
2558 LP_REGION contains the landing pad; REGION is the handler. */
2561 add_reachable_handler (info
, lp_region
, region
)
2562 struct reachable_info
*info
;
2563 struct eh_region
*lp_region
;
2564 struct eh_region
*region
;
2569 if (cfun
->eh
->built_landing_pads
)
2571 if (! info
->handlers
)
2572 info
->handlers
= alloc_INSN_LIST (lp_region
->landing_pad
, NULL_RTX
);
2575 info
->handlers
= alloc_INSN_LIST (region
->label
, info
->handlers
);
2578 /* Process one level of exception regions for reachability.
2579 If TYPE_THROWN is non-null, then it is the *exact* type being
2580 propagated. If INFO is non-null, then collect handler labels
2581 and caught/allowed type information between invocations. */
2583 static enum reachable_code
2584 reachable_next_level (region
, type_thrown
, info
)
2585 struct eh_region
*region
;
2587 struct reachable_info
*info
;
2589 switch (region
->type
)
2592 /* Before landing-pad generation, we model control flow
2593 directly to the individual handlers. In this way we can
2594 see that catch handler types may shadow one another. */
2595 add_reachable_handler (info
, region
, region
);
2596 return RNL_MAYBE_CAUGHT
;
2600 struct eh_region
*c
;
2601 enum reachable_code ret
= RNL_NOT_CAUGHT
;
2603 for (c
= region
->u
.try.catch; c
; c
= c
->u
.catch.next_catch
)
2605 /* A catch-all handler ends the search. */
2606 /* ??? _Unwind_ForcedUnwind will want outer cleanups
2607 to be run as well. */
2608 if (c
->u
.catch.type
== NULL
)
2610 add_reachable_handler (info
, region
, c
);
2616 /* If we have a type match, end the search. */
2617 if (c
->u
.catch.type
== type_thrown
2618 || (lang_eh_type_covers
2619 && (*lang_eh_type_covers
) (c
->u
.catch.type
,
2622 add_reachable_handler (info
, region
, c
);
2626 /* If we have definitive information of a match failure,
2627 the catch won't trigger. */
2628 if (lang_eh_type_covers
)
2629 return RNL_NOT_CAUGHT
;
2633 ret
= RNL_MAYBE_CAUGHT
;
2635 /* A type must not have been previously caught. */
2636 else if (! check_handled (info
->types_caught
, c
->u
.catch.type
))
2638 add_reachable_handler (info
, region
, c
);
2639 info
->types_caught
= tree_cons (NULL
, c
->u
.catch.type
,
2640 info
->types_caught
);
2642 /* ??? If the catch type is a base class of every allowed
2643 type, then we know we can stop the search. */
2644 ret
= RNL_MAYBE_CAUGHT
;
2651 case ERT_ALLOWED_EXCEPTIONS
:
2652 /* An empty list of types definitely ends the search. */
2653 if (region
->u
.allowed
.type_list
== NULL_TREE
)
2655 add_reachable_handler (info
, region
, region
);
2659 /* Collect a list of lists of allowed types for use in detecting
2660 when a catch may be transformed into a catch-all. */
2662 info
->types_allowed
= tree_cons (NULL_TREE
,
2663 region
->u
.allowed
.type_list
,
2664 info
->types_allowed
);
2666 /* If we have definitive information about the type heirarchy,
2667 then we can tell if the thrown type will pass through the
2669 if (type_thrown
&& lang_eh_type_covers
)
2671 if (check_handled (region
->u
.allowed
.type_list
, type_thrown
))
2672 return RNL_NOT_CAUGHT
;
2675 add_reachable_handler (info
, region
, region
);
2680 add_reachable_handler (info
, region
, region
);
2681 return RNL_MAYBE_CAUGHT
;
2684 /* Catch regions are handled by their controling try region. */
2685 return RNL_NOT_CAUGHT
;
2687 case ERT_MUST_NOT_THROW
:
2688 /* Here we end our search, since no exceptions may propagate.
2689 If we've touched down at some landing pad previous, then the
2690 explicit function call we generated may be used. Otherwise
2691 the call is made by the runtime. */
2692 if (info
&& info
->handlers
)
2694 add_reachable_handler (info
, region
, region
);
2702 /* Shouldn't see these here. */
2709 /* Retrieve a list of labels of exception handlers which can be
2710 reached by a given insn. */
2713 reachable_handlers (insn
)
2716 struct reachable_info info
;
2717 struct eh_region
*region
;
2721 if (GET_CODE (insn
) == JUMP_INSN
2722 && GET_CODE (PATTERN (insn
)) == RESX
)
2723 region_number
= XINT (PATTERN (insn
), 0);
2726 rtx note
= find_reg_note (insn
, REG_EH_REGION
, NULL_RTX
);
2727 if (!note
|| INTVAL (XEXP (note
, 0)) <= 0)
2729 region_number
= INTVAL (XEXP (note
, 0));
2732 memset (&info
, 0, sizeof (info
));
2734 region
= cfun
->eh
->region_array
[region_number
];
2736 type_thrown
= NULL_TREE
;
2737 if (region
->type
== ERT_THROW
)
2739 type_thrown
= region
->u
.throw.type
;
2740 region
= region
->outer
;
2742 else if (GET_CODE (insn
) == JUMP_INSN
2743 && GET_CODE (PATTERN (insn
)) == RESX
)
2744 region
= region
->outer
;
2746 for (; region
; region
= region
->outer
)
2747 if (reachable_next_level (region
, type_thrown
, &info
) >= RNL_CAUGHT
)
2750 return info
.handlers
;
2753 /* Determine if the given INSN can throw an exception that is caught
2754 within the function. */
2757 can_throw_internal (insn
)
2760 struct eh_region
*region
;
2764 if (! INSN_P (insn
))
2767 if (GET_CODE (insn
) == INSN
2768 && GET_CODE (PATTERN (insn
)) == SEQUENCE
)
2769 insn
= XVECEXP (PATTERN (insn
), 0, 0);
2771 if (GET_CODE (insn
) == CALL_INSN
2772 && GET_CODE (PATTERN (insn
)) == CALL_PLACEHOLDER
)
2775 for (i
= 0; i
< 3; ++i
)
2777 rtx sub
= XEXP (PATTERN (insn
), i
);
2778 for (; sub
; sub
= NEXT_INSN (sub
))
2779 if (can_throw_internal (sub
))
2785 /* Every insn that might throw has an EH_REGION note. */
2786 note
= find_reg_note (insn
, REG_EH_REGION
, NULL_RTX
);
2787 if (!note
|| INTVAL (XEXP (note
, 0)) <= 0)
2790 region
= cfun
->eh
->region_array
[INTVAL (XEXP (note
, 0))];
2792 type_thrown
= NULL_TREE
;
2793 if (region
->type
== ERT_THROW
)
2795 type_thrown
= region
->u
.throw.type
;
2796 region
= region
->outer
;
2799 /* If this exception is ignored by each and every containing region,
2800 then control passes straight out. The runtime may handle some
2801 regions, which also do not require processing internally. */
2802 for (; region
; region
= region
->outer
)
2804 enum reachable_code how
= reachable_next_level (region
, type_thrown
, 0);
2805 if (how
== RNL_BLOCKED
)
2807 if (how
!= RNL_NOT_CAUGHT
)
2814 /* Determine if the given INSN can throw an exception that is
2815 visible outside the function. */
2818 can_throw_external (insn
)
2821 struct eh_region
*region
;
2825 if (! INSN_P (insn
))
2828 if (GET_CODE (insn
) == INSN
2829 && GET_CODE (PATTERN (insn
)) == SEQUENCE
)
2830 insn
= XVECEXP (PATTERN (insn
), 0, 0);
2832 if (GET_CODE (insn
) == CALL_INSN
2833 && GET_CODE (PATTERN (insn
)) == CALL_PLACEHOLDER
)
2836 for (i
= 0; i
< 3; ++i
)
2838 rtx sub
= XEXP (PATTERN (insn
), i
);
2839 for (; sub
; sub
= NEXT_INSN (sub
))
2840 if (can_throw_external (sub
))
2846 note
= find_reg_note (insn
, REG_EH_REGION
, NULL_RTX
);
2849 /* Calls (and trapping insns) without notes are outside any
2850 exception handling region in this function. We have to
2851 assume it might throw. Given that the front end and middle
2852 ends mark known NOTHROW functions, this isn't so wildly
2854 return (GET_CODE (insn
) == CALL_INSN
2855 || (flag_non_call_exceptions
2856 && may_trap_p (PATTERN (insn
))));
2858 if (INTVAL (XEXP (note
, 0)) <= 0)
2861 region
= cfun
->eh
->region_array
[INTVAL (XEXP (note
, 0))];
2863 type_thrown
= NULL_TREE
;
2864 if (region
->type
== ERT_THROW
)
2866 type_thrown
= region
->u
.throw.type
;
2867 region
= region
->outer
;
2870 /* If the exception is caught or blocked by any containing region,
2871 then it is not seen by any calling function. */
2872 for (; region
; region
= region
->outer
)
2873 if (reachable_next_level (region
, type_thrown
, NULL
) >= RNL_CAUGHT
)
2879 /* True if nothing in this function can throw outside this function. */
2882 nothrow_function_p ()
2886 if (! flag_exceptions
)
2889 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
2890 if (can_throw_external (insn
))
2892 for (insn
= current_function_epilogue_delay_list
; insn
;
2893 insn
= XEXP (insn
, 1))
2894 if (can_throw_external (insn
))
2901 /* Various hooks for unwind library. */
2903 /* Do any necessary initialization to access arbitrary stack frames.
2904 On the SPARC, this means flushing the register windows. */
2907 expand_builtin_unwind_init ()
2909 /* Set this so all the registers get saved in our frame; we need to be
2910 able to copy the saved values for any registers from frames we unwind. */
2911 current_function_has_nonlocal_label
= 1;
2913 #ifdef SETUP_FRAME_ADDRESSES
2914 SETUP_FRAME_ADDRESSES ();
2919 expand_builtin_eh_return_data_regno (arglist
)
2922 tree which
= TREE_VALUE (arglist
);
2923 unsigned HOST_WIDE_INT iwhich
;
2925 if (TREE_CODE (which
) != INTEGER_CST
)
2927 error ("argument of `__builtin_eh_return_regno' must be constant");
2931 iwhich
= tree_low_cst (which
, 1);
2932 iwhich
= EH_RETURN_DATA_REGNO (iwhich
);
2933 if (iwhich
== INVALID_REGNUM
)
2936 #ifdef DWARF_FRAME_REGNUM
2937 iwhich
= DWARF_FRAME_REGNUM (iwhich
);
2939 iwhich
= DBX_REGISTER_NUMBER (iwhich
);
2942 return GEN_INT (iwhich
);
2945 /* Given a value extracted from the return address register or stack slot,
2946 return the actual address encoded in that value. */
2949 expand_builtin_extract_return_addr (addr_tree
)
2952 rtx addr
= expand_expr (addr_tree
, NULL_RTX
, Pmode
, 0);
2954 /* First mask out any unwanted bits. */
2955 #ifdef MASK_RETURN_ADDR
2956 expand_and (addr
, MASK_RETURN_ADDR
, addr
);
2959 /* Then adjust to find the real return address. */
2960 #if defined (RETURN_ADDR_OFFSET)
2961 addr
= plus_constant (addr
, RETURN_ADDR_OFFSET
);
2967 /* Given an actual address in addr_tree, do any necessary encoding
2968 and return the value to be stored in the return address register or
2969 stack slot so the epilogue will return to that address. */
2972 expand_builtin_frob_return_addr (addr_tree
)
2975 rtx addr
= expand_expr (addr_tree
, NULL_RTX
, Pmode
, 0);
2977 #ifdef POINTERS_EXTEND_UNSIGNED
2978 addr
= convert_memory_address (Pmode
, addr
);
2981 #ifdef RETURN_ADDR_OFFSET
2982 addr
= force_reg (Pmode
, addr
);
2983 addr
= plus_constant (addr
, -RETURN_ADDR_OFFSET
);
2989 /* Set up the epilogue with the magic bits we'll need to return to the
2990 exception handler. */
2993 expand_builtin_eh_return (stackadj_tree
, handler_tree
)
2994 tree stackadj_tree
, handler_tree
;
2996 rtx stackadj
, handler
;
2998 stackadj
= expand_expr (stackadj_tree
, cfun
->eh
->ehr_stackadj
, VOIDmode
, 0);
2999 handler
= expand_expr (handler_tree
, cfun
->eh
->ehr_handler
, VOIDmode
, 0);
3001 #ifdef POINTERS_EXTEND_UNSIGNED
3002 stackadj
= convert_memory_address (Pmode
, stackadj
);
3003 handler
= convert_memory_address (Pmode
, handler
);
3006 if (! cfun
->eh
->ehr_label
)
3008 cfun
->eh
->ehr_stackadj
= copy_to_reg (stackadj
);
3009 cfun
->eh
->ehr_handler
= copy_to_reg (handler
);
3010 cfun
->eh
->ehr_label
= gen_label_rtx ();
3014 if (stackadj
!= cfun
->eh
->ehr_stackadj
)
3015 emit_move_insn (cfun
->eh
->ehr_stackadj
, stackadj
);
3016 if (handler
!= cfun
->eh
->ehr_handler
)
3017 emit_move_insn (cfun
->eh
->ehr_handler
, handler
);
3020 emit_jump (cfun
->eh
->ehr_label
);
3026 rtx sa
, ra
, around_label
;
3028 if (! cfun
->eh
->ehr_label
)
3031 sa
= EH_RETURN_STACKADJ_RTX
;
3034 error ("__builtin_eh_return not supported on this target");
3038 current_function_calls_eh_return
= 1;
3040 around_label
= gen_label_rtx ();
3041 emit_move_insn (sa
, const0_rtx
);
3042 emit_jump (around_label
);
3044 emit_label (cfun
->eh
->ehr_label
);
3045 clobber_return_register ();
3047 #ifdef HAVE_eh_return
3049 emit_insn (gen_eh_return (cfun
->eh
->ehr_stackadj
, cfun
->eh
->ehr_handler
));
3053 ra
= EH_RETURN_HANDLER_RTX
;
3056 error ("__builtin_eh_return not supported on this target");
3057 ra
= gen_reg_rtx (Pmode
);
3060 emit_move_insn (sa
, cfun
->eh
->ehr_stackadj
);
3061 emit_move_insn (ra
, cfun
->eh
->ehr_handler
);
3064 emit_label (around_label
);
3067 struct action_record
3075 action_record_eq (pentry
, pdata
)
3079 const struct action_record
*entry
= (const struct action_record
*) pentry
;
3080 const struct action_record
*data
= (const struct action_record
*) pdata
;
3081 return entry
->filter
== data
->filter
&& entry
->next
== data
->next
;
3085 action_record_hash (pentry
)
3088 const struct action_record
*entry
= (const struct action_record
*) pentry
;
3089 return entry
->next
* 1009 + entry
->filter
;
3093 add_action_record (ar_hash
, filter
, next
)
3097 struct action_record
**slot
, *new, tmp
;
3099 tmp
.filter
= filter
;
3101 slot
= (struct action_record
**) htab_find_slot (ar_hash
, &tmp
, INSERT
);
3103 if ((new = *slot
) == NULL
)
3105 new = (struct action_record
*) xmalloc (sizeof (*new));
3106 new->offset
= VARRAY_ACTIVE_SIZE (cfun
->eh
->action_record_data
) + 1;
3107 new->filter
= filter
;
3111 /* The filter value goes in untouched. The link to the next
3112 record is a "self-relative" byte offset, or zero to indicate
3113 that there is no next record. So convert the absolute 1 based
3114 indicies we've been carrying around into a displacement. */
3116 push_sleb128 (&cfun
->eh
->action_record_data
, filter
);
3118 next
-= VARRAY_ACTIVE_SIZE (cfun
->eh
->action_record_data
) + 1;
3119 push_sleb128 (&cfun
->eh
->action_record_data
, next
);
3126 collect_one_action_chain (ar_hash
, region
)
3128 struct eh_region
*region
;
3130 struct eh_region
*c
;
3133 /* If we've reached the top of the region chain, then we have
3134 no actions, and require no landing pad. */
3138 switch (region
->type
)
3141 /* A cleanup adds a zero filter to the beginning of the chain, but
3142 there are special cases to look out for. If there are *only*
3143 cleanups along a path, then it compresses to a zero action.
3144 Further, if there are multiple cleanups along a path, we only
3145 need to represent one of them, as that is enough to trigger
3146 entry to the landing pad at runtime. */
3147 next
= collect_one_action_chain (ar_hash
, region
->outer
);
3150 for (c
= region
->outer
; c
; c
= c
->outer
)
3151 if (c
->type
== ERT_CLEANUP
)
3153 return add_action_record (ar_hash
, 0, next
);
3156 /* Process the associated catch regions in reverse order.
3157 If there's a catch-all handler, then we don't need to
3158 search outer regions. Use a magic -3 value to record
3159 that we havn't done the outer search. */
3161 for (c
= region
->u
.try.last_catch
; c
; c
= c
->u
.catch.prev_catch
)
3163 if (c
->u
.catch.type
== NULL
)
3164 next
= add_action_record (ar_hash
, c
->u
.catch.filter
, 0);
3169 next
= collect_one_action_chain (ar_hash
, region
->outer
);
3173 next
= add_action_record (ar_hash
, c
->u
.catch.filter
, next
);
3178 case ERT_ALLOWED_EXCEPTIONS
:
3179 /* An exception specification adds its filter to the
3180 beginning of the chain. */
3181 next
= collect_one_action_chain (ar_hash
, region
->outer
);
3182 return add_action_record (ar_hash
, region
->u
.allowed
.filter
,
3183 next
< 0 ? 0 : next
);
3185 case ERT_MUST_NOT_THROW
:
3186 /* A must-not-throw region with no inner handlers or cleanups
3187 requires no call-site entry. Note that this differs from
3188 the no handler or cleanup case in that we do require an lsda
3189 to be generated. Return a magic -2 value to record this. */
3194 /* CATCH regions are handled in TRY above. THROW regions are
3195 for optimization information only and produce no output. */
3196 return collect_one_action_chain (ar_hash
, region
->outer
);
3204 add_call_site (landing_pad
, action
)
3208 struct call_site_record
*data
= cfun
->eh
->call_site_data
;
3209 int used
= cfun
->eh
->call_site_data_used
;
3210 int size
= cfun
->eh
->call_site_data_size
;
3214 size
= (size
? size
* 2 : 64);
3215 data
= (struct call_site_record
*)
3216 xrealloc (data
, sizeof (*data
) * size
);
3217 cfun
->eh
->call_site_data
= data
;
3218 cfun
->eh
->call_site_data_size
= size
;
3221 data
[used
].landing_pad
= landing_pad
;
3222 data
[used
].action
= action
;
3224 cfun
->eh
->call_site_data_used
= used
+ 1;
3226 return used
+ call_site_base
;
3229 /* Turn REG_EH_REGION notes back into NOTE_INSN_EH_REGION notes.
3230 The new note numbers will not refer to region numbers, but
3231 instead to call site entries. */
3234 convert_to_eh_region_ranges ()
3236 rtx insn
, iter
, note
;
3238 int last_action
= -3;
3239 rtx last_action_insn
= NULL_RTX
;
3240 rtx last_landing_pad
= NULL_RTX
;
3241 rtx first_no_action_insn
= NULL_RTX
;
3244 if (USING_SJLJ_EXCEPTIONS
|| cfun
->eh
->region_tree
== NULL
)
3247 VARRAY_UCHAR_INIT (cfun
->eh
->action_record_data
, 64, "action_record_data");
3249 ar_hash
= htab_create (31, action_record_hash
, action_record_eq
, free
);
3251 for (iter
= get_insns (); iter
; iter
= NEXT_INSN (iter
))
3254 struct eh_region
*region
;
3256 rtx this_landing_pad
;
3259 if (GET_CODE (insn
) == INSN
3260 && GET_CODE (PATTERN (insn
)) == SEQUENCE
)
3261 insn
= XVECEXP (PATTERN (insn
), 0, 0);
3263 note
= find_reg_note (insn
, REG_EH_REGION
, NULL_RTX
);
3266 if (! (GET_CODE (insn
) == CALL_INSN
3267 || (flag_non_call_exceptions
3268 && may_trap_p (PATTERN (insn
)))))
3275 if (INTVAL (XEXP (note
, 0)) <= 0)
3277 region
= cfun
->eh
->region_array
[INTVAL (XEXP (note
, 0))];
3278 this_action
= collect_one_action_chain (ar_hash
, region
);
3281 /* Existence of catch handlers, or must-not-throw regions
3282 implies that an lsda is needed (even if empty). */
3283 if (this_action
!= -1)
3284 cfun
->uses_eh_lsda
= 1;
3286 /* Delay creation of region notes for no-action regions
3287 until we're sure that an lsda will be required. */
3288 else if (last_action
== -3)
3290 first_no_action_insn
= iter
;
3294 /* Cleanups and handlers may share action chains but not
3295 landing pads. Collect the landing pad for this region. */
3296 if (this_action
>= 0)
3298 struct eh_region
*o
;
3299 for (o
= region
; ! o
->landing_pad
; o
= o
->outer
)
3301 this_landing_pad
= o
->landing_pad
;
3304 this_landing_pad
= NULL_RTX
;
3306 /* Differing actions or landing pads implies a change in call-site
3307 info, which implies some EH_REGION note should be emitted. */
3308 if (last_action
!= this_action
3309 || last_landing_pad
!= this_landing_pad
)
3311 /* If we'd not seen a previous action (-3) or the previous
3312 action was must-not-throw (-2), then we do not need an
3314 if (last_action
>= -1)
3316 /* If we delayed the creation of the begin, do it now. */
3317 if (first_no_action_insn
)
3319 call_site
= add_call_site (NULL_RTX
, 0);
3320 note
= emit_note_before (NOTE_INSN_EH_REGION_BEG
,
3321 first_no_action_insn
);
3322 NOTE_EH_HANDLER (note
) = call_site
;
3323 first_no_action_insn
= NULL_RTX
;
3326 note
= emit_note_after (NOTE_INSN_EH_REGION_END
,
3328 NOTE_EH_HANDLER (note
) = call_site
;
3331 /* If the new action is must-not-throw, then no region notes
3333 if (this_action
>= -1)
3335 call_site
= add_call_site (this_landing_pad
,
3336 this_action
< 0 ? 0 : this_action
);
3337 note
= emit_note_before (NOTE_INSN_EH_REGION_BEG
, iter
);
3338 NOTE_EH_HANDLER (note
) = call_site
;
3341 last_action
= this_action
;
3342 last_landing_pad
= this_landing_pad
;
3344 last_action_insn
= iter
;
3347 if (last_action
>= -1 && ! first_no_action_insn
)
3349 note
= emit_note_after (NOTE_INSN_EH_REGION_END
, last_action_insn
);
3350 NOTE_EH_HANDLER (note
) = call_site
;
3353 htab_delete (ar_hash
);
3358 push_uleb128 (data_area
, value
)
3359 varray_type
*data_area
;
3364 unsigned char byte
= value
& 0x7f;
3368 VARRAY_PUSH_UCHAR (*data_area
, byte
);
3374 push_sleb128 (data_area
, value
)
3375 varray_type
*data_area
;
3383 byte
= value
& 0x7f;
3385 more
= ! ((value
== 0 && (byte
& 0x40) == 0)
3386 || (value
== -1 && (byte
& 0x40) != 0));
3389 VARRAY_PUSH_UCHAR (*data_area
, byte
);
3395 #ifndef HAVE_AS_LEB128
3397 dw2_size_of_call_site_table ()
3399 int n
= cfun
->eh
->call_site_data_used
;
3400 int size
= n
* (4 + 4 + 4);
3403 for (i
= 0; i
< n
; ++i
)
3405 struct call_site_record
*cs
= &cfun
->eh
->call_site_data
[i
];
3406 size
+= size_of_uleb128 (cs
->action
);
3413 sjlj_size_of_call_site_table ()
3415 int n
= cfun
->eh
->call_site_data_used
;
3419 for (i
= 0; i
< n
; ++i
)
3421 struct call_site_record
*cs
= &cfun
->eh
->call_site_data
[i
];
3422 size
+= size_of_uleb128 (INTVAL (cs
->landing_pad
));
3423 size
+= size_of_uleb128 (cs
->action
);
3431 dw2_output_call_site_table ()
3433 const char *function_start_lab
3434 = IDENTIFIER_POINTER (current_function_func_begin_label
);
3435 int n
= cfun
->eh
->call_site_data_used
;
3438 for (i
= 0; i
< n
; ++i
)
3440 struct call_site_record
*cs
= &cfun
->eh
->call_site_data
[i
];
3441 char reg_start_lab
[32];
3442 char reg_end_lab
[32];
3443 char landing_pad_lab
[32];
3445 ASM_GENERATE_INTERNAL_LABEL (reg_start_lab
, "LEHB", call_site_base
+ i
);
3446 ASM_GENERATE_INTERNAL_LABEL (reg_end_lab
, "LEHE", call_site_base
+ i
);
3448 if (cs
->landing_pad
)
3449 ASM_GENERATE_INTERNAL_LABEL (landing_pad_lab
, "L",
3450 CODE_LABEL_NUMBER (cs
->landing_pad
));
3452 /* ??? Perhaps use insn length scaling if the assembler supports
3453 generic arithmetic. */
3454 /* ??? Perhaps use attr_length to choose data1 or data2 instead of
3455 data4 if the function is small enough. */
3456 #ifdef HAVE_AS_LEB128
3457 dw2_asm_output_delta_uleb128 (reg_start_lab
, function_start_lab
,
3458 "region %d start", i
);
3459 dw2_asm_output_delta_uleb128 (reg_end_lab
, reg_start_lab
,
3461 if (cs
->landing_pad
)
3462 dw2_asm_output_delta_uleb128 (landing_pad_lab
, function_start_lab
,
3465 dw2_asm_output_data_uleb128 (0, "landing pad");
3467 dw2_asm_output_delta (4, reg_start_lab
, function_start_lab
,
3468 "region %d start", i
);
3469 dw2_asm_output_delta (4, reg_end_lab
, reg_start_lab
, "length");
3470 if (cs
->landing_pad
)
3471 dw2_asm_output_delta (4, landing_pad_lab
, function_start_lab
,
3474 dw2_asm_output_data (4, 0, "landing pad");
3476 dw2_asm_output_data_uleb128 (cs
->action
, "action");
3479 call_site_base
+= n
;
3483 sjlj_output_call_site_table ()
3485 int n
= cfun
->eh
->call_site_data_used
;
3488 for (i
= 0; i
< n
; ++i
)
3490 struct call_site_record
*cs
= &cfun
->eh
->call_site_data
[i
];
3492 dw2_asm_output_data_uleb128 (INTVAL (cs
->landing_pad
),
3493 "region %d landing pad", i
);
3494 dw2_asm_output_data_uleb128 (cs
->action
, "action");
3497 call_site_base
+= n
;
3501 output_function_exception_table ()
3503 int tt_format
, cs_format
, lp_format
, i
, n
;
3504 #ifdef HAVE_AS_LEB128
3505 char ttype_label
[32];
3506 char cs_after_size_label
[32];
3507 char cs_end_label
[32];
3515 /* Not all functions need anything. */
3516 if (! cfun
->uses_eh_lsda
)
3519 funcdef_number
= (USING_SJLJ_EXCEPTIONS
3520 ? sjlj_funcdef_number
3521 : current_funcdef_number
);
3523 #ifdef IA64_UNWIND_INFO
3524 fputs ("\t.personality\t", asm_out_file
);
3525 output_addr_const (asm_out_file
, eh_personality_libfunc
);
3526 fputs ("\n\t.handlerdata\n", asm_out_file
);
3527 /* Note that varasm still thinks we're in the function's code section.
3528 The ".endp" directive that will immediately follow will take us back. */
3530 exception_section ();
3533 have_tt_data
= (VARRAY_ACTIVE_SIZE (cfun
->eh
->ttype_data
) > 0
3534 || VARRAY_ACTIVE_SIZE (cfun
->eh
->ehspec_data
) > 0);
3536 /* Indicate the format of the @TType entries. */
3538 tt_format
= DW_EH_PE_omit
;
3541 tt_format
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/1);
3542 #ifdef HAVE_AS_LEB128
3543 ASM_GENERATE_INTERNAL_LABEL (ttype_label
, "LLSDATT", funcdef_number
);
3545 tt_format_size
= size_of_encoded_value (tt_format
);
3547 assemble_eh_align (tt_format_size
* BITS_PER_UNIT
);
3550 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LLSDA", funcdef_number
);
3552 /* The LSDA header. */
3554 /* Indicate the format of the landing pad start pointer. An omitted
3555 field implies @LPStart == @Start. */
3556 /* Currently we always put @LPStart == @Start. This field would
3557 be most useful in moving the landing pads completely out of
3558 line to another section, but it could also be used to minimize
3559 the size of uleb128 landing pad offsets. */
3560 lp_format
= DW_EH_PE_omit
;
3561 dw2_asm_output_data (1, lp_format
, "@LPStart format (%s)",
3562 eh_data_format_name (lp_format
));
3564 /* @LPStart pointer would go here. */
3566 dw2_asm_output_data (1, tt_format
, "@TType format (%s)",
3567 eh_data_format_name (tt_format
));
3569 #ifndef HAVE_AS_LEB128
3570 if (USING_SJLJ_EXCEPTIONS
)
3571 call_site_len
= sjlj_size_of_call_site_table ();
3573 call_site_len
= dw2_size_of_call_site_table ();
3576 /* A pc-relative 4-byte displacement to the @TType data. */
3579 #ifdef HAVE_AS_LEB128
3580 char ttype_after_disp_label
[32];
3581 ASM_GENERATE_INTERNAL_LABEL (ttype_after_disp_label
, "LLSDATTD",
3583 dw2_asm_output_delta_uleb128 (ttype_label
, ttype_after_disp_label
,
3584 "@TType base offset");
3585 ASM_OUTPUT_LABEL (asm_out_file
, ttype_after_disp_label
);
3587 /* Ug. Alignment queers things. */
3588 unsigned int before_disp
, after_disp
, last_disp
, disp
;
3590 before_disp
= 1 + 1;
3591 after_disp
= (1 + size_of_uleb128 (call_site_len
)
3593 + VARRAY_ACTIVE_SIZE (cfun
->eh
->action_record_data
)
3594 + (VARRAY_ACTIVE_SIZE (cfun
->eh
->ttype_data
)
3600 unsigned int disp_size
, pad
;
3603 disp_size
= size_of_uleb128 (disp
);
3604 pad
= before_disp
+ disp_size
+ after_disp
;
3605 if (pad
% tt_format_size
)
3606 pad
= tt_format_size
- (pad
% tt_format_size
);
3609 disp
= after_disp
+ pad
;
3611 while (disp
!= last_disp
);
3613 dw2_asm_output_data_uleb128 (disp
, "@TType base offset");
3617 /* Indicate the format of the call-site offsets. */
3618 #ifdef HAVE_AS_LEB128
3619 cs_format
= DW_EH_PE_uleb128
;
3621 cs_format
= DW_EH_PE_udata4
;
3623 dw2_asm_output_data (1, cs_format
, "call-site format (%s)",
3624 eh_data_format_name (cs_format
));
3626 #ifdef HAVE_AS_LEB128
3627 ASM_GENERATE_INTERNAL_LABEL (cs_after_size_label
, "LLSDACSB",
3629 ASM_GENERATE_INTERNAL_LABEL (cs_end_label
, "LLSDACSE",
3631 dw2_asm_output_delta_uleb128 (cs_end_label
, cs_after_size_label
,
3632 "Call-site table length");
3633 ASM_OUTPUT_LABEL (asm_out_file
, cs_after_size_label
);
3634 if (USING_SJLJ_EXCEPTIONS
)
3635 sjlj_output_call_site_table ();
3637 dw2_output_call_site_table ();
3638 ASM_OUTPUT_LABEL (asm_out_file
, cs_end_label
);
3640 dw2_asm_output_data_uleb128 (call_site_len
,"Call-site table length");
3641 if (USING_SJLJ_EXCEPTIONS
)
3642 sjlj_output_call_site_table ();
3644 dw2_output_call_site_table ();
3647 /* ??? Decode and interpret the data for flag_debug_asm. */
3648 n
= VARRAY_ACTIVE_SIZE (cfun
->eh
->action_record_data
);
3649 for (i
= 0; i
< n
; ++i
)
3650 dw2_asm_output_data (1, VARRAY_UCHAR (cfun
->eh
->action_record_data
, i
),
3651 (i
? NULL
: "Action record table"));
3654 assemble_eh_align (tt_format_size
* BITS_PER_UNIT
);
3656 i
= VARRAY_ACTIVE_SIZE (cfun
->eh
->ttype_data
);
3659 tree type
= VARRAY_TREE (cfun
->eh
->ttype_data
, i
);
3661 if (type
== NULL_TREE
)
3662 type
= integer_zero_node
;
3664 type
= lookup_type_for_runtime (type
);
3666 dw2_asm_output_encoded_addr_rtx (tt_format
,
3667 expand_expr (type
, NULL_RTX
, VOIDmode
,
3668 EXPAND_INITIALIZER
),
3672 #ifdef HAVE_AS_LEB128
3674 ASM_OUTPUT_LABEL (asm_out_file
, ttype_label
);
3677 /* ??? Decode and interpret the data for flag_debug_asm. */
3678 n
= VARRAY_ACTIVE_SIZE (cfun
->eh
->ehspec_data
);
3679 for (i
= 0; i
< n
; ++i
)
3680 dw2_asm_output_data (1, VARRAY_UCHAR (cfun
->eh
->ehspec_data
, i
),
3681 (i
? NULL
: "Exception specification table"));
3683 function_section (current_function_decl
);
3685 if (USING_SJLJ_EXCEPTIONS
)
3686 sjlj_funcdef_number
+= 1;