public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* allow EH to escape from GIMPLE_EH_ELSE ELSE block
@ 2019-06-27  8:17 Alexandre Oliva
  2019-06-27  9:36 ` Richard Biener
  0 siblings, 1 reply; 12+ messages in thread
From: Alexandre Oliva @ 2019-06-27  8:17 UTC (permalink / raw)
  To: gcc-patches

The only preexisting use of GIMPLE_EH_ELSE, for transactional memory
commits, did not allow exceptions to escape from the ELSE path.  The
trick it uses to allow the ELSE path to see the propagating exception
does not work very well if the exception cleanup raises further
exceptions: the ELSE block is configured to handle exceptions in
itself.  This confuses the heck out of CFG and EH cleanups.

Basing the lowering context for the ELSE block on outer_state, rather
than this_state, gets us the expected enclosing handler.

Regstrapped on x86_64-linux-gnu.  Ok to install?


for  gcc/ChangeLog

	* tree-eh.c (honor_protect_cleanup_actions): Use outer_
	rather than this_state as the lowering context for the ELSE
	seq in a GIMPLE_EH_ELSE.
---
 gcc/tree-eh.c |   13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/gcc/tree-eh.c b/gcc/tree-eh.c
index 23c56b5661a1..4de09d1bf7b5 100644
--- a/gcc/tree-eh.c
+++ b/gcc/tree-eh.c
@@ -1001,11 +1001,14 @@ honor_protect_cleanup_actions (struct leh_state *outer_state,
       gimple_try_set_cleanup (tf->top_p, gimple_eh_else_n_body (eh_else));
       finally = gimple_eh_else_e_body (eh_else);
 
-      /* Let the ELSE see the exception that's being processed.  */
-      eh_region save_ehp = this_state->ehp_region;
-      this_state->ehp_region = this_state->cur_region;
-      lower_eh_constructs_1 (this_state, &finally);
-      this_state->ehp_region = save_ehp;
+      /* Let the ELSE see the exception that's being processed, but
+	 since the cleanup is outside the try block, process it with
+	 outer_state, otherwise it may be used as a cleanup for
+	 itself, and Bad Things (TM) ensue.  */
+      eh_region save_ehp = outer_state->ehp_region;
+      outer_state->ehp_region = this_state->cur_region;
+      lower_eh_constructs_1 (outer_state, &finally);
+      outer_state->ehp_region = save_ehp;
     }
   else
     {

-- 
Alexandre Oliva, freedom fighter  he/him   https://FSFLA.org/blogs/lxo
Be the change, be Free!                 FSF Latin America board member
GNU Toolchain Engineer                        Free Software Evangelist
Hay que enGNUrecerse, pero sin perder la terGNUra jamás - Che GNUevara

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2019-07-12 10:49 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-27  8:17 allow EH to escape from GIMPLE_EH_ELSE ELSE block Alexandre Oliva
2019-06-27  9:36 ` Richard Biener
2019-06-28  9:43   ` Alexandre Oliva
2019-07-01 11:19     ` Richard Biener
2019-07-02  8:51       ` Alexandre Oliva
2019-07-02 10:11         ` Richard Biener
2019-07-04  8:50           ` Alexandre Oliva
2019-07-04 10:54             ` Richard Biener
2019-07-11 10:44               ` Alexandre Oliva
2019-07-12 10:49                 ` Richard Biener
2019-07-11 10:52               ` Alexandre Oliva
2019-07-12 11:02                 ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).