From patchwork Sun Jan 27 18:36:23 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 216028 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]) by ozlabs.org (Postfix) with SMTP id E669A2C0079 for ; Mon, 28 Jan 2013 05:36:37 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1359916598; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=102jg/7 CnCXTRr7RdDpkkCWO8Jg=; b=Z2VfezMxv4eM8RzQlmWeljSj+iExbmY1IViP+sS F6+B7+GhBYfOvP8sLt4K6rBdp/8Ran3M4T22Y8hqOesitJj4LlntYFT2fQBnRniF OQojfscgS0BRWO4RsYAnHMi1Arh2TEv0RCWIlLL9E7eFZlRx1D1z9UzNLVuzgWoS ZzMc= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=Qf/zi5LjPhNVj0QwOJu9YtpbkxWxa8ZfeDBtlOsE95IcB1uvhTC4YPhZZu4Q4G ihc04BbwT32brfmGvrxGZ/e3GUthCark/cKETX7rbuIU1qtMXqWOeUbbafgpcDxM EJGb2rbPgO3xH1VHXnZ2/9V9FASIIXt8wsREvlKBTfPLk=; Received: (qmail 3585 invoked by alias); 27 Jan 2013 18:36:33 -0000 Received: (qmail 3568 invoked by uid 22791); 27 Jan 2013 18:36:32 -0000 X-SWARE-Spam-Status: No, hits=-1.2 required=5.0 tests=AWL, BAYES_00, KAM_STOCKGEN, KHOP_RCVD_UNTRUST, KHOP_SPAMHAUS_DROP, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_NO, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from cc-smtpout1.netcologne.de (HELO cc-smtpout1.netcologne.de) (89.1.8.211) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 27 Jan 2013 18:36:27 +0000 Received: from cc-smtpin3.netcologne.de (cc-smtpin3.netcologne.de [89.1.8.203]) by cc-smtpout1.netcologne.de (Postfix) with ESMTP id 1F03F123A6; Sun, 27 Jan 2013 19:36:25 +0100 (CET) Received: from [192.168.0.104] (xdsl-78-35-151-231.netcologne.de [78.35.151.231]) by cc-smtpin3.netcologne.de (Postfix) with ESMTPSA id E00BC11DB9; Sun, 27 Jan 2013 19:36:23 +0100 (CET) Message-ID: <510573A7.4010505@netcologne.de> Date: Sun, 27 Jan 2013 19:36:23 +0100 From: Thomas Koenig User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130105 Thunderbird/17.0.2 MIME-Version: 1.0 To: "fortran@gcc.gnu.org" , gcc-patches Subject: [patch, fortran] Fix PR 50627 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 Hello world, the attached patch fixes the regression regarding freeing namespaces twice. The test cases where also run unter valgrind without producing errors. Regression-tested. OK for trunk? Thomas 2013-01-27 Thomas Koenig PR fortran/56054 * decl.c (gfc_match_end): Remove half-ready namespace from parent if the end of a block is missing. * parse.c (parse_module): Do not put namespace into gsymbol on error. 2013-01-27 Thomas Koenig PR fortran/56054 * gfortran.dg/block_12.f90: New test. * gfortran.dg/module_error_1.f90: New test. Index: decl.c =================================================================== --- decl.c (Revision 195319) +++ decl.c (Arbeitskopie) @@ -5979,6 +5979,8 @@ gfc_match_end (gfc_statement *st) const char *target; int eos_ok; match m; + gfc_namespace *parent_ns, *ns, *prev_ns; + gfc_namespace **nsp; old_loc = gfc_current_locus; if (gfc_match ("end") != MATCH_YES) @@ -6204,6 +6206,35 @@ syntax: cleanup: gfc_current_locus = old_loc; + + /* 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) + { + parent_ns = gfc_current_ns->parent; + + nsp = &(gfc_state_stack->previous->tail->ext.block.ns); + + prev_ns = NULL; + ns = *nsp; + while (ns) + { + if (ns == gfc_current_ns) + { + if (prev_ns == NULL) + *nsp = NULL; + else + prev_ns->sibling = ns->sibling; + } + prev_ns = ns; + ns = ns->sibling; + } + + gfc_free_namespace (gfc_current_ns); + gfc_current_ns = parent_ns; + } + return MATCH_ERROR; } Index: parse.c =================================================================== --- parse.c (Revision 195319) +++ parse.c (Arbeitskopie) @@ -4291,6 +4291,7 @@ parse_module (void) { gfc_statement st; gfc_gsymbol *s; + bool error; s = gfc_get_gsymbol (gfc_new_block->name); if (s->defined || (s->type != GSYM_UNKNOWN && s->type != GSYM_MODULE)) @@ -4304,6 +4305,7 @@ parse_module (void) st = parse_spec (ST_NONE); + error = false; loop: switch (st) { @@ -4322,12 +4324,15 @@ loop: gfc_error ("Unexpected %s statement in MODULE at %C", gfc_ascii_statement (st)); + error = true; reject_statement (); st = next_statement (); goto loop; } - s->ns = gfc_current_ns; + /* Make sure not to free the namespace twice on error. */ + if (!error) + s->ns = gfc_current_ns; }