From patchwork Thu Jun 27 07:35:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 1123184 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-503850-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="gl4Hnjsj"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45ZCT40F7yz9sCJ for ; Thu, 27 Jun 2019 18:18:06 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=qqwV1rA0nvBtYW26 Z38DaZCQ6P5XxPh/ze7BLal75FhUpLiHKPPW3rX+RcFFqDUgRHQqOGRr0aSQ88Dx e6V6MBnfv8GwdQj6b5Zv6/4d4uhM3qKrTyB80VTX3jdUT0WC9l/A280VNA54zIWg ODptQMJOxxe8gLTecsxqOp7uqik= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=TPSg9qNbW3fAUGeNT0c80U Oynfk=; b=gl4Hnjsje4c/0paUVSHZjr5MB+5YrCVdk80tL8JaNrJY0xsQZEEnPy XCZ/q3LkDr4cEvIWSuG2y47uYBPENyxF0PLxu+FU3JDaQGtdpatyRbyMEj3ev0zq 0Gv1ZtELLY1TdwPgqhJHyZfowdyWRrG2vrTjYfil/YoBEc/zKE8O0= Received: (qmail 90850 invoked by alias); 27 Jun 2019 08:17:58 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 90833 invoked by uid 89); 27 Jun 2019 08:17:57 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=hay, que, him, america X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 27 Jun 2019 08:17:56 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 293F656084; Thu, 27 Jun 2019 04:17:55 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id KjJLG0jKqv4P; Thu, 27 Jun 2019 04:17:55 -0400 (EDT) Received: from free.home (tron.gnat.com [IPv6:2620:20:4000:0:46a8:42ff:fe0e:e294]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPS id DE4B3116FB5; Thu, 27 Jun 2019 04:17:54 -0400 (EDT) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id x5R7ZhFp528349 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 27 Jun 2019 04:35:43 -0300 From: Alexandre Oliva To: gcc-patches@gcc.gnu.org Subject: allow EH to escape from GIMPLE_EH_ELSE ELSE block Date: Thu, 27 Jun 2019 04:35:43 -0300 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 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 {