From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9601 invoked by alias); 24 Aug 2015 16:30:27 -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 9568 invoked by uid 89); 24 Aug 2015 16:30:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail-wi0-f172.google.com Received: from mail-wi0-f172.google.com (HELO mail-wi0-f172.google.com) (209.85.212.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 24 Aug 2015 16:30:25 +0000 Received: by wicja10 with SMTP id ja10so77073373wic.1; Mon, 24 Aug 2015 09:30:23 -0700 (PDT) X-Received: by 10.194.203.138 with SMTP id kq10mr43155740wjc.124.1440433822982; Mon, 24 Aug 2015 09:30:22 -0700 (PDT) Received: from [192.168.100.6] (chp127.enscp.fr. [193.51.253.127]) by smtp.gmail.com with ESMTPSA id pg5sm23915679wjb.21.2015.08.24.09.30.21 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 24 Aug 2015 09:30:21 -0700 (PDT) Content-Type: multipart/mixed; boundary="Apple-Mail=_072893CF-F303-45E8-97B4-CCDD1DF65641" Mime-Version: 1.0 (Mac OS X Mail 9.0 \(3083\)) Subject: Re: Patch for fortran/62536 and fortran/66175 From: FX In-Reply-To: <14ee727ec7b.104544e4343297.1918480250807930593@zoho.com> Date: Mon, 24 Aug 2015 16:39:00 -0000 Cc: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org Message-Id: <25EB6D73-E490-41BE-BA9A-55C7D5396AF2@gmail.com> References: <14ee727ec7b.104544e4343297.1918480250807930593@zoho.com> To: Louis Krupp X-SW-Source: 2015-08/txt/msg01441.txt.bz2 --Apple-Mail=_072893CF-F303-45E8-97B4-CCDD1DF65641 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Content-length: 673 > This patch cleans up nested blocks when there's an unexpected end of a co= mpilation unit (66175), and it handles cleaned-up blocks gracefully (62536)= . I've run "make check-fortran" with the attached test cases. I have now committed the patch to trunk as revision 227135. Thanks for your contribution! And you=E2=80=99re welcome to repeat that exp= erience anytime :) FYI, I fixed a few minor issues with the patch before committed it (final v= ersion attached): - test directive should be { dg-do compile } not { dg-compile } - comment reformatting - missing gcc/testsuite/ChangeLog entries - reformated date and PR entries in ChangeLog Thanks again, FX --Apple-Mail=_072893CF-F303-45E8-97B4-CCDD1DF65641 Content-Disposition: attachment; filename=block.diff Content-Type: application/octet-stream; name="block.diff" Content-Transfer-Encoding: 7bit Content-length: 3506 Index: gcc/fortran/ChangeLog =================================================================== --- gcc/fortran/ChangeLog (revision 227134) +++ gcc/fortran/ChangeLog (working copy) @@ -1,3 +1,11 @@ +2015-08-24 Louis Krupp + + PR fortran/62536 + PR fortran/66175 + * decl.c (gfc_match_end): Clean up nested BLOCKs. + * parse.c (parse_block_construct): Deal gracefully with cleaned-up + BLOCKs. + 2015-08-23 Francois-Xavier Coudert PR libfortran/54572 Index: gcc/fortran/decl.c =================================================================== --- gcc/fortran/decl.c (revision 227127) +++ gcc/fortran/decl.c (working copy) @@ -6483,7 +6483,7 @@ cleanup: /* If we are missing an END BLOCK, we created a half-ready namespace. Remove it from the parent namespace's sibling list. */ - if (state == COMP_BLOCK) + while (state == COMP_BLOCK) { parent_ns = gfc_current_ns->parent; @@ -6506,6 +6506,8 @@ cleanup: gfc_free_namespace (gfc_current_ns); gfc_current_ns = parent_ns; + gfc_state_stack = gfc_state_stack->previous; + state = gfc_current_state (); } return MATCH_ERROR; Index: gcc/fortran/parse.c =================================================================== --- gcc/fortran/parse.c (revision 227127) +++ gcc/fortran/parse.c (working copy) @@ -3935,6 +3935,7 @@ static void parse_block_construct (void) { gfc_namespace* my_ns; + gfc_namespace* my_parent; gfc_state_data s; gfc_notify_std (GFC_STD_F2008, "BLOCK construct at %C"); @@ -3948,10 +3949,14 @@ parse_block_construct (void) push_state (&s, COMP_BLOCK, my_ns->proc_name); gfc_current_ns = my_ns; + my_parent = my_ns->parent; parse_progunit (ST_NONE); - gfc_current_ns = gfc_current_ns->parent; + /* Don't depend on the value of gfc_current_ns; it might have been + reset if the block had errors and was cleaned up. */ + gfc_current_ns = my_parent; + pop_state (); } Index: gcc/testsuite/ChangeLog =================================================================== --- gcc/testsuite/ChangeLog (revision 227134) +++ gcc/testsuite/ChangeLog (working copy) @@ -1,3 +1,10 @@ +2015-08-24 Louis Krupp + + PR fortran/62536 + PR fortran/66175 + * gfortran.dg/block_end_error_1.f90: New test. + * gfortran.dg/blocks_nested_incomplete_1.f90: New test. + 2015-08-24 H.J. Lu PR target/66821 Index: gcc/testsuite/gfortran.dg/block_end_error_1.f90 =================================================================== --- gcc/testsuite/gfortran.dg/block_end_error_1.f90 (revision 0) +++ gcc/testsuite/gfortran.dg/block_end_error_1.f90 (working copy) @@ -0,0 +1,10 @@ +! { dg-do compile } +! +! PR fortran/62536 +! Bad "end block" causes ICE. +subroutine s + block + end block named ! { dg-error "Syntax error in END BLOCK statement" } + return +endsubroutine +! { dg-prune-output "Unexpected end of file" } Index: gcc/testsuite/gfortran.dg/blocks_nested_incomplete_1.f90 =================================================================== --- gcc/testsuite/gfortran.dg/blocks_nested_incomplete_1.f90 (revision 0) +++ gcc/testsuite/gfortran.dg/blocks_nested_incomplete_1.f90 (working copy) @@ -0,0 +1,9 @@ +! { dg-do compile } +! +! PR fortran/66175 +! Nested incomplete blocks cause ICE. +program main + block + block +end program ! { dg-error "Expecting END BLOCK statement" } +! { dg-prune-output "Unexpected end of file" } --Apple-Mail=_072893CF-F303-45E8-97B4-CCDD1DF65641--