From patchwork Thu Jan 28 11:34:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Vehreschild X-Patchwork-Id: 574669 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 8857A140BD6 for ; Thu, 28 Jan 2016 22:35:14 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=PG1Le50/; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-type; q=dns; s=default; b=bVVL3WSudD844lx8 rrXJdorYimevSjHLULEf2EjlqU3Y2zwlVJ+yJLpd7DFJhrRd7lWY9W5SOIZuRTk7 8ZLU1ubDhbvbtPBEsifTvt+kTFtPlV37KV9+qh9UVQprIHprUptEWKUXL+HyKuzq 1r/tOi6KdUpeZIZJzwaPcEoOTDQ= 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:date :from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-type; s=default; bh=bUB9C4BXJMFTX4pbza5vu+ hWX8Q=; b=PG1Le50/H752mheUAEGeXaD8gD850/SE56rbc3efYqMIjp/VKtzL+V lv3hsgj9+rvDywTKXTJFH8B/lAmpQ/GIadBLP7tMYQMqPE1N9bNZ9VrALJ2P60mL qRZj1HX+GKtF99EWNFDS2A2k6h66J2f4TK7Bikux+/e0ihcDldPpw= Received: (qmail 46314 invoked by alias); 28 Jan 2016 11:35:07 -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 46294 invoked by uid 89); 28 Jan 2016 11:35:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 spammy=enkovich.gnu@gmail.com, enkovichgnugmailcom, arbeitskopie, Arbeitskopie X-Spam-User: qpsmtpd, 2 recipients X-HELO: mout.gmx.net Received: from mout.gmx.net (HELO mout.gmx.net) (212.227.15.18) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 28 Jan 2016 11:35:05 +0000 Received: from vepi2 ([92.213.0.123]) by mail.gmx.com (mrgmx002) with ESMTPSA (Nemesis) id 0M0gww-1a6O7e0Zsk-00uspA; Thu, 28 Jan 2016 12:35:00 +0100 Date: Thu, 28 Jan 2016 12:34:59 +0100 From: Andre Vehreschild To: Jerry DeLisle Cc: GCC-Patches-ML , GCC-Fortran-ML Subject: Re: [Patch, fortran, GCC-5/6, PR62536, v1] ICE (segfault) for invalid END BLOCK statement Message-ID: <20160128123459.5324062e@vepi2> In-Reply-To: <56A95084.1070007@charter.net> References: <20160127172537.6a184e15@vepi2> <56A95084.1070007@charter.net> MIME-Version: 1.0 X-UI-Out-Filterresults: notjunk:1; V01:K0:SF7wgR4dj/M=:jdXBXkcyk5N47gDkeKdm1t bB7HLH56jfOEvStW6gUcEMJQvmCNfB6NeGHAB/6FEGNgJX6tOJ4Gcfk5tGHa/3L4HxOoYsHQ1 2zSrMax2TJK46Gyk7aho5m+WgB9IyYwPifBT5c3TG7WR4EajZX2E2QCSWDSoXUbaBTe1zikf9 pteGu6a+z/QEdCF9mv+KDNP7SR2CGElkASFrUE4nbnWayIixaI+AIBfVkk/ZlisL6P3ZRhHHh pn4pnYAYWCtG6xaj/Pc5yyTnsfhPzyIhXJmUqQDJrvgvITKG47h9F3/fupouCP4qdShKvIp2q 2Hj/6YWeRCiPms+woH8OXrHPctpeOWAc983oSef7f0GFOfLCL2x1/1bi+0KHxNRB4I+pPSZ4h CoSJWmPi2tQvMozlkgHjHxsIYtKMEL+FuelT2pOcMdIgbWyw8fXxPaxsL98vp+ZXeemtHcmIQ 22IgYes+kB9mlLDOKmIokMTfkEEZRe389TOWwUHMxnArPWq6vN3iR0d2OzL4eSiPkFws5f3FA lJRutS3rhl6w32SusRH52mGK8olMldtjB+zgfHLvvJ4tZBUiJjBai0gm2psHJ8jIfERTGadRT NRRapMeaIg9Gib7QTSz9T67zWfmI1O0JM8OvoxWjAI64l+gEIrBrW3UDXzILATfFGVeACzUmX 5yZRrc+TmQLiYci1ncCLKfS/qDYRE1OyXC/epywANRhNz0i/enFz09c2KoWnKqHGl74Ic1ppl EGEsvoLnKPuJTrCqthtdzqTmEdgkHU9zb387dbUzsB85Z+7nL3rTDf1FJDw= Hi Jerry, hi all, thanks for the fast review. Committed as r232918 for gcc-5-branch, and r232919 for trunk. Thanks again Jerry and regards, Andre On Wed, 27 Jan 2016 15:19:32 -0800 Jerry DeLisle wrote: > On 01/27/2016 08:25 AM, Andre Vehreschild wrote: > > Hi all, > > > > attached are two patches one for trunk and one for the gcc-5-branch, > > which fix an ICE when BLOCK statements are not closed correctly (too > > many END BLOCKs). Unfortunately did the patch I tailored for gcc-5 not > > work on trunk. > > > > GCC 5: The ICE is prevented by making sure that gfc_current_ns is not > > set to NULL, when too many closing END BLOCK statements are found. This > > may lead to gfortran be in the wrong namespace, but gfortran is already > > in error. Therefore this does not matter any more. We just need to exit > > cleanly. > > > > GCC 6/trunk: Here the ICE is prevented by making sure, that unnesting > > of BLOCK namespaces is only done, when the END encountered is not the > > one of a BLOCK. This prevents gfortran from removing a correctly > > initialized and for further analysis required namespace. > > > > Bootstrapped and regtested ok on x86_64-linux-gnu/F23. > > > > Ok for trunk and gcc-5-branch, respectively? > > > > OK and thanks for fixes. Much appreciated? > > Jerry Index: gcc/fortran/ChangeLog =================================================================== --- gcc/fortran/ChangeLog (Revision 232917) +++ gcc/fortran/ChangeLog (Arbeitskopie) @@ -1,3 +1,9 @@ +2016-01-28 Andre Vehreschild + + PR fortran/62536 + * decl.c (gfc_match_end): Only unnest and remove BLOCK namespaces + when the END encountered does not match a BLOCK's end. + 2016-01-27 Janus Weil PR fortran/69484 Index: gcc/fortran/decl.c =================================================================== --- gcc/fortran/decl.c (Revision 232917) +++ gcc/fortran/decl.c (Arbeitskopie) @@ -6327,6 +6327,7 @@ gfc_namespace *parent_ns, *ns, *prev_ns; gfc_namespace **nsp; bool abreviated_modproc_decl; + bool got_matching_end = false; old_loc = gfc_current_locus; if (gfc_match ("end") != MATCH_YES) @@ -6510,6 +6511,8 @@ ? "END PROCEDURE" : gfc_ascii_statement(*st), &old_loc); goto cleanup; } + else + got_matching_end = true; old_loc = gfc_current_locus; /* If we're at the end, make sure a block name wasn't required. */ @@ -6581,7 +6584,7 @@ /* If we are missing an END BLOCK, we created a half-ready namespace. Remove it from the parent namespace's sibling list. */ - while (state == COMP_BLOCK) + while (state == COMP_BLOCK && !got_matching_end) { parent_ns = gfc_current_ns->parent; @@ -6601,7 +6604,7 @@ prev_ns = ns; ns = ns->sibling; } - + gfc_free_namespace (gfc_current_ns); gfc_current_ns = parent_ns; gfc_state_stack = gfc_state_stack->previous; Index: gcc/testsuite/ChangeLog =================================================================== --- gcc/testsuite/ChangeLog (Revision 232917) +++ gcc/testsuite/ChangeLog (Arbeitskopie) @@ -1,3 +1,10 @@ +2016-01-28 Andre Vehreschild + + PR fortran/62536 + * gfortran.dg/block_15.f08: New test. + * gfortran.dg/block_end_error_1.f90: Need to catch additional error + on incorrectly closed BLOCK. + 2016-01-28 Ilya Enkovich * gcc.dg/declare-simd.c: New test. Index: gcc/testsuite/gfortran.dg/block_end_error_1.f90 =================================================================== --- gcc/testsuite/gfortran.dg/block_end_error_1.f90 (Revision 232917) +++ gcc/testsuite/gfortran.dg/block_end_error_1.f90 (Arbeitskopie) @@ -6,5 +6,5 @@ block end block named ! { dg-error "Syntax error in END BLOCK statement" } return -endsubroutine +endsubroutine ! { dg-error "Expecting END BLOCK statement" } ! { dg-prune-output "Unexpected end of file" }