From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 130993 invoked by alias); 4 Jul 2019 10:51:50 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 130976 invoked by uid 89); 4 Jul 2019 10:51:49 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-14.6 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,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=H*RU:209.85.167.66, HX-Spam-Relays-External:209.85.167.66 X-HELO: mail-lf1-f66.google.com Received: from mail-lf1-f66.google.com (HELO mail-lf1-f66.google.com) (209.85.167.66) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 04 Jul 2019 10:51:47 +0000 Received: by mail-lf1-f66.google.com with SMTP id z15so3912118lfh.13 for ; Thu, 04 Jul 2019 03:51:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=3TsUgHez0vMS9bkmTLfEF1nXCGJFw/kn6HfkVbOp8Rs=; b=X6DN+gsF1zNDh/P/A5NcHP30qJzYl3SudnGFeXLwVxyMDDGMKXnloQgY3Nq8iqJihC r4BPXzgTMbhRAZYQM/pG4LwdVPsmS1+spgSsrAsCcKkVkyTbTvYJXaJ1AgO7CSueUvMX ghqwYhxGtFEPUdAV68LwiWlQos7s3ZfqcRUgcghPhL6fkqzTccTjCUbLChxwHncOIofl qItPnF8Q5Y5dIsSuejhLPrpNVcCwfatauaRvFvBEkdgW5TxebCqRwT6d1u51aGWnYa9Y qDyOWi1gk2tYEATGe4cQ7Sh6LHkdB+B8gDhnl3CRfP6VjohTqUpZWqtPGxLeTHlDchQW pbHg== MIME-Version: 1.0 References: In-Reply-To: From: Richard Biener Date: Thu, 04 Jul 2019 10:54:00 -0000 Message-ID: Subject: Re: allow EH to escape from GIMPLE_EH_ELSE ELSE block To: Alexandre Oliva Cc: GCC Patches Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2019-07/txt/msg00366.txt.bz2 On Thu, Jul 4, 2019 at 10:29 AM Alexandre Oliva wrote: > > On Jul 2, 2019, Richard Biener wrote: > > > Yeah, it's on trunk. The parser is ontop of the C frontend and resides > > in gcc/c/gimple-parser.c while testcases are in gcc.dg/gimplefe-*.c > > > The parsing is incomplete, there's no support for parsing try/catch/fin= ally > > I'm afraid I haven't got very far, but I tried. It didn't recognize try > and finally as keywords, and since the parser is integrated with the C > parser IIUC, I wasn't sure how to enable the keywords only within gimple > functions. Yeah. For other stuff we're simply looking at CPP_NAME and string-matching, see c_parser_gimple_compound_statement where you'd probably hook this into. > As mentioned in another message, I chose try/finally/else as the > notation for TRY_FINALLY_EXPR <..., EH_ELSE_EXPR <..., ...> >, to avoid > introducing yet another keyword such as eh_finally. > > I also considered try/noexcept/finally, or try/noexcept finally/finally, > but... else seems to be a lot more closely related with EH_ELSE_EXPR, > and at least in gimple it's non-ambiguous. > > > introduce try/finally/else in gimplefe (WIP FTR) > > From: Alexandre Oliva > > > --- > gcc/c/gimple-parser.c | 49 ++++++++++++++++++++++++++++++= ++++++ > gcc/testsuite/gcc.dg/gimplefe-43.c | 13 ++++++++++ > 2 files changed, 62 insertions(+) > create mode 100644 gcc/testsuite/gcc.dg/gimplefe-43.c > > diff --git a/gcc/c/gimple-parser.c b/gcc/c/gimple-parser.c > index b2b364cc41a3..91f2499bb1cc 100644 > --- a/gcc/c/gimple-parser.c > +++ b/gcc/c/gimple-parser.c > @@ -115,6 +115,7 @@ static struct c_expr c_parser_gimple_postfix_expressi= on_after_primary > static void c_parser_gimple_declaration (gimple_parser &); > static void c_parser_gimple_goto_stmt (gimple_parser &, location_t, > tree, gimple_seq *); > +static void c_parser_gimple_try_stmt (gimple_parser &, gimple_seq *); > static void c_parser_gimple_if_stmt (gimple_parser &, gimple_seq *); > static void c_parser_gimple_switch_stmt (gimple_parser &, gimple_seq *); > static void c_parser_gimple_return_stmt (gimple_parser &, gimple_seq *); > @@ -405,6 +406,9 @@ c_parser_gimple_compound_statement (gimple_parser &pa= rser, gimple_seq *seq) > case CPP_KEYWORD: > switch (c_parser_peek_token (parser)->keyword) > { > + case RID_AT_TRY: > + c_parser_gimple_try_stmt (parser, seq); > + break; > case RID_IF: > c_parser_gimple_if_stmt (parser, seq); > break; > @@ -2088,6 +2092,51 @@ c_parser_gimple_paren_condition (gimple_parser &pa= rser) > return cond; > } > > +/* Parse gimple try statement. > + > + try-statement: > + try { ... } finally { ... } > + try { ... } finally { ... } else { ... } > + > + This could support try/catch as well, but it's not implemented yet. > + */ > + > +static void > +c_parser_gimple_try_stmt (gimple_parser &parser, gimple_seq *seq) > +{ > + gimple_seq tryseq =3D NULL; > + c_parser_consume_token (parser); > + c_parser_gimple_compound_statement (parser, &tryseq); > + > + if (c_parser_next_token_is (parser, CPP_KEYWORD) > + && c_parser_peek_token (parser)->keyword =3D=3D RID_AT_FINALLY) > + { > + gimple_seq finseq =3D NULL; > + c_parser_consume_token (parser); > + c_parser_gimple_compound_statement (parser, &finseq); > + > + if (c_parser_next_token_is (parser, CPP_KEYWORD) > + && c_parser_peek_token (parser)->keyword =3D=3D RID_ELSE) > + { > + gimple_seq elsseq =3D NULL; > + c_parser_consume_token (parser); > + c_parser_gimple_compound_statement (parser, &finseq); > + > + geh_else *stmt =3D gimple_build_eh_else (finseq, elsseq); > + finseq =3D NULL; > + gimple_seq_add_stmt_without_update (&finseq, stmt); > + } > + > + gtry *stmt =3D gimple_build_try (tryseq, finseq, GIMPLE_TRY_FINALL= Y); > + gimple_seq_add_stmt_without_update (seq, stmt); > + } > + else if (c_parser_next_token_is (parser, CPP_KEYWORD) > + && c_parser_peek_token (parser)->keyword =3D=3D RID_AT_CATCH) > + c_parser_error (parser, "% is not supported"); > + else > + c_parser_error (parser, "expected % or %"); > +} > + > /* Parse gimple if-else statement. > > if-statement: > diff --git a/gcc/testsuite/gcc.dg/gimplefe-43.c b/gcc/testsuite/gcc.dg/gi= mplefe-43.c > new file mode 100644 > index 000000000000..c740e06a78e1 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/gimplefe-43.c > @@ -0,0 +1,13 @@ > +/* { dg-do compile } */ > +/* { dg-options "-fgimple" } */ > + > +void __GIMPLE foo() > +{ > + try { > + ; > + } finally { > + ; > + } 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=C3=A1s - Che GNUeva= ra