===================================================================
@@ -19322,7 +19322,9 @@ arbitrary signal handlers such as @code{
Consider that instructions that may throw exceptions but don't otherwise
contribute to the execution of the program can be optimized away.
This option is enabled by default for the Ada front end, as permitted by
-the Ada language specification.
+the Ada language specification. It is also enabled for the front ends of
+the C family of languages, as it applies only to non-call exceptions and
+those are not part of the the language specifications.
Optimization passes that cause dead exceptions to be removed are enabled independently at different optimization levels.
@item -funwind-tables
===================================================================
@@ -204,6 +204,11 @@ c_common_init_options_struct (struct gcc
/* By default, C99-like requirements for complex multiply and divide. */
opts->x_flag_complex_method = 2;
+
+ /* We can delete dead instructions that may throw exceptions because, in
+ practice, this occurs only for non-call exceptions and those are not
+ part of the the language specifications. */
+ opts->x_flag_delete_dead_exceptions = 1;
}
/* Common initialization before calling option handlers. */
===================================================================
@@ -96,7 +96,11 @@ DEFCIFCODE(EH_PERSONALITY, N_("exception
/* We can't inline if the callee can throw non-call exceptions but the
caller cannot. */
-DEFCIFCODE(NON_CALL_EXCEPTIONS, N_("non-call exception handling mismatch"))
+DEFCIFCODE(NON_CALL_EXCEPTIONS, N_("non-call exceptions handling mismatch"))
+
+/* We can't inline if the caller can delete dead exceptions but the
+ callee cannot. */
+DEFCIFCODE(DEAD_EXCEPTIONS, N_("dead exceptions handling mismatch"))
/* We can't inline because of mismatched target specific options. */
DEFCIFCODE(TARGET_OPTION_MISMATCH, N_("target specific option mismatch"))
===================================================================
@@ -302,6 +302,16 @@ can_inline_edge_p (struct cgraph_edge *e
e->inline_failed = CIF_NON_CALL_EXCEPTIONS;
inlinable = false;
}
+ /* Don't inline if the caller can delete dead exceptions but the
+ callee cannot.
+ FIXME: this is obviously wrong for LTO where STRUCT_FUNCTION is missing.
+ Move the flag into cgraph node or mirror it in the inline summary. */
+ else if (caller_cfun && caller_cfun->can_delete_dead_exceptions
+ && !(callee_cfun && callee_cfun->can_delete_dead_exceptions))
+ {
+ e->inline_failed = CIF_DEAD_EXCEPTIONS;
+ inlinable = false;
+ }
/* Check compatibility of target optimization options. */
else if (!targetm.target_option.can_inline_p (e->caller->symbol.decl,
callee->symbol.decl))
===================================================================
@@ -2107,6 +2107,7 @@ initialize_cfun (tree new_fndecl, tree c
cfun->after_inlining = src_cfun->after_inlining;
cfun->can_throw_non_call_exceptions
= src_cfun->can_throw_non_call_exceptions;
+ cfun->can_delete_dead_exceptions = src_cfun->can_delete_dead_exceptions;
cfun->returns_struct = src_cfun->returns_struct;
cfun->returns_pcc_struct = src_cfun->returns_pcc_struct;
cfun->after_tree_profile = src_cfun->after_tree_profile;