From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 112708 invoked by alias); 1 Aug 2015 02:47:15 -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 112686 invoked by uid 89); 1 Aug 2015 02:47:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,KAM_ASCII_DIVIDERS,RCVD_IN_DNSWL_NONE,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: sender153-mail.zoho.com Received: from sender153-mail.zoho.com (HELO sender153-mail.zoho.com) (74.201.84.153) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Sat, 01 Aug 2015 02:47:13 +0000 Received: from mail.zoho.com by mx.zohomail.com with SMTP id 1438397230253394.6506053072753; Fri, 31 Jul 2015 19:47:10 -0700 (PDT) Received: from [209.169.24.247] by mail.zoho.com with HTTP;Fri, 31 Jul 2015 19:47:10 -0700 (PDT) Date: Sat, 01 Aug 2015 02:47:00 -0000 From: Louis Krupp To: , Message-ID: <14ee727ec7b.104544e4343297.1918480250807930593@zoho.com> Subject: Patch for fortran/62536 and fortran/66175 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_36926_945342578.1438397230200" User-Agent: Zoho Mail X-Zoho-Virus-Status: 1 X-SW-Source: 2015-08/txt/msg00001.txt.bz2 ------=_Part_36926_945342578.1438397230200 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Content-length: 2232 This patch cleans up nested blocks when there's an unexpected end of a compilation unit (66175), and it handles cleaned-up blocks gracefully (62536). I've run "make check-fortran" with the attached test cases. Index: ChangeLog =================================================================== --- ChangeLog (revision 226452) +++ ChangeLog (working copy) @@ -1877,6 +1877,13 @@ * interface.c (is_procptr_result): New function to check if an expression is a procedure-pointer result. (compare_actual_formal): Use it. + +2015_07_31 Louis Krupp + + PR fortran/62536 and fortran/66175 + * decl.c (gfc_match_end): Clean up nested BLOCKs. + * parse.c (parse_block_construct): Deal gracefully with cleaned-up + BLOCKs. ^L Copyright (C) 2015 Free Software Foundation, Inc. Index: decl.c =================================================================== --- decl.c (revision 226452) +++ 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: parse.c =================================================================== --- parse.c (revision 226452) +++ 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,15 @@ 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 (); } ------=_Part_36926_945342578.1438397230200 Content-Type: application/octet-stream; name=blocks_nested_incomplete_1.f90 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=blocks_nested_incomplete_1.f90 Content-length: 213 ! { dg-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" } ------=_Part_36926_945342578.1438397230200 Content-Type: application/octet-stream; name=block_end_error_1.f90 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=block_end_error_1.f90 Content-length: 233 ! { dg-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" } ------=_Part_36926_945342578.1438397230200--