Line data Source code
1 : /* Implements exception handling.
2 : Copyright (C) 1989-2026 Free Software Foundation, Inc.
3 : Contributed by Mike Stump <mrs@cygnus.com>.
4 :
5 : This file is part of GCC.
6 :
7 : GCC is free software; you can redistribute it and/or modify it under
8 : the terms of the GNU General Public License as published by the Free
9 : Software Foundation; either version 3, or (at your option) any later
10 : version.
11 :
12 : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 : WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 : for more details.
16 :
17 : You should have received a copy of the GNU General Public License
18 : along with GCC; see the file COPYING3. If not see
19 : <http://www.gnu.org/licenses/>. */
20 :
21 :
22 : /* An exception is an event that can be "thrown" from within a
23 : function. This event can then be "caught" by the callers of
24 : the function.
25 :
26 : The representation of exceptions changes several times during
27 : the compilation process:
28 :
29 : In the beginning, in the front end, we have the GENERIC trees
30 : TRY_CATCH_EXPR, TRY_FINALLY_EXPR, EH_ELSE_EXPR, WITH_CLEANUP_EXPR,
31 : CLEANUP_POINT_EXPR, CATCH_EXPR, and EH_FILTER_EXPR.
32 :
33 : During initial gimplification (gimplify.cc) these are lowered to the
34 : GIMPLE_TRY, GIMPLE_CATCH, GIMPLE_EH_ELSE, and GIMPLE_EH_FILTER
35 : nodes. The WITH_CLEANUP_EXPR and CLEANUP_POINT_EXPR nodes are
36 : converted into GIMPLE_TRY_FINALLY nodes; the others are a more
37 : direct 1-1 conversion.
38 :
39 : During pass_lower_eh (tree-eh.cc) we record the nested structure
40 : of the TRY nodes in EH_REGION nodes in CFUN->EH->REGION_TREE.
41 : We expand the eh_protect_cleanup_actions langhook into MUST_NOT_THROW
42 : regions at this time. We can then flatten the statements within
43 : the TRY nodes to straight-line code. Statements that had been within
44 : TRY nodes that can throw are recorded within CFUN->EH->THROW_STMT_TABLE,
45 : so that we may remember what action is supposed to be taken if
46 : a given statement does throw. During this lowering process,
47 : we create an EH_LANDING_PAD node for each EH_REGION that has
48 : some code within the function that needs to be executed if a
49 : throw does happen. We also create RESX statements that are
50 : used to transfer control from an inner EH_REGION to an outer
51 : EH_REGION. We also create EH_DISPATCH statements as placeholders
52 : for a runtime type comparison that should be made in order to
53 : select the action to perform among different CATCH and EH_FILTER
54 : regions.
55 :
56 : During pass_lower_eh_dispatch (tree-eh.cc), which is run after
57 : all inlining is complete, we are able to run assign_filter_values,
58 : which allows us to map the set of types manipulated by all of the
59 : CATCH and EH_FILTER regions to a set of integers. This set of integers
60 : will be how the exception runtime communicates with the code generated
61 : within the function. We then expand the GIMPLE_EH_DISPATCH statements
62 : to a switch or conditional branches that use the argument provided by
63 : the runtime (__builtin_eh_filter) and the set of integers we computed
64 : in assign_filter_values.
65 :
66 : During pass_lower_resx (tree-eh.cc), which is run near the end
67 : of optimization, we expand RESX statements. If the eh region
68 : that is outer to the RESX statement is a MUST_NOT_THROW, then
69 : the RESX expands to some form of abort statement. If the eh
70 : region that is outer to the RESX statement is within the current
71 : function, then the RESX expands to a bookkeeping call
72 : (__builtin_eh_copy_values) and a goto. Otherwise, the next
73 : handler for the exception must be within a function somewhere
74 : up the call chain, so we call back into the exception runtime
75 : (__builtin_unwind_resume).
76 :
77 : During pass_expand (cfgexpand.cc), we generate REG_EH_REGION notes
78 : that create an rtl to eh_region mapping that corresponds to the
79 : gimple to eh_region mapping that had been recorded in the
80 : THROW_STMT_TABLE.
81 :
82 : Then, via finish_eh_generation, we generate the real landing pads
83 : to which the runtime will actually transfer control. These new
84 : landing pads perform whatever bookkeeping is needed by the target
85 : backend in order to resume execution within the current function.
86 : Each of these new landing pads falls through into the post_landing_pad
87 : label which had been used within the CFG up to this point. All
88 : exception edges within the CFG are redirected to the new landing pads.
89 : If the target uses setjmp to implement exceptions, the various extra
90 : calls into the runtime to register and unregister the current stack
91 : frame are emitted at this time.
92 :
93 : During pass_convert_to_eh_region_ranges (except.cc), we transform
94 : the REG_EH_REGION notes attached to individual insns into
95 : non-overlapping ranges of insns bounded by NOTE_INSN_EH_REGION_BEG
96 : and NOTE_INSN_EH_REGION_END. Each insn within such ranges has the
97 : same associated action within the exception region tree, meaning
98 : that (1) the exception is caught by the same landing pad within the
99 : current function, (2) the exception is blocked by the runtime with
100 : a MUST_NOT_THROW region, or (3) the exception is not handled at all
101 : within the current function.
102 :
103 : Finally, during assembly generation, we call
104 : output_function_exception_table (except.cc) to emit the tables with
105 : which the exception runtime can determine if a given stack frame
106 : handles a given exception, and if so what filter value to provide
107 : to the function when the non-local control transfer is effected.
108 : If the target uses dwarf2 unwinding to implement exceptions, then
109 : output_call_frame_info (dwarf2out.cc) emits the required unwind data. */
110 :
111 :
112 : #include "config.h"
113 : #include "system.h"
114 : #include "coretypes.h"
115 : #include "backend.h"
116 : #include "target.h"
117 : #include "rtl.h"
118 : #include "tree.h"
119 : #include "cfghooks.h"
120 : #include "tree-pass.h"
121 : #include "memmodel.h"
122 : #include "tm_p.h"
123 : #include "stringpool.h"
124 : #include "expmed.h"
125 : #include "optabs.h"
126 : #include "emit-rtl.h"
127 : #include "cgraph.h"
128 : #include "diagnostic.h"
129 : #include "fold-const.h"
130 : #include "stor-layout.h"
131 : #include "explow.h"
132 : #include "stmt.h"
133 : #include "expr.h"
134 : #include "calls.h"
135 : #include "libfuncs.h"
136 : #include "except.h"
137 : #include "output.h"
138 : #include "dwarf2asm.h"
139 : #include "dwarf2.h"
140 : #include "common/common-target.h"
141 : #include "langhooks.h"
142 : #include "cfgrtl.h"
143 : #include "tree-pretty-print.h"
144 : #include "cfgloop.h"
145 : #include "builtins.h"
146 : #include "tree-hash-traits.h"
147 : #include "flags.h"
148 :
149 : static GTY(()) int call_site_base;
150 :
151 : static GTY(()) hash_map<tree_hash, tree> *type_to_runtime_map;
152 :
153 : static GTY(()) tree setjmp_fn;
154 :
155 : /* Describe the SjLj_Function_Context structure. */
156 : static GTY(()) tree sjlj_fc_type_node;
157 : static int sjlj_fc_call_site_ofs;
158 : static int sjlj_fc_data_ofs;
159 : static int sjlj_fc_personality_ofs;
160 : static int sjlj_fc_lsda_ofs;
161 : static int sjlj_fc_jbuf_ofs;
162 :
163 :
164 : struct GTY(()) call_site_record_d
165 : {
166 : rtx landing_pad;
167 : int action;
168 : };
169 :
170 : /* In the following structure and associated functions,
171 : we represent entries in the action table as 1-based indices.
172 : Special cases are:
173 :
174 : 0: null action record, non-null landing pad; implies cleanups
175 : -1: null action record, null landing pad; implies no action
176 : -2: no call-site entry; implies must_not_throw
177 : -3: we have yet to process outer regions
178 :
179 : Further, no special cases apply to the "next" field of the record.
180 : For next, 0 means end of list. */
181 :
182 : struct action_record
183 : {
184 : int offset;
185 : int filter;
186 : int next;
187 : };
188 :
189 : /* Hashtable helpers. */
190 :
191 : struct action_record_hasher : free_ptr_hash <action_record>
192 : {
193 : static inline hashval_t hash (const action_record *);
194 : static inline bool equal (const action_record *, const action_record *);
195 : };
196 :
197 : inline hashval_t
198 749150 : action_record_hasher::hash (const action_record *entry)
199 : {
200 749150 : return entry->next * 1009 + entry->filter;
201 : }
202 :
203 : inline bool
204 393418 : action_record_hasher::equal (const action_record *entry,
205 : const action_record *data)
206 : {
207 393418 : return entry->filter == data->filter && entry->next == data->next;
208 : }
209 :
210 : typedef hash_table<action_record_hasher> action_hash_type;
211 :
212 : static bool get_eh_region_and_lp_from_rtx (const rtx_insn *, eh_region *,
213 : eh_landing_pad *);
214 :
215 : static void dw2_build_landing_pads (void);
216 :
217 : static int collect_one_action_chain (action_hash_type *, eh_region);
218 : static int add_call_site (rtx, int, int);
219 :
220 : static void push_uleb128 (vec<uchar, va_gc> **, unsigned int);
221 : static void push_sleb128 (vec<uchar, va_gc> **, int);
222 : static int dw2_size_of_call_site_table (int);
223 : static int sjlj_size_of_call_site_table (void);
224 : static void dw2_output_call_site_table (int, int);
225 : static void sjlj_output_call_site_table (void);
226 :
227 :
228 : void
229 316904 : init_eh (void)
230 : {
231 316904 : if (! flag_exceptions)
232 : return;
233 :
234 149057 : type_to_runtime_map = hash_map<tree_hash, tree>::create_ggc (31);
235 :
236 : /* Create the SjLj_Function_Context structure. This should match
237 : the definition in unwind-sjlj.c. */
238 149057 : if (targetm_common.except_unwind_info (&global_options) == UI_SJLJ)
239 : {
240 0 : tree f_jbuf, f_per, f_lsda, f_prev, f_cs, f_data, tmp;
241 :
242 0 : sjlj_fc_type_node = lang_hooks.types.make_type (RECORD_TYPE);
243 :
244 0 : f_prev = build_decl (BUILTINS_LOCATION,
245 : FIELD_DECL, get_identifier ("__prev"),
246 : build_pointer_type (sjlj_fc_type_node));
247 0 : DECL_FIELD_CONTEXT (f_prev) = sjlj_fc_type_node;
248 :
249 0 : f_cs = build_decl (BUILTINS_LOCATION,
250 : FIELD_DECL, get_identifier ("__call_site"),
251 : integer_type_node);
252 0 : DECL_FIELD_CONTEXT (f_cs) = sjlj_fc_type_node;
253 :
254 0 : tmp = build_index_type (size_int (4 - 1));
255 0 : tmp = build_array_type (lang_hooks.types.type_for_mode
256 0 : (targetm.unwind_word_mode (), 1),
257 : tmp);
258 0 : f_data = build_decl (BUILTINS_LOCATION,
259 : FIELD_DECL, get_identifier ("__data"), tmp);
260 0 : DECL_FIELD_CONTEXT (f_data) = sjlj_fc_type_node;
261 :
262 0 : f_per = build_decl (BUILTINS_LOCATION,
263 : FIELD_DECL, get_identifier ("__personality"),
264 : ptr_type_node);
265 0 : DECL_FIELD_CONTEXT (f_per) = sjlj_fc_type_node;
266 :
267 0 : f_lsda = build_decl (BUILTINS_LOCATION,
268 : FIELD_DECL, get_identifier ("__lsda"),
269 : ptr_type_node);
270 0 : DECL_FIELD_CONTEXT (f_lsda) = sjlj_fc_type_node;
271 :
272 : #ifdef DONT_USE_BUILTIN_SETJMP
273 : #ifdef JMP_BUF_SIZE
274 : tmp = size_int (JMP_BUF_SIZE - 1);
275 : #else
276 : /* Should be large enough for most systems, if it is not,
277 : JMP_BUF_SIZE should be defined with the proper value. It will
278 : also tend to be larger than necessary for most systems, a more
279 : optimal port will define JMP_BUF_SIZE. */
280 : tmp = size_int (FIRST_PSEUDO_REGISTER + 2 - 1);
281 : #endif
282 : #else
283 : /* Compute a minimally sized jump buffer. We need room to store at
284 : least 3 pointers - stack pointer, frame pointer and return address.
285 : Plus for some targets we need room for an extra pointer - in the
286 : case of MIPS this is the global pointer. This makes a total of four
287 : pointers, but to be safe we actually allocate room for 5.
288 :
289 : If pointers are smaller than words then we allocate enough room for
290 : 5 words, just in case the backend needs this much room. For more
291 : discussion on this issue see:
292 : http://gcc.gnu.org/ml/gcc-patches/2014-05/msg00313.html. */
293 0 : if (POINTER_SIZE > BITS_PER_WORD)
294 0 : tmp = size_int (5 - 1);
295 : else
296 0 : tmp = size_int ((5 * BITS_PER_WORD / POINTER_SIZE) - 1);
297 : #endif
298 :
299 0 : tmp = build_index_type (tmp);
300 0 : tmp = build_array_type (ptr_type_node, tmp);
301 0 : f_jbuf = build_decl (BUILTINS_LOCATION,
302 : FIELD_DECL, get_identifier ("__jbuf"), tmp);
303 : #ifdef DONT_USE_BUILTIN_SETJMP
304 : /* We don't know what the alignment requirements of the
305 : runtime's jmp_buf has. Overestimate. */
306 : SET_DECL_ALIGN (f_jbuf, BIGGEST_ALIGNMENT);
307 : DECL_USER_ALIGN (f_jbuf) = 1;
308 : #endif
309 0 : DECL_FIELD_CONTEXT (f_jbuf) = sjlj_fc_type_node;
310 :
311 0 : TYPE_FIELDS (sjlj_fc_type_node) = f_prev;
312 0 : TREE_CHAIN (f_prev) = f_cs;
313 0 : TREE_CHAIN (f_cs) = f_data;
314 0 : TREE_CHAIN (f_data) = f_per;
315 0 : TREE_CHAIN (f_per) = f_lsda;
316 0 : TREE_CHAIN (f_lsda) = f_jbuf;
317 :
318 0 : layout_type (sjlj_fc_type_node);
319 :
320 : /* Cache the interesting field offsets so that we have
321 : easy access from rtl. */
322 0 : sjlj_fc_call_site_ofs
323 0 : = (tree_to_uhwi (DECL_FIELD_OFFSET (f_cs))
324 0 : + tree_to_uhwi (DECL_FIELD_BIT_OFFSET (f_cs)) / BITS_PER_UNIT);
325 0 : sjlj_fc_data_ofs
326 0 : = (tree_to_uhwi (DECL_FIELD_OFFSET (f_data))
327 0 : + tree_to_uhwi (DECL_FIELD_BIT_OFFSET (f_data)) / BITS_PER_UNIT);
328 0 : sjlj_fc_personality_ofs
329 0 : = (tree_to_uhwi (DECL_FIELD_OFFSET (f_per))
330 0 : + tree_to_uhwi (DECL_FIELD_BIT_OFFSET (f_per)) / BITS_PER_UNIT);
331 0 : sjlj_fc_lsda_ofs
332 0 : = (tree_to_uhwi (DECL_FIELD_OFFSET (f_lsda))
333 0 : + tree_to_uhwi (DECL_FIELD_BIT_OFFSET (f_lsda)) / BITS_PER_UNIT);
334 0 : sjlj_fc_jbuf_ofs
335 0 : = (tree_to_uhwi (DECL_FIELD_OFFSET (f_jbuf))
336 0 : + tree_to_uhwi (DECL_FIELD_BIT_OFFSET (f_jbuf)) / BITS_PER_UNIT);
337 :
338 : #ifdef DONT_USE_BUILTIN_SETJMP
339 : tmp = build_function_type_list (integer_type_node, TREE_TYPE (f_jbuf),
340 : NULL);
341 : setjmp_fn = build_decl (BUILTINS_LOCATION, FUNCTION_DECL,
342 : get_identifier ("setjmp"), tmp);
343 : TREE_PUBLIC (setjmp_fn) = 1;
344 : DECL_EXTERNAL (setjmp_fn) = 1;
345 : DECL_ASSEMBLER_NAME (setjmp_fn);
346 : #endif
347 : }
348 : }
349 :
350 : void
351 206358537 : init_eh_for_function (void)
352 : {
353 206358537 : cfun->eh = ggc_cleared_alloc<eh_status> ();
354 :
355 : /* Make sure zero'th entries are used. */
356 206358537 : vec_safe_push (cfun->eh->region_array, (eh_region)0);
357 206358537 : vec_safe_push (cfun->eh->lp_array, (eh_landing_pad)0);
358 206358537 : }
359 :
360 : /* Routines to generate the exception tree somewhat directly.
361 : These are used from tree-eh.cc when processing exception related
362 : nodes during tree optimization. */
363 :
364 : static eh_region
365 2949869 : gen_eh_region (enum eh_region_type type, eh_region outer)
366 : {
367 2949869 : eh_region new_eh;
368 :
369 : /* Insert a new blank region as a leaf in the tree. */
370 2949869 : new_eh = ggc_cleared_alloc<eh_region_d> ();
371 2949869 : new_eh->type = type;
372 2949869 : new_eh->outer = outer;
373 2949869 : if (outer)
374 : {
375 1303588 : new_eh->next_peer = outer->inner;
376 1303588 : outer->inner = new_eh;
377 : }
378 : else
379 : {
380 1646281 : new_eh->next_peer = cfun->eh->region_tree;
381 1646281 : cfun->eh->region_tree = new_eh;
382 : }
383 :
384 2949869 : new_eh->index = vec_safe_length (cfun->eh->region_array);
385 2949869 : vec_safe_push (cfun->eh->region_array, new_eh);
386 :
387 : /* Copy the language's notion of whether to use __cxa_end_cleanup. */
388 2949869 : if (targetm.arm_eabi_unwinder && lang_hooks.eh_use_cxa_end_cleanup)
389 0 : new_eh->use_cxa_end_cleanup = true;
390 :
391 2949869 : return new_eh;
392 : }
393 :
394 : eh_region
395 1303976 : gen_eh_region_cleanup (eh_region outer)
396 : {
397 1303976 : return gen_eh_region (ERT_CLEANUP, outer);
398 : }
399 :
400 : eh_region
401 48979 : gen_eh_region_try (eh_region outer)
402 : {
403 48979 : return gen_eh_region (ERT_TRY, outer);
404 : }
405 :
406 : eh_catch
407 58339 : gen_eh_region_catch (eh_region t, tree type_or_list)
408 : {
409 58339 : eh_catch c, l;
410 58339 : tree type_list, type_node;
411 :
412 58339 : gcc_assert (t->type == ERT_TRY);
413 :
414 : /* Ensure to always end up with a type list to normalize further
415 : processing, then register each type against the runtime types map. */
416 58339 : type_list = type_or_list;
417 58339 : if (type_or_list)
418 : {
419 9669 : if (TREE_CODE (type_or_list) != TREE_LIST)
420 8148 : type_list = tree_cons (NULL_TREE, type_or_list, NULL_TREE);
421 :
422 9669 : type_node = type_list;
423 19338 : for (; type_node; type_node = TREE_CHAIN (type_node))
424 9669 : add_type_for_runtime (TREE_VALUE (type_node));
425 : }
426 :
427 58339 : c = ggc_cleared_alloc<eh_catch_d> ();
428 58339 : c->type_list = type_list;
429 58339 : l = t->u.eh_try.last_catch;
430 58339 : c->prev_catch = l;
431 58339 : if (l)
432 3572 : l->next_catch = c;
433 : else
434 54767 : t->u.eh_try.first_catch = c;
435 58339 : t->u.eh_try.last_catch = c;
436 :
437 58339 : return c;
438 : }
439 :
440 : eh_region
441 4351 : gen_eh_region_allowed (eh_region outer, tree allowed)
442 : {
443 4351 : eh_region region = gen_eh_region (ERT_ALLOWED_EXCEPTIONS, outer);
444 4351 : region->u.allowed.type_list = allowed;
445 :
446 4518 : for (; allowed ; allowed = TREE_CHAIN (allowed))
447 167 : add_type_for_runtime (TREE_VALUE (allowed));
448 :
449 4351 : return region;
450 : }
451 :
452 : eh_region
453 1343356 : gen_eh_region_must_not_throw (eh_region outer)
454 : {
455 1343356 : return gen_eh_region (ERT_MUST_NOT_THROW, outer);
456 : }
457 :
458 : eh_landing_pad
459 1864589 : gen_eh_landing_pad (eh_region region)
460 : {
461 1864589 : eh_landing_pad lp = ggc_cleared_alloc<eh_landing_pad_d> ();
462 :
463 1864589 : lp->next_lp = region->landing_pads;
464 1864589 : lp->region = region;
465 1864589 : lp->index = vec_safe_length (cfun->eh->lp_array);
466 1864589 : region->landing_pads = lp;
467 :
468 1864589 : vec_safe_push (cfun->eh->lp_array, lp);
469 :
470 1864589 : return lp;
471 : }
472 :
473 : eh_region
474 2404643 : get_eh_region_from_number_fn (struct function *ifun, int i)
475 : {
476 2404643 : return (*ifun->eh->region_array)[i];
477 : }
478 :
479 : eh_region
480 2303083 : get_eh_region_from_number (int i)
481 : {
482 2303083 : return get_eh_region_from_number_fn (cfun, i);
483 : }
484 :
485 : eh_landing_pad
486 292783158 : get_eh_landing_pad_from_number_fn (struct function *ifun, int i)
487 : {
488 292783158 : return (*ifun->eh->lp_array)[i];
489 : }
490 :
491 : eh_landing_pad
492 292783158 : get_eh_landing_pad_from_number (int i)
493 : {
494 292783158 : return get_eh_landing_pad_from_number_fn (cfun, i);
495 : }
496 :
497 : eh_region
498 12030528 : get_eh_region_from_lp_number_fn (struct function *ifun, int i)
499 : {
500 12030528 : if (i < 0)
501 62533 : return (*ifun->eh->region_array)[-i];
502 11967995 : else if (i == 0)
503 : return NULL;
504 : else
505 : {
506 5092160 : eh_landing_pad lp;
507 5092160 : lp = (*ifun->eh->lp_array)[i];
508 5092160 : return lp->region;
509 : }
510 : }
511 :
512 : eh_region
513 4954585 : get_eh_region_from_lp_number (int i)
514 : {
515 4954585 : return get_eh_region_from_lp_number_fn (cfun, i);
516 : }
517 :
518 : /* Returns true if the current function has exception handling regions. */
519 :
520 : bool
521 188 : current_function_has_exception_handlers (void)
522 : {
523 188 : return cfun->eh->region_tree != NULL;
524 : }
525 :
526 : /* A subroutine of duplicate_eh_regions. Copy the eh_region tree at OLD.
527 : Root it at OUTER, and apply LP_OFFSET to the lp numbers. */
528 :
529 : struct duplicate_eh_regions_data
530 : {
531 : duplicate_eh_regions_map label_map;
532 : void *label_map_data;
533 : hash_map<void *, void *> *eh_map;
534 : };
535 :
536 : static void
537 249207 : duplicate_eh_regions_1 (struct duplicate_eh_regions_data *data,
538 : eh_region old_r, eh_region outer)
539 : {
540 249207 : eh_landing_pad old_lp, new_lp;
541 249207 : eh_region new_r;
542 :
543 249207 : new_r = gen_eh_region (old_r->type, outer);
544 249207 : bool existed = data->eh_map->put (old_r, new_r);
545 249207 : gcc_assert (!existed);
546 :
547 249207 : switch (old_r->type)
548 : {
549 : case ERT_CLEANUP:
550 : break;
551 :
552 10725 : case ERT_TRY:
553 10725 : {
554 10725 : eh_catch oc, nc;
555 21952 : for (oc = old_r->u.eh_try.first_catch; oc ; oc = oc->next_catch)
556 : {
557 : /* We should be doing all our region duplication before and
558 : during inlining, which is before filter lists are created. */
559 11227 : gcc_assert (oc->filter_list == NULL);
560 11227 : nc = gen_eh_region_catch (new_r, oc->type_list);
561 11227 : nc->label = data->label_map (oc->label, data->label_map_data);
562 : }
563 : }
564 : break;
565 :
566 1198 : case ERT_ALLOWED_EXCEPTIONS:
567 1198 : new_r->u.allowed.type_list = old_r->u.allowed.type_list;
568 1198 : if (old_r->u.allowed.label)
569 163 : new_r->u.allowed.label
570 163 : = data->label_map (old_r->u.allowed.label, data->label_map_data);
571 : else
572 1035 : new_r->u.allowed.label = NULL_TREE;
573 : break;
574 :
575 154839 : case ERT_MUST_NOT_THROW:
576 309678 : new_r->u.must_not_throw.failure_loc =
577 154839 : LOCATION_LOCUS (old_r->u.must_not_throw.failure_loc);
578 154839 : new_r->u.must_not_throw.failure_decl =
579 154839 : old_r->u.must_not_throw.failure_decl;
580 154839 : break;
581 : }
582 :
583 344177 : for (old_lp = old_r->landing_pads; old_lp ; old_lp = old_lp->next_lp)
584 : {
585 : /* Don't bother copying unused landing pads. */
586 94970 : if (old_lp->post_landing_pad == NULL)
587 2451 : continue;
588 :
589 92519 : new_lp = gen_eh_landing_pad (new_r);
590 92519 : bool existed = data->eh_map->put (old_lp, new_lp);
591 92519 : gcc_assert (!existed);
592 :
593 92519 : new_lp->post_landing_pad
594 92519 : = data->label_map (old_lp->post_landing_pad, data->label_map_data);
595 92519 : EH_LANDING_PAD_NR (new_lp->post_landing_pad) = new_lp->index;
596 : }
597 :
598 : /* Make sure to preserve the original use of __cxa_end_cleanup. */
599 249207 : new_r->use_cxa_end_cleanup = old_r->use_cxa_end_cleanup;
600 :
601 274083 : for (old_r = old_r->inner; old_r ; old_r = old_r->next_peer)
602 24876 : duplicate_eh_regions_1 (data, old_r, new_r);
603 249207 : }
604 :
605 : /* Duplicate the EH regions from IFUN rooted at COPY_REGION into
606 : the current function and root the tree below OUTER_REGION.
607 : The special case of COPY_REGION of NULL means all regions.
608 : Remap labels using MAP/MAP_DATA callback. Return a pointer map
609 : that allows the caller to remap uses of both EH regions and
610 : EH landing pads. */
611 :
612 : hash_map<void *, void *> *
613 4891425 : duplicate_eh_regions (struct function *ifun,
614 : eh_region copy_region, int outer_lp,
615 : duplicate_eh_regions_map map, void *map_data)
616 : {
617 4891425 : struct duplicate_eh_regions_data data;
618 4891425 : eh_region outer_region;
619 :
620 4891425 : if (flag_checking)
621 4891413 : verify_eh_tree (ifun);
622 :
623 4891425 : data.label_map = map;
624 4891425 : data.label_map_data = map_data;
625 4891425 : data.eh_map = new hash_map<void *, void *>;
626 :
627 4891425 : outer_region = get_eh_region_from_lp_number_fn (cfun, outer_lp);
628 :
629 : /* Copy all the regions in the subtree. */
630 4891425 : if (copy_region)
631 2053 : duplicate_eh_regions_1 (&data, copy_region, outer_region);
632 : else
633 : {
634 4889372 : eh_region r;
635 5111650 : for (r = ifun->eh->region_tree; r ; r = r->next_peer)
636 222278 : duplicate_eh_regions_1 (&data, r, outer_region);
637 : }
638 :
639 4891425 : if (flag_checking)
640 4891413 : verify_eh_tree (cfun);
641 :
642 4891425 : return data.eh_map;
643 : }
644 :
645 : /* Return the region that is outer to both REGION_A and REGION_B in IFUN. */
646 :
647 : eh_region
648 249 : eh_region_outermost (struct function *ifun, eh_region region_a,
649 : eh_region region_b)
650 : {
651 249 : gcc_assert (ifun->eh->region_array);
652 249 : gcc_assert (ifun->eh->region_tree);
653 :
654 249 : auto_sbitmap b_outer (ifun->eh->region_array->length ());
655 249 : bitmap_clear (b_outer);
656 :
657 600 : do
658 : {
659 600 : bitmap_set_bit (b_outer, region_b->index);
660 600 : region_b = region_b->outer;
661 : }
662 600 : while (region_b);
663 :
664 489 : do
665 : {
666 489 : if (bitmap_bit_p (b_outer, region_a->index))
667 : break;
668 241 : region_a = region_a->outer;
669 : }
670 241 : while (region_a);
671 :
672 249 : return region_a;
673 249 : }
674 :
675 : void
676 9838 : add_type_for_runtime (tree type)
677 : {
678 : /* If TYPE is NOP_EXPR, it means that it already is a runtime type. */
679 9838 : if (TREE_CODE (type) == NOP_EXPR)
680 12 : return;
681 :
682 9826 : bool existed = false;
683 9826 : tree *slot = &type_to_runtime_map->get_or_insert (type, &existed);
684 9826 : if (!existed)
685 3160 : *slot = lang_hooks.eh_runtime_type (type);
686 : }
687 :
688 : tree
689 39253 : lookup_type_for_runtime (tree type)
690 : {
691 : /* If TYPE is NOP_EXPR, it means that it already is a runtime type. */
692 39253 : if (TREE_CODE (type) == NOP_EXPR)
693 : return type;
694 :
695 : /* We should have always inserted the data earlier. */
696 39253 : return *type_to_runtime_map->get (type);
697 : }
698 :
699 :
700 : /* Represent an entry in @TTypes for either catch actions
701 : or exception filter actions. */
702 : struct ttypes_filter {
703 : tree t;
704 : int filter;
705 : };
706 :
707 : /* Helper for ttypes_filter hashing. */
708 :
709 : struct ttypes_filter_hasher : free_ptr_hash <ttypes_filter>
710 : {
711 : typedef tree_node *compare_type;
712 : static inline hashval_t hash (const ttypes_filter *);
713 : static inline bool equal (const ttypes_filter *, const tree_node *);
714 : };
715 :
716 : /* Compare ENTRY (a ttypes_filter entry in the hash table) with DATA
717 : (a tree) for a @TTypes type node we are thinking about adding. */
718 :
719 : inline bool
720 24241 : ttypes_filter_hasher::equal (const ttypes_filter *entry, const tree_node *data)
721 : {
722 24241 : return entry->t == data;
723 : }
724 :
725 : inline hashval_t
726 26607 : ttypes_filter_hasher::hash (const ttypes_filter *entry)
727 : {
728 26607 : return TREE_HASH (entry->t);
729 : }
730 :
731 : typedef hash_table<ttypes_filter_hasher> ttypes_hash_type;
732 :
733 :
734 : /* Helper for ehspec hashing. */
735 :
736 : struct ehspec_hasher : free_ptr_hash <ttypes_filter>
737 : {
738 : static inline hashval_t hash (const ttypes_filter *);
739 : static inline bool equal (const ttypes_filter *, const ttypes_filter *);
740 : };
741 :
742 : /* Compare ENTRY with DATA (both struct ttypes_filter) for a @TTypes
743 : exception specification list we are thinking about adding. */
744 : /* ??? Currently we use the type lists in the order given. Someone
745 : should put these in some canonical order. */
746 :
747 : inline bool
748 552 : ehspec_hasher::equal (const ttypes_filter *entry, const ttypes_filter *data)
749 : {
750 552 : return type_list_equal (entry->t, data->t);
751 : }
752 :
753 : /* Hash function for exception specification lists. */
754 :
755 : inline hashval_t
756 1877 : ehspec_hasher::hash (const ttypes_filter *entry)
757 : {
758 1877 : hashval_t h = 0;
759 1877 : tree list;
760 :
761 2017 : for (list = entry->t; list ; list = TREE_CHAIN (list))
762 140 : h = (h << 5) + (h >> 27) + TREE_HASH (TREE_VALUE (list));
763 1877 : return h;
764 : }
765 :
766 : typedef hash_table<ehspec_hasher> ehspec_hash_type;
767 :
768 :
769 : /* Add TYPE (which may be NULL) to cfun->eh->ttype_data, using TYPES_HASH
770 : to speed up the search. Return the filter value to be used. */
771 :
772 : static int
773 48039 : add_ttypes_entry (ttypes_hash_type *ttypes_hash, tree type)
774 : {
775 48039 : struct ttypes_filter **slot, *n;
776 :
777 48039 : slot = ttypes_hash->find_slot_with_hash (type, (hashval_t) TREE_HASH (type),
778 : INSERT);
779 :
780 48039 : if ((n = *slot) == NULL)
781 : {
782 : /* Filter value is a 1 based table index. */
783 :
784 24024 : n = XNEW (struct ttypes_filter);
785 24024 : n->t = type;
786 24024 : n->filter = vec_safe_length (cfun->eh->ttype_data) + 1;
787 24024 : *slot = n;
788 :
789 24024 : vec_safe_push (cfun->eh->ttype_data, type);
790 : }
791 :
792 48039 : return n->filter;
793 : }
794 :
795 : /* Add LIST to cfun->eh->ehspec_data, using EHSPEC_HASH and TYPES_HASH
796 : to speed up the search. Return the filter value to be used. */
797 :
798 : static int
799 1337 : add_ehspec_entry (ehspec_hash_type *ehspec_hash, ttypes_hash_type *ttypes_hash,
800 : tree list)
801 : {
802 1337 : struct ttypes_filter **slot, *n;
803 1337 : struct ttypes_filter dummy;
804 :
805 1337 : dummy.t = list;
806 1337 : slot = ehspec_hash->find_slot (&dummy, INSERT);
807 :
808 1337 : if ((n = *slot) == NULL)
809 : {
810 785 : int len;
811 :
812 785 : if (targetm.arm_eabi_unwinder)
813 0 : len = vec_safe_length (cfun->eh->ehspec_data.arm_eabi);
814 : else
815 1570 : len = vec_safe_length (cfun->eh->ehspec_data.other);
816 :
817 : /* Filter value is a -1 based byte index into a uleb128 buffer. */
818 :
819 785 : n = XNEW (struct ttypes_filter);
820 785 : n->t = list;
821 785 : n->filter = -(len + 1);
822 785 : *slot = n;
823 :
824 : /* Generate a 0 terminated list of filter values. */
825 913 : for (; list ; list = TREE_CHAIN (list))
826 : {
827 128 : if (targetm.arm_eabi_unwinder)
828 0 : vec_safe_push (cfun->eh->ehspec_data.arm_eabi, TREE_VALUE (list));
829 : else
830 : {
831 : /* Look up each type in the list and encode its filter
832 : value as a uleb128. */
833 256 : push_uleb128 (&cfun->eh->ehspec_data.other,
834 128 : add_ttypes_entry (ttypes_hash, TREE_VALUE (list)));
835 : }
836 : }
837 785 : if (targetm.arm_eabi_unwinder)
838 0 : vec_safe_push (cfun->eh->ehspec_data.arm_eabi, NULL_TREE);
839 : else
840 785 : vec_safe_push (cfun->eh->ehspec_data.other, (uchar)0);
841 : }
842 :
843 1337 : return n->filter;
844 : }
845 :
846 : /* Generate the action filter values to be used for CATCH and
847 : ALLOWED_EXCEPTIONS regions. When using dwarf2 exception regions,
848 : we use lots of landing pads, and so every type or list can share
849 : the same filter value, which saves table space. */
850 :
851 : void
852 150295 : assign_filter_values (void)
853 : {
854 150295 : int i;
855 150295 : eh_region r;
856 150295 : eh_catch c;
857 :
858 150295 : vec_alloc (cfun->eh->ttype_data, 16);
859 150295 : if (targetm.arm_eabi_unwinder)
860 0 : vec_alloc (cfun->eh->ehspec_data.arm_eabi, 64);
861 : else
862 150295 : vec_alloc (cfun->eh->ehspec_data.other, 64);
863 :
864 150295 : ehspec_hash_type ehspec (31);
865 150295 : ttypes_hash_type ttypes (31);
866 :
867 1434914 : for (i = 1; vec_safe_iterate (cfun->eh->region_array, i, &r); ++i)
868 : {
869 1134324 : if (r == NULL)
870 652595 : continue;
871 :
872 481729 : switch (r->type)
873 : {
874 45843 : case ERT_TRY:
875 93754 : for (c = r->u.eh_try.first_catch; c ; c = c->next_catch)
876 : {
877 : /* Whatever type_list is (NULL or true list), we build a list
878 : of filters for the region. */
879 47911 : c->filter_list = NULL_TREE;
880 :
881 47911 : if (c->type_list != NULL)
882 : {
883 : /* Get a filter value for each of the types caught and store
884 : them in the region's dedicated list. */
885 : tree tp_node = c->type_list;
886 :
887 15904 : for ( ; tp_node; tp_node = TREE_CHAIN (tp_node))
888 : {
889 7952 : int flt
890 7952 : = add_ttypes_entry (&ttypes, TREE_VALUE (tp_node));
891 7952 : tree flt_node = build_int_cst (integer_type_node, flt);
892 :
893 7952 : c->filter_list
894 7952 : = tree_cons (NULL_TREE, flt_node, c->filter_list);
895 : }
896 : }
897 : else
898 : {
899 : /* Get a filter value for the NULL list also since it
900 : will need an action record anyway. */
901 39959 : int flt = add_ttypes_entry (&ttypes, NULL);
902 39959 : tree flt_node = build_int_cst (integer_type_node, flt);
903 :
904 39959 : c->filter_list
905 39959 : = tree_cons (NULL_TREE, flt_node, NULL);
906 : }
907 : }
908 : break;
909 :
910 1337 : case ERT_ALLOWED_EXCEPTIONS:
911 1337 : r->u.allowed.filter
912 1337 : = add_ehspec_entry (&ehspec, &ttypes, r->u.allowed.type_list);
913 1337 : break;
914 :
915 : default:
916 : break;
917 : }
918 : }
919 150295 : }
920 :
921 : /* Emit SEQ into basic block just before INSN (that is assumed to be
922 : first instruction of some existing BB and return the newly
923 : produced block. */
924 : static basic_block
925 220578 : emit_to_new_bb_before (rtx_insn *seq, rtx_insn *insn)
926 : {
927 220578 : rtx_insn *next, *last;
928 220578 : basic_block bb;
929 220578 : edge e;
930 220578 : edge_iterator ei;
931 :
932 : /* If there happens to be a fallthru edge (possibly created by cleanup_cfg
933 : call), we don't want it to go into newly created landing pad or other EH
934 : construct. */
935 1121467 : for (ei = ei_start (BLOCK_FOR_INSN (insn)->preds); (e = ei_safe_edge (ei)); )
936 900889 : if (e->flags & EDGE_FALLTHRU)
937 59111 : force_nonfallthru (e);
938 : else
939 841778 : ei_next (&ei);
940 :
941 : /* Make sure to put the location of INSN or a subsequent instruction on SEQ
942 : to avoid inheriting the location of the previous instruction. */
943 : next = insn;
944 1058241 : while (next && !NONDEBUG_INSN_P (next))
945 837663 : next = NEXT_INSN (next);
946 220578 : if (next)
947 220570 : last = emit_insn_before_setloc (seq, insn, next->location ());
948 : else
949 8 : last = emit_insn_before (seq, insn);
950 220578 : if (BARRIER_P (last))
951 0 : last = PREV_INSN (last);
952 220578 : bb = create_basic_block (seq, last, BLOCK_FOR_INSN (insn)->prev_bb);
953 220578 : update_bb_for_insn (bb);
954 220578 : bb->flags |= BB_SUPERBLOCK;
955 220578 : return bb;
956 : }
957 :
958 : /* A subroutine of dw2_build_landing_pads, also used for edge splitting
959 : at the rtl level. Emit the code required by the target at a landing
960 : pad for the given region. */
961 :
962 : static void
963 220578 : expand_dw2_landing_pad_for_region (eh_region region)
964 : {
965 220578 : if (targetm.have_exception_receiver ())
966 0 : emit_insn (targetm.gen_exception_receiver ());
967 220578 : else if (targetm.have_nonlocal_goto_receiver ())
968 0 : emit_insn (targetm.gen_nonlocal_goto_receiver ());
969 : else
970 : { /* Nothing */ }
971 :
972 220578 : if (region->exc_ptr_reg)
973 : {
974 193110 : rtx exc_ptr_reg;
975 193110 : if (EH_RETURN_DATA_REGNO (0) != INVALID_REGNUM)
976 193110 : exc_ptr_reg = gen_rtx_REG (ptr_mode, EH_RETURN_DATA_REGNO (0));
977 : else
978 : /* The target must be doing something special. Submit a dummy. */
979 : exc_ptr_reg = constm1_rtx;
980 193110 : emit_move_insn (region->exc_ptr_reg, exc_ptr_reg);
981 : }
982 220578 : if (region->filter_reg)
983 : {
984 122773 : rtx filter_reg;
985 122773 : if (EH_RETURN_DATA_REGNO (1) != INVALID_REGNUM)
986 122773 : filter_reg = gen_rtx_REG (targetm.eh_return_filter_mode (),
987 : EH_RETURN_DATA_REGNO (1));
988 : else
989 : /* The target must be doing something special. Submit a dummy. */
990 : filter_reg = constm1_rtx;
991 122773 : emit_move_insn (region->filter_reg, filter_reg);
992 : }
993 220578 : }
994 :
995 : /* Expand the extra code needed at landing pads for dwarf2 unwinding. */
996 :
997 : static void
998 66048 : dw2_build_landing_pads (void)
999 : {
1000 66048 : int i;
1001 66048 : eh_landing_pad lp;
1002 66048 : int e_flags = EDGE_FALLTHRU;
1003 :
1004 : /* If we're going to partition blocks, we need to be able to add
1005 : new landing pads later, which means that we need to hold on to
1006 : the post-landing-pad block. Prevent it from being merged away.
1007 : We'll remove this bit after partitioning. */
1008 66048 : if (flag_reorder_blocks_and_partition)
1009 44388 : e_flags |= EDGE_PRESERVE;
1010 :
1011 1335487 : for (i = 1; vec_safe_iterate (cfun->eh->lp_array, i, &lp); ++i)
1012 : {
1013 1269439 : basic_block bb;
1014 1269439 : rtx_insn *seq;
1015 :
1016 1269439 : if (lp == NULL || lp->post_landing_pad == NULL)
1017 1048861 : continue;
1018 :
1019 220578 : start_sequence ();
1020 :
1021 220578 : lp->landing_pad = gen_label_rtx ();
1022 220578 : emit_label (lp->landing_pad);
1023 220578 : LABEL_PRESERVE_P (lp->landing_pad) = 1;
1024 :
1025 220578 : expand_dw2_landing_pad_for_region (lp->region);
1026 :
1027 220578 : seq = end_sequence ();
1028 :
1029 220578 : bb = emit_to_new_bb_before (seq, label_rtx (lp->post_landing_pad));
1030 220578 : bb->count = bb->next_bb->count;
1031 220578 : make_single_succ_edge (bb, bb->next_bb, e_flags);
1032 220578 : if (current_loops)
1033 : {
1034 220578 : class loop *loop = bb->next_bb->loop_father;
1035 : /* If we created a pre-header block, add the new block to the
1036 : outer loop, otherwise to the loop itself. */
1037 220578 : if (bb->next_bb == loop->header)
1038 8330 : add_bb_to_loop (bb, loop_outer (loop));
1039 : else
1040 212248 : add_bb_to_loop (bb, loop);
1041 : }
1042 : }
1043 66048 : }
1044 :
1045 :
1046 : static vec<int> sjlj_lp_call_site_index;
1047 :
1048 : /* Process all active landing pads. Assign each one a compact dispatch
1049 : index, and a call-site index. */
1050 :
1051 : static int
1052 0 : sjlj_assign_call_site_values (void)
1053 : {
1054 0 : action_hash_type ar_hash (31);
1055 0 : int i, disp_index;
1056 0 : eh_landing_pad lp;
1057 :
1058 0 : vec_alloc (crtl->eh.action_record_data, 64);
1059 :
1060 0 : disp_index = 0;
1061 0 : call_site_base = 1;
1062 0 : for (i = 1; vec_safe_iterate (cfun->eh->lp_array, i, &lp); ++i)
1063 0 : if (lp && lp->post_landing_pad)
1064 : {
1065 0 : int action, call_site;
1066 :
1067 : /* First: build the action table. */
1068 0 : action = collect_one_action_chain (&ar_hash, lp->region);
1069 :
1070 : /* Next: assign call-site values. If dwarf2 terms, this would be
1071 : the region number assigned by convert_to_eh_region_ranges, but
1072 : handles no-action and must-not-throw differently. */
1073 : /* Map must-not-throw to otherwise unused call-site index 0. */
1074 0 : if (action == -2)
1075 : call_site = 0;
1076 : /* Map no-action to otherwise unused call-site index -1. */
1077 0 : else if (action == -1)
1078 : call_site = -1;
1079 : /* Otherwise, look it up in the table. */
1080 : else
1081 0 : call_site = add_call_site (GEN_INT (disp_index), action, 0);
1082 0 : sjlj_lp_call_site_index[i] = call_site;
1083 :
1084 0 : disp_index++;
1085 : }
1086 :
1087 0 : return disp_index;
1088 0 : }
1089 :
1090 : /* Emit code to record the current call-site index before every
1091 : insn that can throw. */
1092 :
1093 : static void
1094 0 : sjlj_mark_call_sites (void)
1095 : {
1096 0 : int last_call_site = -2;
1097 0 : rtx_insn *insn;
1098 0 : rtx mem;
1099 :
1100 0 : for (insn = get_insns (); insn ; insn = NEXT_INSN (insn))
1101 : {
1102 0 : eh_landing_pad lp;
1103 0 : eh_region r;
1104 0 : bool nothrow;
1105 0 : int this_call_site;
1106 0 : rtx_insn *before, *p;
1107 :
1108 : /* Reset value tracking at extended basic block boundaries. */
1109 0 : if (LABEL_P (insn))
1110 0 : last_call_site = -2;
1111 :
1112 : /* If the function allocates dynamic stack space, the context must
1113 : be updated after every allocation/deallocation accordingly. */
1114 0 : if (NOTE_P (insn) && NOTE_KIND (insn) == NOTE_INSN_UPDATE_SJLJ_CONTEXT)
1115 : {
1116 0 : rtx buf_addr;
1117 :
1118 0 : start_sequence ();
1119 0 : buf_addr = plus_constant (Pmode, XEXP (crtl->eh.sjlj_fc, 0),
1120 0 : sjlj_fc_jbuf_ofs);
1121 0 : expand_builtin_update_setjmp_buf (buf_addr);
1122 0 : p = end_sequence ();
1123 0 : emit_insn_before (p, insn);
1124 : }
1125 :
1126 0 : if (! INSN_P (insn))
1127 0 : continue;
1128 :
1129 0 : nothrow = get_eh_region_and_lp_from_rtx (insn, &r, &lp);
1130 0 : if (nothrow)
1131 0 : continue;
1132 0 : if (lp)
1133 0 : this_call_site = sjlj_lp_call_site_index[lp->index];
1134 0 : else if (r == NULL)
1135 : {
1136 : /* Calls (and trapping insns) without notes are outside any
1137 : exception handling region in this function. Mark them as
1138 : no action. */
1139 : this_call_site = -1;
1140 : }
1141 : else
1142 : {
1143 0 : gcc_assert (r->type == ERT_MUST_NOT_THROW);
1144 : this_call_site = 0;
1145 : }
1146 :
1147 0 : if (this_call_site != -1)
1148 0 : crtl->uses_eh_lsda = 1;
1149 :
1150 0 : if (this_call_site == last_call_site)
1151 0 : continue;
1152 :
1153 : /* Don't separate a call from it's argument loads. */
1154 0 : before = insn;
1155 0 : if (auto call = dyn_cast<rtx_call_insn *> (insn))
1156 0 : before = find_first_parameter_load (call, NULL);
1157 :
1158 0 : start_sequence ();
1159 0 : mem = adjust_address (crtl->eh.sjlj_fc, TYPE_MODE (integer_type_node),
1160 : sjlj_fc_call_site_ofs);
1161 0 : emit_move_insn (mem, gen_int_mode (this_call_site, GET_MODE (mem)));
1162 0 : p = end_sequence ();
1163 :
1164 0 : emit_insn_before (p, before);
1165 0 : last_call_site = this_call_site;
1166 : }
1167 0 : }
1168 :
1169 : /* Construct the SjLj_Function_Context. */
1170 :
1171 : static void
1172 0 : sjlj_emit_function_enter (rtx_code_label *dispatch_label)
1173 : {
1174 0 : rtx_insn *fn_begin, *seq;
1175 0 : rtx fc, mem;
1176 0 : bool fn_begin_outside_block;
1177 0 : rtx personality = get_personality_function (current_function_decl);
1178 :
1179 0 : fc = crtl->eh.sjlj_fc;
1180 :
1181 0 : start_sequence ();
1182 :
1183 : /* We're storing this libcall's address into memory instead of
1184 : calling it directly. Thus, we must call assemble_external_libcall
1185 : here, as we cannot depend on emit_library_call to do it for us. */
1186 0 : assemble_external_libcall (personality);
1187 0 : mem = adjust_address (fc, Pmode, sjlj_fc_personality_ofs);
1188 0 : emit_move_insn (mem, personality);
1189 :
1190 0 : mem = adjust_address (fc, Pmode, sjlj_fc_lsda_ofs);
1191 0 : if (crtl->uses_eh_lsda)
1192 : {
1193 0 : char buf[20];
1194 0 : rtx sym;
1195 :
1196 0 : ASM_GENERATE_INTERNAL_LABEL (buf, "LLSDA", current_function_funcdef_no);
1197 0 : sym = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
1198 0 : SYMBOL_REF_FLAGS (sym) = SYMBOL_FLAG_LOCAL;
1199 0 : emit_move_insn (mem, sym);
1200 : }
1201 : else
1202 0 : emit_move_insn (mem, const0_rtx);
1203 :
1204 0 : if (dispatch_label)
1205 : {
1206 0 : rtx addr = plus_constant (Pmode, XEXP (fc, 0), sjlj_fc_jbuf_ofs);
1207 :
1208 : #ifdef DONT_USE_BUILTIN_SETJMP
1209 : addr = copy_addr_to_reg (addr);
1210 : addr = convert_memory_address (ptr_mode, addr);
1211 : tree addr_tree = make_tree (ptr_type_node, addr);
1212 :
1213 : tree call_expr = build_call_expr (setjmp_fn, 1, addr_tree);
1214 : rtx x = expand_call (call_expr, NULL_RTX, false);
1215 :
1216 : emit_cmp_and_jump_insns (x, const0_rtx, NE, 0,
1217 : TYPE_MODE (integer_type_node), 0,
1218 : dispatch_label,
1219 : profile_probability::unlikely ());
1220 : #else
1221 0 : expand_builtin_setjmp_setup (addr, dispatch_label);
1222 : #endif
1223 : }
1224 :
1225 0 : emit_library_call (unwind_sjlj_register_libfunc, LCT_NORMAL, VOIDmode,
1226 0 : XEXP (fc, 0), Pmode);
1227 :
1228 0 : seq = end_sequence ();
1229 :
1230 : /* ??? Instead of doing this at the beginning of the function,
1231 : do this in a block that is at loop level 0 and dominates all
1232 : can_throw_internal instructions. */
1233 :
1234 0 : fn_begin_outside_block = true;
1235 0 : for (fn_begin = get_insns (); ; fn_begin = NEXT_INSN (fn_begin))
1236 0 : if (NOTE_P (fn_begin))
1237 : {
1238 0 : if (NOTE_KIND (fn_begin) == NOTE_INSN_FUNCTION_BEG)
1239 : break;
1240 0 : else if (NOTE_INSN_BASIC_BLOCK_P (fn_begin))
1241 0 : fn_begin_outside_block = false;
1242 : }
1243 : /* assign_params can indirectly call emit_block_move_via_loop, e.g.
1244 : for g++.dg/torture/pr85627.C for 16-bit targets. */
1245 0 : else if (JUMP_P (fn_begin))
1246 0 : fn_begin_outside_block = true;
1247 :
1248 : #ifdef DONT_USE_BUILTIN_SETJMP
1249 : if (dispatch_label)
1250 : {
1251 : /* The sequence contains a branch in the middle so we need to force
1252 : the creation of a new basic block by means of BB_SUPERBLOCK. */
1253 : if (fn_begin_outside_block)
1254 : {
1255 : basic_block bb
1256 : = split_edge (single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun)));
1257 : if (JUMP_P (BB_END (bb)))
1258 : emit_insn_before (seq, BB_END (bb));
1259 : else
1260 : emit_insn_after (seq, BB_END (bb));
1261 : }
1262 : else
1263 : emit_insn_after (seq, fn_begin);
1264 :
1265 : single_succ (ENTRY_BLOCK_PTR_FOR_FN (cfun))->flags |= BB_SUPERBLOCK;
1266 : return;
1267 : }
1268 : #endif
1269 :
1270 0 : if (fn_begin_outside_block)
1271 0 : insert_insn_on_edge (seq, single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun)));
1272 : else
1273 0 : emit_insn_after (seq, fn_begin);
1274 0 : }
1275 :
1276 : /* Call back from expand_function_end to know where we should put
1277 : the call to unwind_sjlj_unregister_libfunc if needed. */
1278 :
1279 : void
1280 0 : sjlj_emit_function_exit_after (rtx_insn *after)
1281 : {
1282 0 : crtl->eh.sjlj_exit_after = after;
1283 0 : }
1284 :
1285 : static void
1286 0 : sjlj_emit_function_exit (void)
1287 : {
1288 0 : rtx_insn *seq, *insn;
1289 :
1290 0 : start_sequence ();
1291 :
1292 0 : emit_library_call (unwind_sjlj_unregister_libfunc, LCT_NORMAL, VOIDmode,
1293 0 : XEXP (crtl->eh.sjlj_fc, 0), Pmode);
1294 :
1295 0 : seq = end_sequence ();
1296 :
1297 : /* ??? Really this can be done in any block at loop level 0 that
1298 : post-dominates all can_throw_internal instructions. This is
1299 : the last possible moment. */
1300 :
1301 0 : insn = crtl->eh.sjlj_exit_after;
1302 0 : if (LABEL_P (insn))
1303 0 : insn = NEXT_INSN (insn);
1304 :
1305 0 : emit_insn_after (seq, insn);
1306 0 : }
1307 :
1308 : static void
1309 0 : sjlj_emit_dispatch_table (rtx_code_label *dispatch_label, int num_dispatch)
1310 : {
1311 0 : scalar_int_mode unwind_word_mode = targetm.unwind_word_mode ();
1312 0 : scalar_int_mode filter_mode = targetm.eh_return_filter_mode ();
1313 0 : eh_landing_pad lp;
1314 0 : rtx mem, fc, exc_ptr_reg, filter_reg;
1315 0 : rtx_insn *seq;
1316 0 : basic_block bb;
1317 0 : eh_region r;
1318 0 : int i, disp_index;
1319 0 : vec<tree> dispatch_labels = vNULL;
1320 :
1321 0 : fc = crtl->eh.sjlj_fc;
1322 :
1323 0 : start_sequence ();
1324 :
1325 0 : emit_label (dispatch_label);
1326 :
1327 : #ifndef DONT_USE_BUILTIN_SETJMP
1328 0 : expand_builtin_setjmp_receiver (dispatch_label);
1329 :
1330 : /* The caller of expand_builtin_setjmp_receiver is responsible for
1331 : making sure that the label doesn't vanish. The only other caller
1332 : is the expander for __builtin_setjmp_receiver, which places this
1333 : label on the nonlocal_goto_label list. Since we're modeling these
1334 : CFG edges more exactly, we can use the forced_labels list instead. */
1335 0 : LABEL_PRESERVE_P (dispatch_label) = 1;
1336 0 : vec_safe_push<rtx_insn *> (forced_labels, dispatch_label);
1337 : #endif
1338 :
1339 : /* Load up exc_ptr and filter values from the function context. */
1340 0 : mem = adjust_address (fc, unwind_word_mode, sjlj_fc_data_ofs);
1341 0 : if (unwind_word_mode != ptr_mode)
1342 : {
1343 : #ifdef POINTERS_EXTEND_UNSIGNED
1344 0 : mem = convert_memory_address (ptr_mode, mem);
1345 : #else
1346 : mem = convert_to_mode (ptr_mode, mem, 0);
1347 : #endif
1348 : }
1349 0 : exc_ptr_reg = force_reg (ptr_mode, mem);
1350 :
1351 0 : mem = adjust_address (fc, unwind_word_mode,
1352 : sjlj_fc_data_ofs + GET_MODE_SIZE (unwind_word_mode));
1353 0 : if (unwind_word_mode != filter_mode)
1354 0 : mem = convert_to_mode (filter_mode, mem, 0);
1355 0 : filter_reg = force_reg (filter_mode, mem);
1356 :
1357 : /* Jump to one of the directly reachable regions. */
1358 :
1359 0 : disp_index = 0;
1360 0 : rtx_code_label *first_reachable_label = NULL;
1361 :
1362 : /* If there's exactly one call site in the function, don't bother
1363 : generating a switch statement. */
1364 0 : if (num_dispatch > 1)
1365 0 : dispatch_labels.create (num_dispatch);
1366 :
1367 0 : for (i = 1; vec_safe_iterate (cfun->eh->lp_array, i, &lp); ++i)
1368 0 : if (lp && lp->post_landing_pad)
1369 : {
1370 0 : rtx_insn *seq2;
1371 0 : rtx_code_label *label;
1372 :
1373 0 : start_sequence ();
1374 :
1375 0 : lp->landing_pad = dispatch_label;
1376 :
1377 0 : if (num_dispatch > 1)
1378 : {
1379 0 : tree t_label, case_elt, t;
1380 :
1381 0 : t_label = create_artificial_label (UNKNOWN_LOCATION);
1382 0 : t = build_int_cst (integer_type_node, disp_index);
1383 0 : case_elt = build_case_label (t, NULL, t_label);
1384 0 : dispatch_labels.quick_push (case_elt);
1385 0 : label = jump_target_rtx (t_label);
1386 : }
1387 : else
1388 0 : label = gen_label_rtx ();
1389 :
1390 0 : if (disp_index == 0)
1391 0 : first_reachable_label = label;
1392 0 : emit_label (label);
1393 :
1394 0 : r = lp->region;
1395 0 : if (r->exc_ptr_reg)
1396 0 : emit_move_insn (r->exc_ptr_reg, exc_ptr_reg);
1397 0 : if (r->filter_reg)
1398 0 : emit_move_insn (r->filter_reg, filter_reg);
1399 :
1400 0 : seq2 = end_sequence ();
1401 :
1402 0 : rtx_insn *before = label_rtx (lp->post_landing_pad);
1403 0 : bb = emit_to_new_bb_before (seq2, before);
1404 0 : make_single_succ_edge (bb, bb->next_bb, EDGE_FALLTHRU);
1405 0 : if (current_loops)
1406 : {
1407 0 : class loop *loop = bb->next_bb->loop_father;
1408 : /* If we created a pre-header block, add the new block to the
1409 : outer loop, otherwise to the loop itself. */
1410 0 : if (bb->next_bb == loop->header)
1411 0 : add_bb_to_loop (bb, loop_outer (loop));
1412 : else
1413 0 : add_bb_to_loop (bb, loop);
1414 : /* ??? For multiple dispatches we will end up with edges
1415 : from the loop tree root into this loop, making it a
1416 : multiple-entry loop. Discard all affected loops. */
1417 0 : if (num_dispatch > 1)
1418 : {
1419 0 : for (loop = bb->loop_father;
1420 0 : loop_outer (loop); loop = loop_outer (loop))
1421 0 : mark_loop_for_removal (loop);
1422 : }
1423 : }
1424 :
1425 0 : disp_index++;
1426 : }
1427 0 : gcc_assert (disp_index == num_dispatch);
1428 :
1429 0 : if (num_dispatch > 1)
1430 : {
1431 0 : rtx disp = adjust_address (fc, TYPE_MODE (integer_type_node),
1432 : sjlj_fc_call_site_ofs);
1433 0 : expand_sjlj_dispatch_table (disp, dispatch_labels);
1434 : }
1435 :
1436 0 : seq = end_sequence ();
1437 :
1438 0 : bb = emit_to_new_bb_before (seq, first_reachable_label);
1439 0 : if (num_dispatch == 1)
1440 : {
1441 0 : make_single_succ_edge (bb, bb->next_bb, EDGE_FALLTHRU);
1442 0 : if (current_loops)
1443 : {
1444 0 : class loop *loop = bb->next_bb->loop_father;
1445 : /* If we created a pre-header block, add the new block to the
1446 : outer loop, otherwise to the loop itself. */
1447 0 : if (bb->next_bb == loop->header)
1448 0 : add_bb_to_loop (bb, loop_outer (loop));
1449 : else
1450 0 : add_bb_to_loop (bb, loop);
1451 : }
1452 : }
1453 : else
1454 : {
1455 : /* We are not wiring up edges here, but as the dispatcher call
1456 : is at function begin simply associate the block with the
1457 : outermost (non-)loop. */
1458 0 : if (current_loops)
1459 0 : add_bb_to_loop (bb, current_loops->tree_root);
1460 : }
1461 0 : }
1462 :
1463 : static void
1464 0 : sjlj_build_landing_pads (void)
1465 : {
1466 0 : int num_dispatch;
1467 :
1468 0 : num_dispatch = vec_safe_length (cfun->eh->lp_array);
1469 0 : if (num_dispatch == 0)
1470 : return;
1471 0 : sjlj_lp_call_site_index.safe_grow_cleared (num_dispatch, true);
1472 :
1473 0 : num_dispatch = sjlj_assign_call_site_values ();
1474 0 : if (num_dispatch > 0)
1475 : {
1476 0 : rtx_code_label *dispatch_label = gen_label_rtx ();
1477 0 : int align = STACK_SLOT_ALIGNMENT (sjlj_fc_type_node,
1478 : TYPE_MODE (sjlj_fc_type_node),
1479 : TYPE_ALIGN (sjlj_fc_type_node));
1480 0 : crtl->eh.sjlj_fc
1481 0 : = assign_stack_local_1 (TYPE_MODE (sjlj_fc_type_node),
1482 0 : int_size_in_bytes (sjlj_fc_type_node),
1483 : align, ASLK_RECORD_PAD | ASLK_REDUCE_ALIGN);
1484 :
1485 0 : sjlj_mark_call_sites ();
1486 0 : sjlj_emit_function_enter (dispatch_label);
1487 0 : sjlj_emit_dispatch_table (dispatch_label, num_dispatch);
1488 0 : sjlj_emit_function_exit ();
1489 : }
1490 :
1491 : /* If we do not have any landing pads, we may still need to register a
1492 : personality routine and (empty) LSDA to handle must-not-throw regions. */
1493 0 : else if (function_needs_eh_personality (cfun) != eh_personality_none)
1494 : {
1495 0 : int align = STACK_SLOT_ALIGNMENT (sjlj_fc_type_node,
1496 : TYPE_MODE (sjlj_fc_type_node),
1497 : TYPE_ALIGN (sjlj_fc_type_node));
1498 0 : crtl->eh.sjlj_fc
1499 0 : = assign_stack_local_1 (TYPE_MODE (sjlj_fc_type_node),
1500 0 : int_size_in_bytes (sjlj_fc_type_node),
1501 : align, ASLK_RECORD_PAD | ASLK_REDUCE_ALIGN);
1502 :
1503 0 : sjlj_mark_call_sites ();
1504 0 : sjlj_emit_function_enter (NULL);
1505 0 : sjlj_emit_function_exit ();
1506 : }
1507 :
1508 0 : sjlj_lp_call_site_index.release ();
1509 : }
1510 :
1511 : /* Update the sjlj function context. This function should be called
1512 : whenever we allocate or deallocate dynamic stack space. */
1513 :
1514 : void
1515 0 : update_sjlj_context (void)
1516 : {
1517 0 : if (!flag_exceptions)
1518 : return;
1519 :
1520 0 : emit_note (NOTE_INSN_UPDATE_SJLJ_CONTEXT);
1521 : }
1522 :
1523 : /* After initial rtl generation, call back to finish generating
1524 : exception support code. */
1525 :
1526 : void
1527 66048 : finish_eh_generation (void)
1528 : {
1529 66048 : basic_block bb;
1530 :
1531 : /* Construct the landing pads. */
1532 66048 : if (targetm_common.except_unwind_info (&global_options) == UI_SJLJ)
1533 0 : sjlj_build_landing_pads ();
1534 : else
1535 66048 : dw2_build_landing_pads ();
1536 :
1537 66048 : break_superblocks ();
1538 :
1539 : /* Redirect all EH edges from the post_landing_pad to the landing pad. */
1540 3769087 : FOR_EACH_BB_FN (bb, cfun)
1541 : {
1542 3703039 : eh_landing_pad lp;
1543 3703039 : edge_iterator ei;
1544 3703039 : edge e;
1545 :
1546 3703039 : lp = get_eh_landing_pad_from_rtx (BB_END (bb));
1547 :
1548 7654211 : FOR_EACH_EDGE (e, ei, bb->succs)
1549 4696978 : if (e->flags & EDGE_EH)
1550 : break;
1551 :
1552 : /* We should not have generated any new throwing insns during this
1553 : pass, and we should not have lost any EH edges, so we only need
1554 : to handle two cases here:
1555 : (1) reachable handler and an existing edge to post-landing-pad,
1556 : (2) no reachable handler and no edge. */
1557 3703039 : gcc_assert ((lp != NULL) == (e != NULL));
1558 3703039 : if (lp != NULL)
1559 : {
1560 745806 : gcc_assert (BB_HEAD (e->dest) == label_rtx (lp->post_landing_pad));
1561 :
1562 745806 : redirect_edge_succ (e, BLOCK_FOR_INSN (lp->landing_pad));
1563 745806 : e->flags |= (CALL_P (BB_END (bb))
1564 745806 : ? EDGE_ABNORMAL | EDGE_ABNORMAL_CALL
1565 : : EDGE_ABNORMAL);
1566 : }
1567 : }
1568 :
1569 66048 : if (targetm_common.except_unwind_info (&global_options) == UI_SJLJ
1570 : /* Kludge for Alpha (see alpha_gp_save_rtx). */
1571 66048 : || single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun))->insns.r)
1572 0 : commit_edge_insertions ();
1573 66048 : }
1574 :
1575 : /* This section handles removing dead code for flow. */
1576 :
1577 : void
1578 1405835 : remove_eh_landing_pad (eh_landing_pad lp)
1579 : {
1580 1405835 : eh_landing_pad *pp;
1581 :
1582 30175219 : for (pp = &lp->region->landing_pads; *pp != lp; pp = &(*pp)->next_lp)
1583 28769384 : continue;
1584 1405835 : *pp = lp->next_lp;
1585 :
1586 1405835 : if (lp->post_landing_pad)
1587 1398620 : EH_LANDING_PAD_NR (lp->post_landing_pad) = 0;
1588 1405835 : (*cfun->eh->lp_array)[lp->index] = NULL;
1589 28769384 : }
1590 :
1591 : /* Splice the EH region at PP from the region tree. */
1592 :
1593 : static void
1594 2537094 : remove_eh_handler_splicer (eh_region *pp)
1595 : {
1596 2537094 : eh_region region = *pp;
1597 2537094 : eh_landing_pad lp;
1598 :
1599 2693575 : for (lp = region->landing_pads; lp ; lp = lp->next_lp)
1600 : {
1601 156481 : if (lp->post_landing_pad)
1602 156434 : EH_LANDING_PAD_NR (lp->post_landing_pad) = 0;
1603 156481 : (*cfun->eh->lp_array)[lp->index] = NULL;
1604 : }
1605 :
1606 2537094 : if (region->inner)
1607 : {
1608 120224 : eh_region p, outer;
1609 120224 : outer = region->outer;
1610 :
1611 120224 : *pp = p = region->inner;
1612 141587 : do
1613 : {
1614 141587 : p->outer = outer;
1615 141587 : pp = &p->next_peer;
1616 141587 : p = *pp;
1617 : }
1618 141587 : while (p);
1619 : }
1620 2537094 : *pp = region->next_peer;
1621 :
1622 2537094 : (*cfun->eh->region_array)[region->index] = NULL;
1623 2537094 : }
1624 :
1625 : /* Splice a single EH region REGION from the region tree.
1626 :
1627 : To unlink REGION, we need to find the pointer to it with a relatively
1628 : expensive search in REGION's outer region. If you are going to
1629 : remove a number of handlers, using remove_unreachable_eh_regions may
1630 : be a better option. */
1631 :
1632 : void
1633 0 : remove_eh_handler (eh_region region)
1634 : {
1635 0 : eh_region *pp, *pp_start, p, outer;
1636 :
1637 0 : outer = region->outer;
1638 0 : if (outer)
1639 0 : pp_start = &outer->inner;
1640 : else
1641 0 : pp_start = &cfun->eh->region_tree;
1642 0 : for (pp = pp_start, p = *pp; p != region; pp = &p->next_peer, p = *pp)
1643 0 : continue;
1644 :
1645 0 : remove_eh_handler_splicer (pp);
1646 0 : }
1647 :
1648 : /* Worker for remove_unreachable_eh_regions.
1649 : PP is a pointer to the region to start a region tree depth-first
1650 : search from. R_REACHABLE is the set of regions that have to be
1651 : preserved. */
1652 :
1653 : static void
1654 5669652 : remove_unreachable_eh_regions_worker (eh_region *pp, sbitmap r_reachable)
1655 : {
1656 9879767 : while (*pp)
1657 : {
1658 4210115 : eh_region region = *pp;
1659 4210115 : remove_unreachable_eh_regions_worker (®ion->inner, r_reachable);
1660 4210115 : if (!bitmap_bit_p (r_reachable, region->index))
1661 2537094 : remove_eh_handler_splicer (pp);
1662 : else
1663 1673021 : pp = ®ion->next_peer;
1664 : }
1665 5669652 : }
1666 :
1667 : /* Splice all EH regions *not* marked in R_REACHABLE from the region tree.
1668 : Do this by traversing the EH tree top-down and splice out regions that
1669 : are not marked. By removing regions from the leaves, we avoid costly
1670 : searches in the region tree. */
1671 :
1672 : void
1673 1459537 : remove_unreachable_eh_regions (sbitmap r_reachable)
1674 : {
1675 1459537 : remove_unreachable_eh_regions_worker (&cfun->eh->region_tree, r_reachable);
1676 1459537 : }
1677 :
1678 : /* Invokes CALLBACK for every exception handler landing pad label.
1679 : Only used by reload hackery; should not be used by new code. */
1680 :
1681 : void
1682 0 : for_each_eh_label (void (*callback) (rtx_code_label *))
1683 : {
1684 0 : eh_landing_pad lp;
1685 0 : int i;
1686 :
1687 0 : for (i = 1; vec_safe_iterate (cfun->eh->lp_array, i, &lp); ++i)
1688 : {
1689 0 : if (lp)
1690 : {
1691 0 : rtx_code_label *lab = lp->landing_pad;
1692 0 : if (lab && LABEL_P (lab))
1693 0 : (*callback) (lab);
1694 : }
1695 : }
1696 0 : }
1697 :
1698 : /* Create the REG_EH_REGION note for INSN, given its ECF_FLAGS for a
1699 : call insn.
1700 :
1701 : At the gimple level, we use LP_NR
1702 : > 0 : The statement transfers to landing pad LP_NR
1703 : = 0 : The statement is outside any EH region
1704 : < 0 : The statement is within MUST_NOT_THROW region -LP_NR.
1705 :
1706 : At the rtl level, we use LP_NR
1707 : > 0 : The insn transfers to landing pad LP_NR
1708 : = 0 : The insn cannot throw
1709 : < 0 : The insn is within MUST_NOT_THROW region -LP_NR
1710 : = INT_MIN : The insn cannot throw or execute a nonlocal-goto.
1711 : missing note: The insn is outside any EH region.
1712 :
1713 : ??? This difference probably ought to be avoided. We could stand
1714 : to record nothrow for arbitrary gimple statements, and so avoid
1715 : some moderately complex lookups in stmt_could_throw_p. Perhaps
1716 : NOTHROW should be mapped on both sides to INT_MIN. Perhaps the
1717 : no-nonlocal-goto property should be recorded elsewhere as a bit
1718 : on the call_insn directly. Perhaps we should make more use of
1719 : attaching the trees to call_insns (reachable via symbol_ref in
1720 : direct call cases) and just pull the data out of the trees. */
1721 :
1722 : void
1723 7018585 : make_reg_eh_region_note (rtx_insn *insn, int ecf_flags, int lp_nr)
1724 : {
1725 7018585 : rtx value;
1726 7018585 : if (ecf_flags & ECF_NOTHROW)
1727 2456838 : value = const0_rtx;
1728 4561747 : else if (lp_nr != 0)
1729 822861 : value = GEN_INT (lp_nr);
1730 : else
1731 : return;
1732 3279699 : add_reg_note (insn, REG_EH_REGION, value);
1733 : }
1734 :
1735 : /* Create a REG_EH_REGION note for a CALL_INSN that cannot throw
1736 : nor perform a non-local goto. Replace the region note if it
1737 : already exists. */
1738 :
1739 : void
1740 508273 : make_reg_eh_region_note_nothrow_nononlocal (rtx_insn *insn)
1741 : {
1742 508273 : rtx note = find_reg_note (insn, REG_EH_REGION, NULL_RTX);
1743 508273 : rtx intmin = GEN_INT (INT_MIN);
1744 :
1745 508273 : if (note != 0)
1746 243582 : XEXP (note, 0) = intmin;
1747 : else
1748 264691 : add_reg_note (insn, REG_EH_REGION, intmin);
1749 508273 : }
1750 :
1751 : /* Return true if INSN could throw, assuming no REG_EH_REGION note
1752 : to the contrary. */
1753 :
1754 : bool
1755 3174245296 : insn_could_throw_p (const rtx_insn *insn)
1756 : {
1757 3174245296 : if (!flag_exceptions)
1758 : return false;
1759 2615445024 : if (CALL_P (insn))
1760 : return true;
1761 2240501537 : if (INSN_P (insn) && cfun->can_throw_non_call_exceptions)
1762 1898382153 : return may_trap_p (PATTERN (insn));
1763 : return false;
1764 : }
1765 :
1766 : /* Return true if a REG_EH_REGION note should be copied to INSN. Every
1767 : call needs it, even one that cannot throw: an INT_MIN note also says
1768 : the call cannot perform a nonlocal goto. */
1769 :
1770 : static bool
1771 55148 : copy_reg_eh_region_note_p (const rtx_insn *insn)
1772 : {
1773 55148 : return CALL_P (insn) || insn_could_throw_p (insn);
1774 : }
1775 :
1776 : /* Copy an REG_EH_REGION note to each insn that needs it, beginning
1777 : at FIRST and ending at LAST. NOTE_OR_INSN is either the source insn
1778 : to look for a note, or the note itself. */
1779 :
1780 : void
1781 2421227 : copy_reg_eh_region_note_forward (rtx note_or_insn, rtx_insn *first,
1782 : rtx_insn *last)
1783 : {
1784 2421227 : rtx note = note_or_insn;
1785 :
1786 2421227 : if (rtx_insn *insn = dyn_cast <rtx_insn *> (note_or_insn))
1787 : {
1788 2421227 : if (!INSN_P (insn))
1789 : return;
1790 :
1791 2336271 : note = find_reg_note (insn, REG_EH_REGION, NULL_RTX);
1792 2336271 : if (note == NULL)
1793 : return;
1794 : }
1795 42014 : note = XEXP (note, 0);
1796 :
1797 91673 : for (rtx_insn *insn = first; insn != last ; insn = NEXT_INSN (insn))
1798 49659 : if (!find_reg_note (insn, REG_EH_REGION, NULL_RTX)
1799 49659 : && copy_reg_eh_region_note_p (insn))
1800 12964 : add_reg_note (insn, REG_EH_REGION, note);
1801 : }
1802 :
1803 : /* Likewise, but iterate backward. */
1804 :
1805 : void
1806 2830 : copy_reg_eh_region_note_backward (rtx note_or_insn, rtx_insn *last,
1807 : rtx_insn *first)
1808 : {
1809 2830 : rtx note = note_or_insn;
1810 :
1811 2830 : if (rtx_insn *insn = dyn_cast <rtx_insn *> (note_or_insn))
1812 : {
1813 0 : if (!INSN_P (insn))
1814 : return;
1815 :
1816 0 : note = find_reg_note (insn, REG_EH_REGION, NULL_RTX);
1817 0 : if (note == NULL)
1818 : return;
1819 : }
1820 2830 : note = XEXP (note, 0);
1821 :
1822 8319 : for (rtx_insn *insn = last; insn != first; insn = PREV_INSN (insn))
1823 5489 : if (!find_reg_note (insn, REG_EH_REGION, NULL_RTX)
1824 5489 : && copy_reg_eh_region_note_p (insn))
1825 5259 : add_reg_note (insn, REG_EH_REGION, note);
1826 : }
1827 :
1828 :
1829 : /* Extract all EH information from INSN. Return true if the insn
1830 : was marked NOTHROW. */
1831 :
1832 : static bool
1833 3420473139 : get_eh_region_and_lp_from_rtx (const rtx_insn *insn, eh_region *pr,
1834 : eh_landing_pad *plp)
1835 : {
1836 3420473139 : rtx note;
1837 3420473139 : int lp_nr;
1838 :
1839 3420473139 : *pr = nullptr;
1840 3420473139 : *plp = nullptr;
1841 3420473139 : if (! INSN_P (insn))
1842 : return false;
1843 :
1844 3419920887 : rtx_sequence *seq = dyn_cast<rtx_sequence *> (PATTERN (insn));
1845 3419920887 : if (NONJUMP_INSN_P (insn) && seq)
1846 0 : insn = seq->insn (0);
1847 :
1848 3419920887 : note = find_reg_note (insn, REG_EH_REGION, NULL_RTX);
1849 3419920887 : if (!note)
1850 3170565766 : return !insn_could_throw_p (insn);
1851 :
1852 249355121 : lp_nr = INTVAL (XEXP (note, 0));
1853 249355121 : if (lp_nr == 0 || lp_nr == INT_MIN)
1854 : return true;
1855 :
1856 45601749 : if (lp_nr < 0)
1857 4710720 : *pr = (*cfun->eh->region_array)[-lp_nr];
1858 : else
1859 : {
1860 40891029 : *plp = (*cfun->eh->lp_array)[lp_nr];
1861 40891029 : *pr = (*plp)->region;
1862 : }
1863 :
1864 : return false;
1865 : }
1866 :
1867 : /* Return the landing pad to which INSN may go, or NULL if it does not
1868 : have a reachable landing pad within this function. */
1869 :
1870 : eh_landing_pad
1871 2176286013 : get_eh_landing_pad_from_rtx (const rtx_insn *insn)
1872 : {
1873 2176286013 : eh_landing_pad lp;
1874 2176286013 : eh_region r;
1875 :
1876 2176286013 : get_eh_region_and_lp_from_rtx (insn, &r, &lp);
1877 2176286013 : return lp;
1878 : }
1879 :
1880 : /* Return the region to which INSN may go, or NULL if it does not
1881 : have a reachable region within this function. */
1882 :
1883 : eh_region
1884 3678745 : get_eh_region_from_rtx (const rtx_insn *insn)
1885 : {
1886 3678745 : eh_landing_pad lp;
1887 3678745 : eh_region r;
1888 :
1889 3678745 : get_eh_region_and_lp_from_rtx (insn, &r, &lp);
1890 3678745 : return r;
1891 : }
1892 :
1893 : /* Return true if INSN throws and is caught by something in this function. */
1894 :
1895 : bool
1896 2137434590 : can_throw_internal (const rtx_insn *insn)
1897 : {
1898 2137434590 : return get_eh_landing_pad_from_rtx (insn) != NULL;
1899 : }
1900 :
1901 : /* Return true if INSN throws and escapes from the current function. */
1902 :
1903 : bool
1904 40361064 : can_throw_external (const rtx_insn *insn)
1905 : {
1906 40361064 : eh_landing_pad lp;
1907 40361064 : eh_region r;
1908 40361064 : bool nothrow;
1909 :
1910 40361064 : if (! INSN_P (insn))
1911 : return false;
1912 :
1913 12690606 : rtx_sequence *seq = dyn_cast<rtx_sequence *> (PATTERN (insn));
1914 12690606 : if (NONJUMP_INSN_P (insn) && seq)
1915 : {
1916 0 : int i, n = seq->len ();
1917 :
1918 0 : for (i = 0; i < n; i++)
1919 0 : if (can_throw_external (seq->insn (i)))
1920 : return true;
1921 :
1922 : return false;
1923 : }
1924 :
1925 12690606 : nothrow = get_eh_region_and_lp_from_rtx (insn, &r, &lp);
1926 :
1927 : /* If we can't throw, we obviously can't throw external. */
1928 12690606 : if (nothrow)
1929 : return false;
1930 :
1931 : /* If we have an internal landing pad, then we're not external. */
1932 653591 : if (lp != NULL)
1933 : return false;
1934 :
1935 : /* If we're not within an EH region, then we are external. */
1936 492313 : if (r == NULL)
1937 : return true;
1938 :
1939 : /* The only thing that ought to be left is MUST_NOT_THROW regions,
1940 : which don't always have landing pads. */
1941 17506 : gcc_assert (r->type == ERT_MUST_NOT_THROW);
1942 : return false;
1943 : }
1944 :
1945 : /* Return true if INSN cannot throw at all. */
1946 :
1947 : bool
1948 1214617952 : insn_nothrow_p (const rtx_insn *insn)
1949 : {
1950 1214617952 : eh_landing_pad lp;
1951 1214617952 : eh_region r;
1952 :
1953 1214617952 : if (! INSN_P (insn))
1954 : return true;
1955 :
1956 1214617952 : rtx_sequence *seq = dyn_cast<rtx_sequence *> (PATTERN (insn));
1957 1214617952 : if (NONJUMP_INSN_P (insn) && seq)
1958 : {
1959 0 : int i, n = seq->len ();
1960 :
1961 0 : for (i = 0; i < n; i++)
1962 0 : if (!insn_nothrow_p (seq->insn (i)))
1963 : return false;
1964 :
1965 : return true;
1966 : }
1967 :
1968 1214617952 : return get_eh_region_and_lp_from_rtx (insn, &r, &lp);
1969 : }
1970 :
1971 : /* Return true if INSN can perform a non-local goto. */
1972 : /* ??? This test is here in this file because it (ab)uses REG_EH_REGION. */
1973 :
1974 : bool
1975 409980970 : can_nonlocal_goto (const rtx_insn *insn)
1976 : {
1977 409980970 : if (nonlocal_goto_handler_labels && CALL_P (insn))
1978 : {
1979 89493 : rtx note = find_reg_note (insn, REG_EH_REGION, NULL_RTX);
1980 89493 : if (!note || INTVAL (XEXP (note, 0)) != INT_MIN)
1981 87871 : return true;
1982 : }
1983 : return false;
1984 : }
1985 :
1986 : /* Set TREE_NOTHROW and crtl->all_throwers_are_sibcalls. */
1987 :
1988 : static unsigned int
1989 1531124 : set_nothrow_function_flags (void)
1990 : {
1991 1531124 : rtx_insn *insn;
1992 :
1993 1531124 : crtl->nothrow = 1;
1994 :
1995 : /* Assume crtl->all_throwers_are_sibcalls until we encounter
1996 : something that can throw an exception. We specifically exempt
1997 : CALL_INSNs that are SIBLING_CALL_P, as these are really jumps,
1998 : and can't throw. Most CALL_INSNs are not SIBLING_CALL_P, so this
1999 : is optimistic. */
2000 :
2001 1531124 : crtl->all_throwers_are_sibcalls = 1;
2002 :
2003 : /* If we don't know that this implementation of the function will
2004 : actually be used, then we must not set TREE_NOTHROW, since
2005 : callers must not assume that this function does not throw. */
2006 1531124 : if (TREE_NOTHROW (current_function_decl))
2007 : return 0;
2008 :
2009 743918 : if (! flag_exceptions)
2010 : return 0;
2011 :
2012 39998342 : for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2013 39931784 : if (can_throw_external (insn))
2014 : {
2015 473168 : crtl->nothrow = 0;
2016 :
2017 473168 : auto call = dyn_cast<rtx_call_insn *> (insn);
2018 219530 : if (!call || !SIBLING_CALL_P (call))
2019 : {
2020 452933 : crtl->all_throwers_are_sibcalls = 0;
2021 452933 : return 0;
2022 : }
2023 : }
2024 :
2025 66558 : if (crtl->nothrow
2026 66558 : && (cgraph_node::get (current_function_decl)->get_availability ()
2027 : >= AVAIL_AVAILABLE))
2028 : {
2029 44350 : struct cgraph_node *node = cgraph_node::get (current_function_decl);
2030 44350 : struct cgraph_edge *e;
2031 57441 : for (e = node->callers; e; e = e->next_caller)
2032 13091 : e->can_throw_external = false;
2033 44350 : node->set_nothrow_flag (true);
2034 :
2035 44350 : if (dump_file)
2036 5 : fprintf (dump_file, "Marking function nothrow: %s\n\n",
2037 : current_function_name ());
2038 : }
2039 : return 0;
2040 : }
2041 :
2042 : namespace {
2043 :
2044 : const pass_data pass_data_set_nothrow_function_flags =
2045 : {
2046 : RTL_PASS, /* type */
2047 : "nothrow", /* name */
2048 : OPTGROUP_NONE, /* optinfo_flags */
2049 : TV_NONE, /* tv_id */
2050 : 0, /* properties_required */
2051 : 0, /* properties_provided */
2052 : 0, /* properties_destroyed */
2053 : 0, /* todo_flags_start */
2054 : 0, /* todo_flags_finish */
2055 : };
2056 :
2057 : class pass_set_nothrow_function_flags : public rtl_opt_pass
2058 : {
2059 : public:
2060 302985 : pass_set_nothrow_function_flags (gcc::context *ctxt)
2061 605970 : : rtl_opt_pass (pass_data_set_nothrow_function_flags, ctxt)
2062 : {}
2063 :
2064 : /* opt_pass methods: */
2065 1531124 : unsigned int execute (function *) final override
2066 : {
2067 1531124 : return set_nothrow_function_flags ();
2068 : }
2069 :
2070 : }; // class pass_set_nothrow_function_flags
2071 :
2072 : } // anon namespace
2073 :
2074 : rtl_opt_pass *
2075 302985 : make_pass_set_nothrow_function_flags (gcc::context *ctxt)
2076 : {
2077 302985 : return new pass_set_nothrow_function_flags (ctxt);
2078 : }
2079 :
2080 :
2081 : /* Various hooks for unwind library. */
2082 :
2083 : /* Expand the EH support builtin functions:
2084 : __builtin_eh_pointer and __builtin_eh_filter. */
2085 :
2086 : static eh_region
2087 316988 : expand_builtin_eh_common (tree region_nr_t)
2088 : {
2089 316988 : HOST_WIDE_INT region_nr;
2090 316988 : eh_region region;
2091 :
2092 316988 : gcc_assert (tree_fits_shwi_p (region_nr_t));
2093 316988 : region_nr = tree_to_shwi (region_nr_t);
2094 :
2095 316988 : region = (*cfun->eh->region_array)[region_nr];
2096 :
2097 : /* ??? We shouldn't have been able to delete a eh region without
2098 : deleting all the code that depended on it. */
2099 316988 : gcc_assert (region != NULL);
2100 :
2101 316988 : return region;
2102 : }
2103 :
2104 : /* Expand to the exc_ptr value from the given eh region. */
2105 :
2106 : rtx
2107 103206 : expand_builtin_eh_pointer (tree exp)
2108 : {
2109 103206 : eh_region region
2110 103206 : = expand_builtin_eh_common (CALL_EXPR_ARG (exp, 0));
2111 103206 : if (region->exc_ptr_reg == NULL)
2112 67169 : region->exc_ptr_reg = gen_reg_rtx (ptr_mode);
2113 103206 : return region->exc_ptr_reg;
2114 : }
2115 :
2116 : /* Expand to the filter value from the given eh region. */
2117 :
2118 : rtx
2119 7146 : expand_builtin_eh_filter (tree exp)
2120 : {
2121 7146 : eh_region region
2122 7146 : = expand_builtin_eh_common (CALL_EXPR_ARG (exp, 0));
2123 7146 : if (region->filter_reg == NULL)
2124 5560 : region->filter_reg = gen_reg_rtx (targetm.eh_return_filter_mode ());
2125 7146 : return region->filter_reg;
2126 : }
2127 :
2128 : /* Copy the exc_ptr and filter values from one landing pad's registers
2129 : to another. This is used to inline the resx statement. */
2130 :
2131 : rtx
2132 103318 : expand_builtin_eh_copy_values (tree exp)
2133 : {
2134 103318 : eh_region dst
2135 103318 : = expand_builtin_eh_common (CALL_EXPR_ARG (exp, 0));
2136 103318 : eh_region src
2137 103318 : = expand_builtin_eh_common (CALL_EXPR_ARG (exp, 1));
2138 103318 : scalar_int_mode fmode = targetm.eh_return_filter_mode ();
2139 :
2140 103318 : if (dst->exc_ptr_reg == NULL)
2141 75694 : dst->exc_ptr_reg = gen_reg_rtx (ptr_mode);
2142 103318 : if (src->exc_ptr_reg == NULL)
2143 56438 : src->exc_ptr_reg = gen_reg_rtx (ptr_mode);
2144 :
2145 103318 : if (dst->filter_reg == NULL)
2146 75696 : dst->filter_reg = gen_reg_rtx (fmode);
2147 103318 : if (src->filter_reg == NULL)
2148 55716 : src->filter_reg = gen_reg_rtx (fmode);
2149 :
2150 103318 : emit_move_insn (dst->exc_ptr_reg, src->exc_ptr_reg);
2151 103318 : emit_move_insn (dst->filter_reg, src->filter_reg);
2152 :
2153 103318 : return const0_rtx;
2154 : }
2155 :
2156 : /* Do any necessary initialization to access arbitrary stack frames.
2157 : On the SPARC, this means flushing the register windows. */
2158 :
2159 : void
2160 34 : expand_builtin_unwind_init (void)
2161 : {
2162 : /* Set this so all the registers get saved in our frame; we need to be
2163 : able to copy the saved values for any registers from frames we unwind. */
2164 34 : crtl->saves_all_registers = 1;
2165 :
2166 34 : SETUP_FRAME_ADDRESSES ();
2167 34 : }
2168 :
2169 : /* Map a non-negative number to an eh return data register number; expands
2170 : to -1 if no return data register is associated with the input number.
2171 : At least the inputs 0 and 1 must be mapped; the target may provide more. */
2172 :
2173 : rtx
2174 21 : expand_builtin_eh_return_data_regno (tree exp)
2175 : {
2176 21 : tree which = CALL_EXPR_ARG (exp, 0);
2177 21 : unsigned HOST_WIDE_INT iwhich;
2178 :
2179 21 : if (TREE_CODE (which) != INTEGER_CST)
2180 : {
2181 0 : error ("argument of %<__builtin_eh_return_regno%> must be constant");
2182 0 : return constm1_rtx;
2183 : }
2184 :
2185 21 : if (!tree_fits_uhwi_p (which))
2186 1 : return constm1_rtx;
2187 :
2188 20 : iwhich = tree_to_uhwi (which);
2189 20 : iwhich = EH_RETURN_DATA_REGNO (iwhich);
2190 20 : if (iwhich == INVALID_REGNUM)
2191 0 : return constm1_rtx;
2192 :
2193 : #ifdef DWARF_FRAME_REGNUM
2194 20 : iwhich = DWARF_FRAME_REGNUM (iwhich);
2195 : #else
2196 : iwhich = DEBUGGER_REGNO (iwhich);
2197 : #endif
2198 :
2199 20 : return GEN_INT (iwhich);
2200 : }
2201 :
2202 : /* Given a value extracted from the return address register or stack slot,
2203 : return the actual address encoded in that value. */
2204 :
2205 : rtx
2206 2352 : expand_builtin_extract_return_addr (tree addr_tree)
2207 : {
2208 2668 : rtx addr = expand_expr (addr_tree, NULL_RTX, Pmode, EXPAND_NORMAL);
2209 :
2210 2352 : if (GET_MODE (addr) != Pmode
2211 2352 : && GET_MODE (addr) != VOIDmode)
2212 : {
2213 : #ifdef POINTERS_EXTEND_UNSIGNED
2214 0 : addr = convert_memory_address (Pmode, addr);
2215 : #else
2216 : addr = convert_to_mode (Pmode, addr, 0);
2217 : #endif
2218 : }
2219 :
2220 : /* First mask out any unwanted bits. */
2221 2352 : rtx mask = MASK_RETURN_ADDR;
2222 2352 : if (mask)
2223 : expand_and (Pmode, addr, mask, addr);
2224 :
2225 : /* Then adjust to find the real return address. */
2226 2352 : if (RETURN_ADDR_OFFSET)
2227 : addr = plus_constant (Pmode, addr, RETURN_ADDR_OFFSET);
2228 :
2229 2352 : return addr;
2230 : }
2231 :
2232 : /* Given an actual address in addr_tree, do any necessary encoding
2233 : and return the value to be stored in the return address register or
2234 : stack slot so the epilogue will return to that address. */
2235 :
2236 : rtx
2237 19 : expand_builtin_frob_return_addr (tree addr_tree)
2238 : {
2239 19 : rtx addr = expand_expr (addr_tree, NULL_RTX, ptr_mode, EXPAND_NORMAL);
2240 :
2241 27 : addr = convert_memory_address (Pmode, addr);
2242 :
2243 19 : if (RETURN_ADDR_OFFSET)
2244 : {
2245 : addr = force_reg (Pmode, addr);
2246 : addr = plus_constant (Pmode, addr, -RETURN_ADDR_OFFSET);
2247 : }
2248 :
2249 19 : return addr;
2250 : }
2251 :
2252 : /* Set up the epilogue with the magic bits we'll need to return to the
2253 : exception handler. */
2254 :
2255 : void
2256 31 : expand_builtin_eh_return (tree stackadj_tree ATTRIBUTE_UNUSED,
2257 : tree handler_tree)
2258 : {
2259 31 : rtx tmp;
2260 :
2261 : #ifdef EH_RETURN_STACKADJ_RTX
2262 31 : tmp = expand_expr (stackadj_tree, crtl->eh.ehr_stackadj,
2263 : VOIDmode, EXPAND_NORMAL);
2264 39 : tmp = convert_memory_address (Pmode, tmp);
2265 31 : if (!crtl->eh.ehr_stackadj)
2266 31 : crtl->eh.ehr_stackadj = copy_addr_to_reg (tmp);
2267 0 : else if (tmp != crtl->eh.ehr_stackadj)
2268 0 : emit_move_insn (crtl->eh.ehr_stackadj, tmp);
2269 : #endif
2270 :
2271 31 : tmp = expand_expr (handler_tree, crtl->eh.ehr_handler,
2272 : VOIDmode, EXPAND_NORMAL);
2273 39 : tmp = convert_memory_address (Pmode, tmp);
2274 31 : if (!crtl->eh.ehr_handler)
2275 31 : crtl->eh.ehr_handler = copy_addr_to_reg (tmp);
2276 0 : else if (tmp != crtl->eh.ehr_handler)
2277 0 : emit_move_insn (crtl->eh.ehr_handler, tmp);
2278 :
2279 31 : if (!crtl->eh.ehr_label)
2280 31 : crtl->eh.ehr_label = gen_label_rtx ();
2281 31 : emit_jump (crtl->eh.ehr_label);
2282 31 : }
2283 :
2284 : /* Expand __builtin_eh_return. This exit path from the function loads up
2285 : the eh return data registers, adjusts the stack, and branches to a
2286 : given PC other than the normal return address. */
2287 :
2288 : void
2289 1531888 : expand_eh_return (void)
2290 : {
2291 1531888 : rtx_code_label *around_label;
2292 :
2293 1531888 : if (! crtl->eh.ehr_label)
2294 : return;
2295 :
2296 31 : crtl->calls_eh_return = 1;
2297 :
2298 : #ifdef EH_RETURN_STACKADJ_RTX
2299 39 : emit_move_insn (EH_RETURN_STACKADJ_RTX, const0_rtx);
2300 : #endif
2301 :
2302 : #ifdef EH_RETURN_TAKEN_RTX
2303 : emit_move_insn (EH_RETURN_TAKEN_RTX, const0_rtx);
2304 : #endif
2305 :
2306 31 : around_label = gen_label_rtx ();
2307 31 : emit_jump (around_label);
2308 :
2309 31 : emit_label (crtl->eh.ehr_label);
2310 31 : clobber_return_register ();
2311 :
2312 : #ifdef EH_RETURN_STACKADJ_RTX
2313 39 : emit_move_insn (EH_RETURN_STACKADJ_RTX, crtl->eh.ehr_stackadj);
2314 : #endif
2315 :
2316 : #ifdef EH_RETURN_TAKEN_RTX
2317 : emit_move_insn (EH_RETURN_TAKEN_RTX, const1_rtx);
2318 : #endif
2319 :
2320 31 : if (targetm.have_eh_return ())
2321 31 : emit_insn (targetm.gen_eh_return (crtl->eh.ehr_handler));
2322 : else
2323 : {
2324 0 : if (rtx handler = EH_RETURN_HANDLER_RTX)
2325 : emit_move_insn (handler, crtl->eh.ehr_handler);
2326 : else
2327 0 : error ("%<__builtin_eh_return%> not supported on this target");
2328 : }
2329 :
2330 : #ifdef EH_RETURN_TAKEN_RTX
2331 : rtx_code_label *eh_done_label = gen_label_rtx ();
2332 : emit_jump (eh_done_label);
2333 : #endif
2334 :
2335 31 : emit_label (around_label);
2336 :
2337 : #ifdef EH_RETURN_TAKEN_RTX
2338 : for (rtx tmp : { EH_RETURN_STACKADJ_RTX, EH_RETURN_HANDLER_RTX })
2339 : if (tmp && REG_P (tmp))
2340 : emit_clobber (tmp);
2341 : emit_label (eh_done_label);
2342 : #endif
2343 : }
2344 :
2345 : /* Convert a ptr_mode address ADDR_TREE to a Pmode address controlled by
2346 : POINTERS_EXTEND_UNSIGNED and return it. */
2347 :
2348 : rtx
2349 2 : expand_builtin_extend_pointer (tree addr_tree)
2350 : {
2351 2 : rtx addr = expand_expr (addr_tree, NULL_RTX, ptr_mode, EXPAND_NORMAL);
2352 2 : int extend;
2353 :
2354 : #ifdef POINTERS_EXTEND_UNSIGNED
2355 2 : extend = POINTERS_EXTEND_UNSIGNED;
2356 : #else
2357 : /* The previous EH code did an unsigned extend by default, so we do this also
2358 : for consistency. */
2359 : extend = 1;
2360 : #endif
2361 :
2362 2 : return convert_modes (targetm.unwind_word_mode (), ptr_mode, addr, extend);
2363 : }
2364 :
2365 : static int
2366 381450 : add_action_record (action_hash_type *ar_hash, int filter, int next)
2367 : {
2368 381450 : struct action_record **slot, *new_ar, tmp;
2369 :
2370 381450 : tmp.filter = filter;
2371 381450 : tmp.next = next;
2372 381450 : slot = ar_hash->find_slot (&tmp, INSERT);
2373 :
2374 381450 : if ((new_ar = *slot) == NULL)
2375 : {
2376 27538 : new_ar = XNEW (struct action_record);
2377 27538 : new_ar->offset = crtl->eh.action_record_data->length () + 1;
2378 27538 : new_ar->filter = filter;
2379 27538 : new_ar->next = next;
2380 27538 : *slot = new_ar;
2381 :
2382 : /* The filter value goes in untouched. The link to the next
2383 : record is a "self-relative" byte offset, or zero to indicate
2384 : that there is no next record. So convert the absolute 1 based
2385 : indices we've been carrying around into a displacement. */
2386 :
2387 27538 : push_sleb128 (&crtl->eh.action_record_data, filter);
2388 27538 : if (next)
2389 5642 : next -= crtl->eh.action_record_data->length () + 1;
2390 27538 : push_sleb128 (&crtl->eh.action_record_data, next);
2391 : }
2392 :
2393 381450 : return new_ar->offset;
2394 : }
2395 :
2396 : static int
2397 25517341 : collect_one_action_chain (action_hash_type *ar_hash, eh_region region)
2398 : {
2399 25517341 : int next;
2400 :
2401 : /* If we've reached the top of the region chain, then we have
2402 : no actions, and require no landing pad. */
2403 25517341 : if (region == NULL)
2404 : return -1;
2405 :
2406 25176829 : switch (region->type)
2407 : {
2408 24765278 : case ERT_CLEANUP:
2409 24765278 : {
2410 24765278 : eh_region r;
2411 : /* A cleanup adds a zero filter to the beginning of the chain, but
2412 : there are special cases to look out for. If there are *only*
2413 : cleanups along a path, then it compresses to a zero action.
2414 : Further, if there are multiple cleanups along a path, we only
2415 : need to represent one of them, as that is enough to trigger
2416 : entry to the landing pad at runtime. */
2417 24765278 : next = collect_one_action_chain (ar_hash, region->outer);
2418 24765278 : if (next <= 0)
2419 : return 0;
2420 76624 : for (r = region->outer; r ; r = r->outer)
2421 63397 : if (r->type == ERT_CLEANUP)
2422 : return next;
2423 13227 : return add_action_record (ar_hash, 0, next);
2424 : }
2425 :
2426 354651 : case ERT_TRY:
2427 354651 : {
2428 354651 : eh_catch c;
2429 :
2430 : /* Process the associated catch regions in reverse order.
2431 : If there's a catch-all handler, then we don't need to
2432 : search outer regions. Use a magic -3 value to record
2433 : that we haven't done the outer search. */
2434 354651 : next = -3;
2435 717063 : for (c = region->u.eh_try.last_catch; c ; c = c->prev_catch)
2436 : {
2437 362412 : if (c->type_list == NULL)
2438 : {
2439 : /* Retrieve the filter from the head of the filter list
2440 : where we have stored it (see assign_filter_values). */
2441 337575 : int filter = TREE_INT_CST_LOW (TREE_VALUE (c->filter_list));
2442 337575 : next = add_action_record (ar_hash, filter, 0);
2443 : }
2444 : else
2445 : {
2446 : /* Once the outer search is done, trigger an action record for
2447 : each filter we have. */
2448 24837 : tree flt_node;
2449 :
2450 24837 : if (next == -3)
2451 : {
2452 17076 : next = collect_one_action_chain (ar_hash, region->outer);
2453 :
2454 : /* If there is no next action, terminate the chain. */
2455 17076 : if (next == -1)
2456 : next = 0;
2457 : /* If all outer actions are cleanups or must_not_throw,
2458 : we'll have no action record for it, since we had wanted
2459 : to encode these states in the call-site record directly.
2460 : Add a cleanup action to the chain to catch these. */
2461 10165 : else if (next <= 0)
2462 5284 : next = add_action_record (ar_hash, 0, 0);
2463 : }
2464 :
2465 24837 : flt_node = c->filter_list;
2466 49674 : for (; flt_node; flt_node = TREE_CHAIN (flt_node))
2467 : {
2468 24837 : int filter = TREE_INT_CST_LOW (TREE_VALUE (flt_node));
2469 24837 : next = add_action_record (ar_hash, filter, next);
2470 : }
2471 : }
2472 : }
2473 : return next;
2474 : }
2475 :
2476 495 : case ERT_ALLOWED_EXCEPTIONS:
2477 : /* An exception specification adds its filter to the
2478 : beginning of the chain. */
2479 495 : next = collect_one_action_chain (ar_hash, region->outer);
2480 :
2481 : /* If there is no next action, terminate the chain. */
2482 495 : if (next == -1)
2483 : next = 0;
2484 : /* If all outer actions are cleanups or must_not_throw,
2485 : we'll have no action record for it, since we had wanted
2486 : to encode these states in the call-site record directly.
2487 : Add a cleanup action to the chain to catch these. */
2488 41 : else if (next <= 0)
2489 32 : next = add_action_record (ar_hash, 0, 0);
2490 :
2491 495 : return add_action_record (ar_hash, region->u.allowed.filter, next);
2492 :
2493 : case ERT_MUST_NOT_THROW:
2494 : /* A must-not-throw region with no inner handlers or cleanups
2495 : requires no call-site entry. Note that this differs from
2496 : the no handler or cleanup case in that we do require an lsda
2497 : to be generated. Return a magic -2 value to record this. */
2498 : return -2;
2499 : }
2500 :
2501 0 : gcc_unreachable ();
2502 : }
2503 :
2504 : static int
2505 428427 : add_call_site (rtx landing_pad, int action, int section)
2506 : {
2507 428427 : call_site_record record;
2508 :
2509 428427 : record = ggc_alloc<call_site_record_d> ();
2510 428427 : record->landing_pad = landing_pad;
2511 428427 : record->action = action;
2512 :
2513 428427 : vec_safe_push (crtl->eh.call_site_record_v[section], record);
2514 :
2515 428427 : return call_site_base + crtl->eh.call_site_record_v[section]->length () - 1;
2516 : }
2517 :
2518 : static rtx_note *
2519 428427 : emit_note_eh_region_end (rtx_insn *insn)
2520 : {
2521 0 : return emit_note_after (NOTE_INSN_EH_REGION_END, insn);
2522 : }
2523 :
2524 : /* Add NOP after NOTE_INSN_SWITCH_TEXT_SECTIONS when the cold section starts
2525 : with landing pad.
2526 : With landing pad being at offset 0 from the start label of the section
2527 : we would miss EH delivery because 0 is special and means no landing pad. */
2528 :
2529 : static bool
2530 66025 : maybe_add_nop_after_section_switch (void)
2531 : {
2532 66025 : if (!crtl->uses_eh_lsda
2533 65965 : || !crtl->eh.call_site_record_v[1])
2534 : return false;
2535 13958 : int n = vec_safe_length (crtl->eh.call_site_record_v[1]);
2536 13958 : hash_set<rtx_insn *> visited;
2537 :
2538 67965 : for (int i = 0; i < n; ++i)
2539 : {
2540 40049 : struct call_site_record_d *cs
2541 40049 : = (*crtl->eh.call_site_record_v[1])[i];
2542 40049 : if (cs->landing_pad)
2543 : {
2544 21289 : rtx_insn *insn = as_a <rtx_insn *> (cs->landing_pad);
2545 352127 : while (true)
2546 : {
2547 : /* Landing pads have LABEL_PRESERVE_P flag set. This check make
2548 : sure that we do not walk past landing pad visited earlier
2549 : which would result in possible quadratic behaviour. */
2550 21289 : if (LABEL_P (insn) && LABEL_PRESERVE_P (insn)
2551 207997 : && visited.add (insn))
2552 : break;
2553 :
2554 : /* Conservatively assume that ASM insn may be empty. We have
2555 : now way to tell what they contain. */
2556 184274 : if (active_insn_p (insn)
2557 18499 : && GET_CODE (PATTERN (insn)) != ASM_INPUT
2558 202773 : && GET_CODE (PATTERN (insn)) != ASM_OPERANDS)
2559 : break;
2560 :
2561 : /* If we reached the start of hot section, then NOP will be
2562 : needed. */
2563 165775 : if (GET_CODE (insn) == NOTE
2564 128421 : && NOTE_KIND (insn) == NOTE_INSN_SWITCH_TEXT_SECTIONS)
2565 : {
2566 356 : emit_insn_after (gen_nop (), insn);
2567 356 : break;
2568 : }
2569 :
2570 : /* We visit only labels from cold section. We should never hit
2571 : beginning of the insn stream here. */
2572 165419 : insn = PREV_INSN (insn);
2573 165419 : }
2574 : }
2575 : }
2576 13958 : return false;
2577 13958 : }
2578 :
2579 : /* Turn REG_EH_REGION notes back into NOTE_INSN_EH_REGION notes.
2580 : The new note numbers will not refer to region numbers, but
2581 : instead to call site entries. */
2582 :
2583 : static unsigned int
2584 66025 : convert_to_eh_region_ranges (void)
2585 : {
2586 66025 : rtx_insn *insn;
2587 66025 : rtx_insn *iter;
2588 66025 : rtx_note *note;
2589 66025 : action_hash_type ar_hash (31);
2590 66025 : int last_action = -3;
2591 66025 : rtx_insn *last_action_insn = NULL;
2592 66025 : rtx last_landing_pad = NULL_RTX;
2593 66025 : rtx_insn *first_no_action_insn = NULL;
2594 66025 : int call_site = 0;
2595 66025 : int cur_sec = 0;
2596 66025 : rtx_insn *section_switch_note = NULL;
2597 66025 : rtx_insn *first_no_action_insn_before_switch = NULL;
2598 66025 : rtx_insn *last_no_action_insn_before_switch = NULL;
2599 66025 : int saved_call_site_base = call_site_base;
2600 :
2601 66025 : vec_alloc (crtl->eh.action_record_data, 64);
2602 :
2603 60234549 : for (iter = get_insns (); iter ; iter = NEXT_INSN (iter))
2604 60168524 : if (INSN_P (iter))
2605 : {
2606 13199823 : eh_landing_pad lp;
2607 13199823 : eh_region region;
2608 13199823 : bool nothrow;
2609 13199823 : int this_action;
2610 13199823 : rtx_code_label *this_landing_pad;
2611 :
2612 13199823 : insn = iter;
2613 13199823 : rtx_sequence *seq = dyn_cast<rtx_sequence *> (PATTERN (insn));
2614 13199823 : if (NONJUMP_INSN_P (insn) && seq)
2615 0 : insn = seq->insn (0);
2616 :
2617 13199823 : nothrow = get_eh_region_and_lp_from_rtx (insn, ®ion, &lp);
2618 13199823 : if (nothrow)
2619 12205243 : continue;
2620 994580 : if (region)
2621 734492 : this_action = collect_one_action_chain (&ar_hash, region);
2622 : else
2623 : this_action = -1;
2624 :
2625 : /* Existence of catch handlers, or must-not-throw regions
2626 : implies that an lsda is needed (even if empty). */
2627 734492 : if (this_action != -1)
2628 734492 : crtl->uses_eh_lsda = 1;
2629 :
2630 : /* Delay creation of region notes for no-action regions
2631 : until we're sure that an lsda will be required. */
2632 260088 : else if (last_action == -3)
2633 : {
2634 28970 : first_no_action_insn = iter;
2635 28970 : last_action = -1;
2636 : }
2637 :
2638 994580 : if (this_action >= 0)
2639 680145 : this_landing_pad = lp->landing_pad;
2640 : else
2641 : this_landing_pad = NULL;
2642 :
2643 : /* Differing actions or landing pads implies a change in call-site
2644 : info, which implies some EH_REGION note should be emitted. */
2645 994580 : if (last_action != this_action
2646 994580 : || last_landing_pad != this_landing_pad)
2647 : {
2648 : /* If there is a queued no-action region in the other section
2649 : with hot/cold partitioning, emit it now. */
2650 431668 : if (first_no_action_insn_before_switch)
2651 : {
2652 574 : gcc_assert (this_action != -1
2653 : && last_action == (first_no_action_insn
2654 : ? -1 : -3));
2655 326 : call_site = add_call_site (NULL_RTX, 0, 0);
2656 326 : note = emit_note_before (NOTE_INSN_EH_REGION_BEG,
2657 : first_no_action_insn_before_switch);
2658 326 : NOTE_EH_HANDLER (note) = call_site;
2659 326 : note
2660 326 : = emit_note_eh_region_end (last_no_action_insn_before_switch);
2661 326 : NOTE_EH_HANDLER (note) = call_site;
2662 326 : gcc_assert (last_action != -3
2663 : || (last_action_insn
2664 : == last_no_action_insn_before_switch));
2665 326 : first_no_action_insn_before_switch = NULL;
2666 326 : last_no_action_insn_before_switch = NULL;
2667 326 : call_site_base++;
2668 : }
2669 : /* If we'd not seen a previous action (-3) or the previous
2670 : action was must-not-throw (-2), then we do not need an
2671 : end note. */
2672 431668 : if (last_action >= -1)
2673 : {
2674 : /* If we delayed the creation of the begin, do it now. */
2675 372250 : if (first_no_action_insn)
2676 : {
2677 28610 : call_site = add_call_site (NULL_RTX, 0, cur_sec);
2678 28610 : note = emit_note_before (NOTE_INSN_EH_REGION_BEG,
2679 : first_no_action_insn);
2680 28610 : NOTE_EH_HANDLER (note) = call_site;
2681 28610 : first_no_action_insn = NULL;
2682 : }
2683 :
2684 372250 : note = emit_note_eh_region_end (last_action_insn);
2685 372250 : NOTE_EH_HANDLER (note) = call_site;
2686 : }
2687 :
2688 : /* If the new action is must-not-throw, then no region notes
2689 : are created. */
2690 431668 : if (this_action >= -1)
2691 : {
2692 399491 : call_site = add_call_site (this_landing_pad,
2693 : this_action < 0 ? 0 : this_action,
2694 : cur_sec);
2695 399491 : note = emit_note_before (NOTE_INSN_EH_REGION_BEG, iter);
2696 399491 : NOTE_EH_HANDLER (note) = call_site;
2697 : }
2698 :
2699 : last_action = this_action;
2700 : last_landing_pad = this_landing_pad;
2701 : }
2702 994580 : last_action_insn = iter;
2703 : }
2704 46968701 : else if (NOTE_P (iter)
2705 44529767 : && NOTE_KIND (iter) == NOTE_INSN_SWITCH_TEXT_SECTIONS)
2706 : {
2707 13970 : gcc_assert (section_switch_note == NULL_RTX);
2708 13970 : gcc_assert (flag_reorder_blocks_and_partition);
2709 13970 : section_switch_note = iter;
2710 13970 : if (first_no_action_insn)
2711 : {
2712 326 : first_no_action_insn_before_switch = first_no_action_insn;
2713 326 : last_no_action_insn_before_switch = last_action_insn;
2714 326 : first_no_action_insn = NULL;
2715 326 : gcc_assert (last_action == -1);
2716 : last_action = -3;
2717 : }
2718 : /* Force closing of current EH region before section switch and
2719 : opening a new one afterwards. */
2720 13644 : else if (last_action != -3)
2721 12864 : last_landing_pad = pc_rtx;
2722 13970 : if (crtl->eh.call_site_record_v[cur_sec])
2723 12752 : call_site_base += crtl->eh.call_site_record_v[cur_sec]->length ();
2724 13970 : cur_sec++;
2725 13970 : gcc_assert (crtl->eh.call_site_record_v[cur_sec] == NULL);
2726 13970 : vec_alloc (crtl->eh.call_site_record_v[cur_sec], 10);
2727 : }
2728 :
2729 66025 : if (last_action >= -1 && ! first_no_action_insn)
2730 : {
2731 55851 : note = emit_note_eh_region_end (last_action_insn);
2732 55851 : NOTE_EH_HANDLER (note) = call_site;
2733 : }
2734 :
2735 66025 : call_site_base = saved_call_site_base;
2736 :
2737 132050 : return 0;
2738 66025 : }
2739 :
2740 : namespace {
2741 :
2742 : const pass_data pass_data_convert_to_eh_region_ranges =
2743 : {
2744 : RTL_PASS, /* type */
2745 : "eh_ranges", /* name */
2746 : OPTGROUP_NONE, /* optinfo_flags */
2747 : TV_NONE, /* tv_id */
2748 : 0, /* properties_required */
2749 : 0, /* properties_provided */
2750 : 0, /* properties_destroyed */
2751 : 0, /* todo_flags_start */
2752 : 0, /* todo_flags_finish */
2753 : };
2754 :
2755 : class pass_convert_to_eh_region_ranges : public rtl_opt_pass
2756 : {
2757 : public:
2758 302985 : pass_convert_to_eh_region_ranges (gcc::context *ctxt)
2759 605970 : : rtl_opt_pass (pass_data_convert_to_eh_region_ranges, ctxt)
2760 : {}
2761 :
2762 : /* opt_pass methods: */
2763 : bool gate (function *) final override;
2764 66025 : unsigned int execute (function *) final override
2765 : {
2766 66025 : int ret = convert_to_eh_region_ranges ();
2767 66025 : maybe_add_nop_after_section_switch ();
2768 66025 : return ret;
2769 : }
2770 :
2771 : }; // class pass_convert_to_eh_region_ranges
2772 :
2773 : bool
2774 1531131 : pass_convert_to_eh_region_ranges::gate (function *)
2775 : {
2776 : /* Nothing to do for SJLJ exceptions or if no regions created. */
2777 1531131 : if (cfun->eh->region_tree == NULL)
2778 : return false;
2779 66025 : if (targetm_common.except_unwind_info (&global_options) == UI_SJLJ)
2780 0 : return false;
2781 : return true;
2782 : }
2783 :
2784 : } // anon namespace
2785 :
2786 : rtl_opt_pass *
2787 302985 : make_pass_convert_to_eh_region_ranges (gcc::context *ctxt)
2788 : {
2789 302985 : return new pass_convert_to_eh_region_ranges (ctxt);
2790 : }
2791 :
2792 : static void
2793 128 : push_uleb128 (vec<uchar, va_gc> **data_area, unsigned int value)
2794 : {
2795 128 : do
2796 : {
2797 128 : unsigned char byte = value & 0x7f;
2798 128 : value >>= 7;
2799 128 : if (value)
2800 0 : byte |= 0x80;
2801 128 : vec_safe_push (*data_area, byte);
2802 : }
2803 128 : while (value);
2804 128 : }
2805 :
2806 : static void
2807 55076 : push_sleb128 (vec<uchar, va_gc> **data_area, int value)
2808 : {
2809 55076 : unsigned char byte;
2810 55076 : int more;
2811 :
2812 55076 : do
2813 : {
2814 55076 : byte = value & 0x7f;
2815 55076 : value >>= 7;
2816 55076 : more = ! ((value == 0 && (byte & 0x40) == 0)
2817 5878 : || (value == -1 && (byte & 0x40) != 0));
2818 : if (more)
2819 0 : byte |= 0x80;
2820 55076 : vec_safe_push (*data_area, byte);
2821 : }
2822 55076 : while (more);
2823 55076 : }
2824 :
2825 :
2826 : static int
2827 0 : dw2_size_of_call_site_table (int section)
2828 : {
2829 0 : int n = vec_safe_length (crtl->eh.call_site_record_v[section]);
2830 0 : int size = n * (4 + 4 + 4);
2831 0 : int i;
2832 :
2833 0 : for (i = 0; i < n; ++i)
2834 : {
2835 0 : struct call_site_record_d *cs =
2836 0 : (*crtl->eh.call_site_record_v[section])[i];
2837 0 : size += size_of_uleb128 (cs->action);
2838 : }
2839 :
2840 0 : return size;
2841 : }
2842 :
2843 : static int
2844 0 : sjlj_size_of_call_site_table (void)
2845 : {
2846 0 : int n = vec_safe_length (crtl->eh.call_site_record_v[0]);
2847 0 : int size = 0;
2848 0 : int i;
2849 :
2850 0 : for (i = 0; i < n; ++i)
2851 : {
2852 0 : struct call_site_record_d *cs =
2853 0 : (*crtl->eh.call_site_record_v[0])[i];
2854 0 : size += size_of_uleb128 (INTVAL (cs->landing_pad));
2855 0 : size += size_of_uleb128 (cs->action);
2856 : }
2857 :
2858 0 : return size;
2859 : }
2860 :
2861 : static void
2862 79923 : dw2_output_call_site_table (int cs_format, int section)
2863 : {
2864 79923 : int n = vec_safe_length (crtl->eh.call_site_record_v[section]);
2865 79923 : int i;
2866 79923 : const char *begin;
2867 :
2868 79923 : if (section == 0)
2869 65965 : begin = current_function_func_begin_label;
2870 13958 : else if (first_function_block_is_cold)
2871 0 : begin = crtl->subsections.hot_section_label;
2872 : else
2873 13958 : begin = crtl->subsections.cold_section_label;
2874 :
2875 508350 : for (i = 0; i < n; ++i)
2876 : {
2877 428427 : struct call_site_record_d *cs = (*crtl->eh.call_site_record_v[section])[i];
2878 428427 : char reg_start_lab[32];
2879 428427 : char reg_end_lab[32];
2880 428427 : char landing_pad_lab[32];
2881 :
2882 428427 : ASM_GENERATE_INTERNAL_LABEL (reg_start_lab, "LEHB", call_site_base + i);
2883 428427 : ASM_GENERATE_INTERNAL_LABEL (reg_end_lab, "LEHE", call_site_base + i);
2884 :
2885 428427 : if (cs->landing_pad)
2886 283235 : ASM_GENERATE_INTERNAL_LABEL (landing_pad_lab, "L",
2887 : CODE_LABEL_NUMBER (cs->landing_pad));
2888 :
2889 : /* ??? Perhaps use insn length scaling if the assembler supports
2890 : generic arithmetic. */
2891 : /* ??? Perhaps use attr_length to choose data1 or data2 instead of
2892 : data4 if the function is small enough. */
2893 428427 : if (cs_format == DW_EH_PE_uleb128)
2894 : {
2895 428427 : dw2_asm_output_delta_uleb128 (reg_start_lab, begin,
2896 : "region %d start", i);
2897 428427 : dw2_asm_output_delta_uleb128 (reg_end_lab, reg_start_lab,
2898 : "length");
2899 428427 : if (cs->landing_pad)
2900 283235 : dw2_asm_output_delta_uleb128 (landing_pad_lab, begin,
2901 : "landing pad");
2902 : else
2903 145192 : dw2_asm_output_data_uleb128 (0, "landing pad");
2904 : }
2905 : else
2906 : {
2907 0 : dw2_asm_output_delta (4, reg_start_lab, begin,
2908 : "region %d start", i);
2909 0 : dw2_asm_output_delta (4, reg_end_lab, reg_start_lab, "length");
2910 0 : if (cs->landing_pad)
2911 0 : dw2_asm_output_delta (4, landing_pad_lab, begin,
2912 : "landing pad");
2913 : else
2914 0 : dw2_asm_output_data (4, 0, "landing pad");
2915 : }
2916 428427 : dw2_asm_output_data_uleb128 (cs->action, "action");
2917 : }
2918 :
2919 79923 : call_site_base += n;
2920 79923 : }
2921 :
2922 : static void
2923 0 : sjlj_output_call_site_table (void)
2924 : {
2925 0 : int n = vec_safe_length (crtl->eh.call_site_record_v[0]);
2926 0 : int i;
2927 :
2928 0 : for (i = 0; i < n; ++i)
2929 : {
2930 0 : struct call_site_record_d *cs = (*crtl->eh.call_site_record_v[0])[i];
2931 :
2932 0 : dw2_asm_output_data_uleb128 (INTVAL (cs->landing_pad),
2933 : "region %d landing pad", i);
2934 0 : dw2_asm_output_data_uleb128 (cs->action, "action");
2935 : }
2936 :
2937 0 : call_site_base += n;
2938 0 : }
2939 :
2940 : /* Switch to the section that should be used for exception tables. */
2941 :
2942 : static void
2943 79923 : switch_to_exception_section (const char * ARG_UNUSED (fnname))
2944 : {
2945 79923 : section *s;
2946 :
2947 79923 : if (exception_section
2948 : /* Don't use the cached section for comdat if it will be different. */
2949 : #ifdef HAVE_LD_EH_GC_SECTIONS
2950 96227 : && !(targetm_common.have_named_sections
2951 16304 : && DECL_COMDAT_GROUP (current_function_decl)
2952 : && HAVE_COMDAT_GROUP)
2953 : #endif
2954 : )
2955 14812 : s = exception_section;
2956 : else
2957 : {
2958 65111 : int flags;
2959 :
2960 65111 : if (EH_TABLES_CAN_BE_READ_ONLY)
2961 : {
2962 65111 : int tt_format =
2963 65111 : ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/1);
2964 130222 : flags = ((! flag_pic
2965 7751 : || ((tt_format & 0x70) != DW_EH_PE_absptr
2966 7751 : && (tt_format & 0x70) != DW_EH_PE_aligned))
2967 65111 : ? 0 : SECTION_WRITE);
2968 : }
2969 : else
2970 : flags = SECTION_WRITE;
2971 :
2972 : /* Compute the section and cache it into exception_section,
2973 : unless it depends on the function name. */
2974 65111 : if (targetm_common.have_named_sections)
2975 : {
2976 : #ifdef HAVE_LD_EH_GC_SECTIONS
2977 65111 : if (flag_function_sections
2978 65111 : || (DECL_COMDAT_GROUP (current_function_decl) && HAVE_COMDAT_GROUP))
2979 : {
2980 55339 : char *section_name = XNEWVEC (char, strlen (fnname) + 32);
2981 : /* The EH table must match the code section, so only mark
2982 : it linkonce if we have COMDAT groups to tie them together. */
2983 55339 : if (DECL_COMDAT_GROUP (current_function_decl) && HAVE_COMDAT_GROUP)
2984 31870 : flags |= SECTION_LINKONCE;
2985 55339 : sprintf (section_name, ".gcc_except_table.%s", fnname);
2986 55339 : s = get_section (section_name, flags, current_function_decl);
2987 55339 : free (section_name);
2988 : }
2989 : else
2990 : #endif
2991 9772 : exception_section
2992 9772 : = s = get_section (".gcc_except_table", flags, NULL);
2993 : }
2994 : else
2995 0 : exception_section
2996 0 : = s = flags == SECTION_WRITE ? data_section : readonly_data_section;
2997 : }
2998 :
2999 79923 : switch_to_section (s);
3000 79923 : }
3001 :
3002 : /* Output a reference from an exception table to the type_info object TYPE.
3003 : TT_FORMAT and TT_FORMAT_SIZE describe the DWARF encoding method used for
3004 : the value. */
3005 :
3006 : static void
3007 28017 : output_ttype (tree type, int tt_format, int tt_format_size)
3008 : {
3009 28017 : rtx value;
3010 28017 : bool is_public = true;
3011 :
3012 28017 : if (type == NULL_TREE)
3013 21596 : value = const0_rtx;
3014 : else
3015 : {
3016 : /* FIXME lto. pass_ipa_free_lang_data changes all types to
3017 : runtime types so TYPE should already be a runtime type
3018 : reference. When pass_ipa_free_lang data is made a default
3019 : pass, we can then remove the call to lookup_type_for_runtime
3020 : below. */
3021 6421 : if (TYPE_P (type))
3022 6117 : type = lookup_type_for_runtime (type);
3023 :
3024 6421 : value = expand_expr (type, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
3025 :
3026 : /* Let cgraph know that the rtti decl is used. Not all of the
3027 : paths below go through assemble_integer, which would take
3028 : care of this for us. */
3029 6421 : STRIP_NOPS (type);
3030 6421 : if (TREE_CODE (type) == ADDR_EXPR)
3031 : {
3032 6421 : type = TREE_OPERAND (type, 0);
3033 6421 : if (VAR_P (type))
3034 6421 : is_public = TREE_PUBLIC (type);
3035 : }
3036 : else
3037 0 : gcc_assert (TREE_CODE (type) == INTEGER_CST);
3038 : }
3039 :
3040 : /* Allow the target to override the type table entry format. */
3041 28017 : if (targetm.asm_out.ttype (value))
3042 : return;
3043 :
3044 28017 : if (tt_format == DW_EH_PE_absptr || tt_format == DW_EH_PE_aligned)
3045 3061 : assemble_integer (value, tt_format_size,
3046 3061 : tt_format_size * BITS_PER_UNIT, 1);
3047 : else
3048 24956 : dw2_asm_output_encoded_addr_rtx (tt_format, value, is_public, NULL);
3049 : }
3050 :
3051 : /* Output an exception table for the current function according to SECTION.
3052 :
3053 : If the function has been partitioned into hot and cold parts, value 0 for
3054 : SECTION refers to the table associated with the hot part while value 1
3055 : refers to the table associated with the cold part. If the function has
3056 : not been partitioned, value 0 refers to the single exception table. */
3057 :
3058 : static void
3059 79923 : output_one_function_exception_table (int section)
3060 : {
3061 79923 : int tt_format, cs_format, lp_format, i;
3062 79923 : char ttype_label[32];
3063 79923 : char cs_after_size_label[32];
3064 79923 : char cs_end_label[32];
3065 79923 : int call_site_len;
3066 79923 : int have_tt_data;
3067 79923 : int tt_format_size = 0;
3068 :
3069 79923 : have_tt_data = (vec_safe_length (cfun->eh->ttype_data)
3070 79632 : || (targetm.arm_eabi_unwinder
3071 54863 : ? vec_safe_length (cfun->eh->ehspec_data.arm_eabi)
3072 109435 : : vec_safe_length (cfun->eh->ehspec_data.other)));
3073 :
3074 : /* Indicate the format of the @TType entries. */
3075 : if (! have_tt_data)
3076 : tt_format = DW_EH_PE_omit;
3077 : else
3078 : {
3079 25303 : tt_format = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/1);
3080 25303 : if (HAVE_AS_LEB128)
3081 47132 : ASM_GENERATE_INTERNAL_LABEL (ttype_label,
3082 : section ? "LLSDATTC" : "LLSDATT",
3083 : current_function_funcdef_no);
3084 :
3085 25303 : tt_format_size = size_of_encoded_value (tt_format);
3086 :
3087 25303 : assemble_align (tt_format_size * BITS_PER_UNIT);
3088 : }
3089 :
3090 79923 : targetm.asm_out.internal_label (asm_out_file, section ? "LLSDAC" : "LLSDA",
3091 79923 : current_function_funcdef_no);
3092 :
3093 : /* The LSDA header. */
3094 :
3095 : /* Indicate the format of the landing pad start pointer. An omitted
3096 : field implies @LPStart == @Start. */
3097 : /* Currently we always put @LPStart == @Start. This field would
3098 : be most useful in moving the landing pads completely out of
3099 : line to another section, but it could also be used to minimize
3100 : the size of uleb128 landing pad offsets. */
3101 79923 : lp_format = DW_EH_PE_omit;
3102 79923 : dw2_asm_output_data (1, lp_format, "@LPStart format (%s)",
3103 : eh_data_format_name (lp_format));
3104 :
3105 : /* @LPStart pointer would go here. */
3106 :
3107 79923 : dw2_asm_output_data (1, tt_format, "@TType format (%s)",
3108 : eh_data_format_name (tt_format));
3109 :
3110 79923 : if (!HAVE_AS_LEB128)
3111 : {
3112 : if (targetm_common.except_unwind_info (&global_options) == UI_SJLJ)
3113 : call_site_len = sjlj_size_of_call_site_table ();
3114 : else
3115 : call_site_len = dw2_size_of_call_site_table (section);
3116 : }
3117 :
3118 : /* A pc-relative 4-byte displacement to the @TType data. */
3119 79923 : if (have_tt_data)
3120 : {
3121 25303 : if (HAVE_AS_LEB128)
3122 : {
3123 25303 : char ttype_after_disp_label[32];
3124 47132 : ASM_GENERATE_INTERNAL_LABEL (ttype_after_disp_label,
3125 : section ? "LLSDATTDC" : "LLSDATTD",
3126 : current_function_funcdef_no);
3127 25303 : dw2_asm_output_delta_uleb128 (ttype_label, ttype_after_disp_label,
3128 : "@TType base offset");
3129 25303 : ASM_OUTPUT_LABEL (asm_out_file, ttype_after_disp_label);
3130 : }
3131 : else
3132 : {
3133 : /* Ug. Alignment queers things. */
3134 : unsigned int before_disp, after_disp, last_disp, disp;
3135 :
3136 : before_disp = 1 + 1;
3137 : after_disp = (1 + size_of_uleb128 (call_site_len)
3138 : + call_site_len
3139 : + vec_safe_length (crtl->eh.action_record_data)
3140 : + (vec_safe_length (cfun->eh->ttype_data)
3141 : * tt_format_size));
3142 :
3143 : disp = after_disp;
3144 : do
3145 : {
3146 : unsigned int disp_size, pad;
3147 :
3148 : last_disp = disp;
3149 : disp_size = size_of_uleb128 (disp);
3150 : pad = before_disp + disp_size + after_disp;
3151 : if (pad % tt_format_size)
3152 : pad = tt_format_size - (pad % tt_format_size);
3153 : else
3154 : pad = 0;
3155 : disp = after_disp + pad;
3156 : }
3157 : while (disp != last_disp);
3158 :
3159 : dw2_asm_output_data_uleb128 (disp, "@TType base offset");
3160 : }
3161 : }
3162 :
3163 : /* Indicate the format of the call-site offsets. */
3164 79923 : if (HAVE_AS_LEB128)
3165 79923 : cs_format = DW_EH_PE_uleb128;
3166 : else
3167 : cs_format = DW_EH_PE_udata4;
3168 :
3169 79923 : dw2_asm_output_data (1, cs_format, "call-site format (%s)",
3170 : eh_data_format_name (cs_format));
3171 :
3172 79923 : if (HAVE_AS_LEB128)
3173 : {
3174 145888 : ASM_GENERATE_INTERNAL_LABEL (cs_after_size_label,
3175 : section ? "LLSDACSBC" : "LLSDACSB",
3176 : current_function_funcdef_no);
3177 145888 : ASM_GENERATE_INTERNAL_LABEL (cs_end_label,
3178 : section ? "LLSDACSEC" : "LLSDACSE",
3179 : current_function_funcdef_no);
3180 79923 : dw2_asm_output_delta_uleb128 (cs_end_label, cs_after_size_label,
3181 : "Call-site table length");
3182 79923 : ASM_OUTPUT_LABEL (asm_out_file, cs_after_size_label);
3183 79923 : if (targetm_common.except_unwind_info (&global_options) == UI_SJLJ)
3184 0 : sjlj_output_call_site_table ();
3185 : else
3186 79923 : dw2_output_call_site_table (cs_format, section);
3187 79923 : ASM_OUTPUT_LABEL (asm_out_file, cs_end_label);
3188 : }
3189 : else
3190 : {
3191 : dw2_asm_output_data_uleb128 (call_site_len, "Call-site table length");
3192 : if (targetm_common.except_unwind_info (&global_options) == UI_SJLJ)
3193 : sjlj_output_call_site_table ();
3194 : else
3195 : dw2_output_call_site_table (cs_format, section);
3196 : }
3197 :
3198 : /* ??? Decode and interpret the data for flag_debug_asm. */
3199 79923 : {
3200 79923 : uchar uc;
3201 225162 : FOR_EACH_VEC_ELT (*crtl->eh.action_record_data, i, uc)
3202 105468 : dw2_asm_output_data (1, uc, i ? NULL : "Action record table");
3203 : }
3204 :
3205 79923 : if (have_tt_data)
3206 25303 : assemble_align (tt_format_size * BITS_PER_UNIT);
3207 :
3208 79923 : i = vec_safe_length (cfun->eh->ttype_data);
3209 107940 : while (i-- > 0)
3210 : {
3211 28017 : tree type = (*cfun->eh->ttype_data)[i];
3212 28017 : output_ttype (type, tt_format, tt_format_size);
3213 : }
3214 :
3215 79923 : if (HAVE_AS_LEB128 && have_tt_data)
3216 25303 : ASM_OUTPUT_LABEL (asm_out_file, ttype_label);
3217 :
3218 : /* ??? Decode and interpret the data for flag_debug_asm. */
3219 79923 : if (targetm.arm_eabi_unwinder)
3220 : {
3221 : tree type;
3222 0 : for (i = 0;
3223 0 : vec_safe_iterate (cfun->eh->ehspec_data.arm_eabi, i, &type); ++i)
3224 0 : output_ttype (type, tt_format, tt_format_size);
3225 : }
3226 : else
3227 : {
3228 : uchar uc;
3229 518 : for (i = 0;
3230 80441 : vec_safe_iterate (cfun->eh->ehspec_data.other, i, &uc); ++i)
3231 648 : dw2_asm_output_data (1, uc,
3232 : i ? NULL : "Exception specification table");
3233 : }
3234 79923 : }
3235 :
3236 : /* Output an exception table for the current function according to SECTION,
3237 : switching back and forth from the function section appropriately.
3238 :
3239 : If the function has been partitioned into hot and cold parts, value 0 for
3240 : SECTION refers to the table associated with the hot part while value 1
3241 : refers to the table associated with the cold part. If the function has
3242 : not been partitioned, value 0 refers to the single exception table. */
3243 :
3244 : void
3245 1596816 : output_function_exception_table (int section)
3246 : {
3247 : /* Not all functions need anything. */
3248 1596816 : if (!crtl->uses_eh_lsda
3249 1596816 : || targetm_common.except_unwind_info (&global_options) == UI_NONE)
3250 : return;
3251 :
3252 : /* No need to emit any boilerplate stuff for the cold part. */
3253 79923 : if (section == 1 && !crtl->eh.call_site_record_v[1])
3254 : return;
3255 :
3256 79923 : const char *fnname = get_fnname_from_decl (current_function_decl);
3257 79923 : rtx personality = get_personality_function (current_function_decl);
3258 :
3259 79923 : if (personality)
3260 : {
3261 79923 : assemble_external_libcall (personality);
3262 :
3263 79923 : if (targetm.asm_out.emit_except_personality)
3264 0 : targetm.asm_out.emit_except_personality (personality);
3265 : }
3266 :
3267 79923 : switch_to_exception_section (fnname);
3268 :
3269 : /* If the target wants a label to begin the table, emit it here. */
3270 79923 : targetm.asm_out.emit_except_table_label (asm_out_file);
3271 :
3272 : /* Do the real work. */
3273 79923 : output_one_function_exception_table (section);
3274 :
3275 79923 : switch_to_section (current_function_section ());
3276 : }
3277 :
3278 : void
3279 1955756 : set_eh_throw_stmt_table (function *fun, hash_map<gimple *, int> *table)
3280 : {
3281 1955756 : fun->eh->throw_stmt_table = table;
3282 1955756 : }
3283 :
3284 : hash_map<gimple *, int> *
3285 727751942 : get_eh_throw_stmt_table (struct function *fun)
3286 : {
3287 727751942 : return fun->eh->throw_stmt_table;
3288 : }
3289 :
3290 : /* Determine if the function needs an EH personality function. */
3291 :
3292 : enum eh_personality_kind
3293 5591527 : function_needs_eh_personality (struct function *fn)
3294 : {
3295 5591527 : enum eh_personality_kind kind = eh_personality_none;
3296 5591527 : eh_region i;
3297 :
3298 6530631 : FOR_ALL_EH_REGION_FN (i, fn)
3299 : {
3300 1925331 : switch (i->type)
3301 : {
3302 939104 : case ERT_CLEANUP:
3303 : /* Can do with any personality including the generic C one. */
3304 939104 : kind = eh_personality_any;
3305 939104 : break;
3306 :
3307 : case ERT_TRY:
3308 : case ERT_ALLOWED_EXCEPTIONS:
3309 : /* Always needs a EH personality function. The generic C
3310 : personality doesn't handle these even for empty type lists. */
3311 : return eh_personality_lang;
3312 :
3313 : case ERT_MUST_NOT_THROW:
3314 : /* Always needs a EH personality function. The language may specify
3315 : what abort routine that must be used, e.g. std::terminate. */
3316 : return eh_personality_lang;
3317 : }
3318 : }
3319 :
3320 : return kind;
3321 : }
3322 :
3323 : /* Dump EH information to OUT. */
3324 :
3325 : void
3326 668 : dump_eh_tree (FILE * out, struct function *fun)
3327 : {
3328 668 : eh_region i;
3329 668 : int depth = 0;
3330 668 : static const char *const type_name[] = {
3331 : "cleanup", "try", "allowed_exceptions", "must_not_throw"
3332 : };
3333 :
3334 668 : i = fun->eh->region_tree;
3335 668 : if (!i)
3336 : return;
3337 :
3338 55 : fprintf (out, "Eh tree:\n");
3339 108 : while (1)
3340 : {
3341 108 : fprintf (out, " %*s %i %s", depth * 2, "",
3342 108 : i->index, type_name[(int) i->type]);
3343 :
3344 108 : if (i->landing_pads)
3345 : {
3346 43 : eh_landing_pad lp;
3347 :
3348 43 : fprintf (out, " land:");
3349 43 : if (current_ir_type () == IR_GIMPLE)
3350 : {
3351 86 : for (lp = i->landing_pads; lp ; lp = lp->next_lp)
3352 : {
3353 43 : fprintf (out, "{%i,", lp->index);
3354 43 : print_generic_expr (out, lp->post_landing_pad);
3355 43 : fputc ('}', out);
3356 43 : if (lp->next_lp)
3357 0 : fputc (',', out);
3358 : }
3359 : }
3360 : else
3361 : {
3362 0 : for (lp = i->landing_pads; lp ; lp = lp->next_lp)
3363 : {
3364 0 : fprintf (out, "{%i,", lp->index);
3365 0 : if (lp->landing_pad)
3366 0 : fprintf (out, "%i%s,", INSN_UID (lp->landing_pad),
3367 0 : NOTE_P (lp->landing_pad) ? "(del)" : "");
3368 : else
3369 0 : fprintf (out, "(nil),");
3370 0 : if (lp->post_landing_pad)
3371 : {
3372 0 : rtx_insn *lab = label_rtx (lp->post_landing_pad);
3373 0 : fprintf (out, "%i%s}", INSN_UID (lab),
3374 0 : NOTE_P (lab) ? "(del)" : "");
3375 : }
3376 : else
3377 0 : fprintf (out, "(nil)}");
3378 0 : if (lp->next_lp)
3379 0 : fputc (',', out);
3380 : }
3381 : }
3382 : }
3383 :
3384 108 : switch (i->type)
3385 : {
3386 : case ERT_CLEANUP:
3387 : case ERT_MUST_NOT_THROW:
3388 : break;
3389 :
3390 14 : case ERT_TRY:
3391 14 : {
3392 14 : eh_catch c;
3393 14 : fprintf (out, " catch:");
3394 28 : for (c = i->u.eh_try.first_catch; c; c = c->next_catch)
3395 : {
3396 14 : fputc ('{', out);
3397 14 : if (c->label)
3398 : {
3399 0 : fprintf (out, "lab:");
3400 0 : print_generic_expr (out, c->label);
3401 0 : fputc (';', out);
3402 : }
3403 14 : print_generic_expr (out, c->type_list);
3404 14 : fputc ('}', out);
3405 14 : if (c->next_catch)
3406 0 : fputc (',', out);
3407 : }
3408 : }
3409 : break;
3410 :
3411 0 : case ERT_ALLOWED_EXCEPTIONS:
3412 0 : fprintf (out, " filter :%i types:", i->u.allowed.filter);
3413 0 : print_generic_expr (out, i->u.allowed.type_list);
3414 0 : break;
3415 : }
3416 108 : fputc ('\n', out);
3417 :
3418 : /* If there are sub-regions, process them. */
3419 108 : if (i->inner)
3420 30 : i = i->inner, depth++;
3421 : /* If there are peers, process them. */
3422 78 : else if (i->next_peer)
3423 : i = i->next_peer;
3424 : /* Otherwise, step back up the tree to the next peer. */
3425 : else
3426 : {
3427 85 : do
3428 : {
3429 85 : i = i->outer;
3430 85 : depth--;
3431 85 : if (i == NULL)
3432 : return;
3433 : }
3434 30 : while (i->next_peer == NULL);
3435 : i = i->next_peer;
3436 : }
3437 : }
3438 : }
3439 :
3440 : /* Dump the EH tree for FN on stderr. */
3441 :
3442 : DEBUG_FUNCTION void
3443 0 : debug_eh_tree (struct function *fn)
3444 : {
3445 0 : dump_eh_tree (stderr, fn);
3446 0 : }
3447 :
3448 : /* Verify invariants on EH datastructures. */
3449 :
3450 : DEBUG_FUNCTION void
3451 10946375 : verify_eh_tree (struct function *fun)
3452 : {
3453 10946375 : eh_region r, outer;
3454 10946375 : int nvisited_lp, nvisited_r;
3455 10946375 : int count_lp, count_r, depth, i;
3456 10946375 : eh_landing_pad lp;
3457 10946375 : bool err = false;
3458 :
3459 10946375 : if (!fun->eh->region_tree)
3460 10946375 : return;
3461 :
3462 : count_r = 0;
3463 112987816 : for (i = 1; vec_safe_iterate (fun->eh->region_array, i, &r); ++i)
3464 109389854 : if (r)
3465 : {
3466 71255305 : if (r->index == i)
3467 71255305 : count_r++;
3468 : else
3469 : {
3470 0 : error ("%<region_array%> is corrupted for region %i", r->index);
3471 0 : err = true;
3472 : }
3473 : }
3474 :
3475 : count_lp = 0;
3476 53310569 : for (i = 1; vec_safe_iterate (fun->eh->lp_array, i, &lp); ++i)
3477 49712607 : if (lp)
3478 : {
3479 37036670 : if (lp->index == i)
3480 37036670 : count_lp++;
3481 : else
3482 : {
3483 0 : error ("%<lp_array%> is corrupted for lp %i", lp->index);
3484 0 : err = true;
3485 : }
3486 : }
3487 :
3488 3597962 : depth = nvisited_lp = nvisited_r = 0;
3489 3597962 : outer = NULL;
3490 3597962 : r = fun->eh->region_tree;
3491 71255305 : while (1)
3492 : {
3493 71255305 : if ((*fun->eh->region_array)[r->index] != r)
3494 : {
3495 0 : error ("%<region_array%> is corrupted for region %i", r->index);
3496 0 : err = true;
3497 : }
3498 71255305 : if (r->outer != outer)
3499 : {
3500 0 : error ("outer block of region %i is wrong", r->index);
3501 0 : err = true;
3502 : }
3503 71255305 : if (depth < 0)
3504 : {
3505 0 : error ("negative nesting depth of region %i", r->index);
3506 0 : err = true;
3507 : }
3508 71255305 : nvisited_r++;
3509 :
3510 108291975 : for (lp = r->landing_pads; lp ; lp = lp->next_lp)
3511 : {
3512 37036670 : if ((*fun->eh->lp_array)[lp->index] != lp)
3513 : {
3514 0 : error ("%<lp_array%> is corrupted for lp %i", lp->index);
3515 0 : err = true;
3516 : }
3517 37036670 : if (lp->region != r)
3518 : {
3519 0 : error ("region of lp %i is wrong", lp->index);
3520 0 : err = true;
3521 : }
3522 37036670 : nvisited_lp++;
3523 : }
3524 :
3525 71255305 : if (r->inner)
3526 23680999 : outer = r, r = r->inner, depth++;
3527 47574306 : else if (r->next_peer)
3528 : r = r->next_peer;
3529 : else
3530 : {
3531 27278961 : do
3532 : {
3533 27278961 : r = r->outer;
3534 27278961 : if (r == NULL)
3535 3597962 : goto region_done;
3536 23680999 : depth--;
3537 23680999 : outer = r->outer;
3538 : }
3539 23680999 : while (r->next_peer == NULL);
3540 : r = r->next_peer;
3541 : }
3542 : }
3543 3597962 : region_done:
3544 3597962 : if (depth != 0)
3545 : {
3546 0 : error ("tree list ends on depth %i", depth);
3547 0 : err = true;
3548 : }
3549 3597962 : if (count_r != nvisited_r)
3550 : {
3551 0 : error ("%<region_array%> does not match %<region_tree%>");
3552 0 : err = true;
3553 : }
3554 3597962 : if (count_lp != nvisited_lp)
3555 : {
3556 0 : error ("%<lp_array%> does not match %<region_tree%>");
3557 0 : err = true;
3558 : }
3559 :
3560 3597962 : if (err)
3561 : {
3562 0 : dump_eh_tree (stderr, fun);
3563 0 : internal_error ("%qs failed", __func__);
3564 : }
3565 : }
3566 :
3567 : #include "gt-except.h"
|