From patchwork Sun Apr 14 12:51:59 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikael Morin X-Patchwork-Id: 236430 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 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 3C5962C00A1 for ; Sun, 14 Apr 2013 22:52:15 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=QgXP17c47lzODdSU+HaFgffxQAex1wAd/oZc8wskCH4YFp VMB/SqeMSm7z4MJnFATQ/i0GPtzGUotPx+uFvxJsp98jnCgTA4nTi68unNT+QajK boBWyBkbaydThp6HLv1CsOQ0vCI5ylOz/DUk7W6vSlJqkuHKxqjj5gWcmO0Qk= 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 :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=xNFcLrlYoBduEeIYB/kPIdJcaJA=; b=SEmZN1qkTXd5VYu4/qhn D5oDm5+18a0IHHMXfZ0phH8M+m2jLLkx6FN71Lwk5Jr4AzRRW1NRmEF5IHYOig9Z vFj6R7d7VgdfPBGmeuyfV59oAf9VUPhgR3gBIuuNl2ca3rl7NxsbAS5o+gzHtoph FcX7t7vvb7EdxKJuhRB6/c8= Received: (qmail 8494 invoked by alias); 14 Apr 2013 12:52:09 -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 8474 invoked by uid 89); 14 Apr 2013 12:52:08 -0000 X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD autolearn=ham version=3.3.1 X-Spam-User: qpsmtpd, 2 recipients Received: from smtp21.services.sfr.fr (HELO smtp21.services.sfr.fr) (93.17.128.1) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Sun, 14 Apr 2013 12:52:07 +0000 Received: from filter.sfr.fr (localhost [127.0.0.1]) by msfrf2121.sfr.fr (SMTP Server) with ESMTP id 410D1700008C; Sun, 14 Apr 2013 14:52:05 +0200 (CEST) Received: from [192.168.1.58] (53.183.72.86.rev.sfr.net [86.72.183.53]) by msfrf2121.sfr.fr (SMTP Server) with ESMTP id D2D2A7000088; Sun, 14 Apr 2013 14:52:04 +0200 (CEST) X-SFR-UUID: 20130414125204863.D2D2A7000088@msfrf2121.sfr.fr Message-ID: <516AA66F.4060109@sfr.fr> Date: Sun, 14 Apr 2013 14:51:59 +0200 From: Mikael Morin User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130412 Thunderbird/17.0.5 MIME-Version: 1.0 To: gfortran , gcc patches Subject: [Patch, fortran] PR56816: double free on unfinished SELECT TYPE statement X-Virus-Found: No Hello, this fixes a case where an unfinished SELECT TYPE statement was leading to an ICE because at the time the statement was rejected, the compiler tried to free some symbols that had already freed with the SELECT TYPE namespace. The fix moves the namespace allocation and cleanup out of gfc_match_namespace. A syntax error is added to avoid the default "unclassifiable statement" error. Bootstrapped (with asan) and regression tested on x86_64-linux. OK for trunk/4.8? Mikael 2013-04-14 Mikael Morin PR fortran/56816 * match.c (gfc_match_select_type): Add syntax error. Move namespace allocation and cleanup... * parse.c (decode_statement): ... here. 2013-04-14 Mikael Morin PR fortran/56816 * gfortran.dg/select_type_33.f03: New test. ! { dg-do compile } ! ! PR fortran/56816 ! The unfinished SELECT TYPE statement below was leading to an ICE because ! at the time the statement was rejected, the compiler tried to free ! some symbols that had already been freed with the SELECT TYPE ! namespace. ! ! Original testcase from Dominique Pelletier ! module any_list_module implicit none private public :: anylist, anyitem type anylist end type type anyitem class(*), allocatable :: value end type end module any_list_module module my_item_list_module use any_list_module implicit none type, extends (anyitem) :: myitem end type myitem contains subroutine myprint (this) class (myitem) :: this select type ( v => this % value ! { dg-error "parse error in SELECT TYPE" } end select ! { dg-error "Expecting END SUBROUTINE" } end subroutine myprint end module my_item_list_module diff --git a/match.c b/match.c index a1529da..b5e9609 100644 --- a/match.c +++ b/match.c @@ -5337,7 +5337,6 @@ gfc_match_select_type (void) char name[GFC_MAX_SYMBOL_LEN]; bool class_array; gfc_symbol *sym; - gfc_namespace *parent_ns; m = gfc_match_label (); if (m == MATCH_ERROR) @@ -5347,8 +5346,6 @@ gfc_match_select_type (void) if (m != MATCH_YES) return m; - gfc_current_ns = gfc_build_block_ns (gfc_current_ns); - m = gfc_match (" %n => %e", name, &expr2); if (m == MATCH_YES) { @@ -5379,7 +5376,10 @@ gfc_match_select_type (void) m = gfc_match (" )%t"); if (m != MATCH_YES) - goto cleanup; + { + gfc_error ("parse error in SELECT TYPE statement at %C"); + goto cleanup; + } /* This ghastly expression seems to be needed to distinguish a CLASS array, which can have a reference, from other expressions that @@ -5417,9 +5417,6 @@ gfc_match_select_type (void) return MATCH_YES; cleanup: - parent_ns = gfc_current_ns->parent; - gfc_free_namespace (gfc_current_ns); - gfc_current_ns = parent_ns; return m; } diff --git a/parse.c b/parse.c index 6dde0c6..74a5b4b 100644 --- a/parse.c +++ b/parse.c @@ -262,6 +262,7 @@ end_of_block: static gfc_statement decode_statement (void) { + gfc_namespace *ns; gfc_statement st; locus old_locus; match m; @@ -363,7 +364,12 @@ decode_statement (void) match (NULL, gfc_match_associate, ST_ASSOCIATE); match (NULL, gfc_match_critical, ST_CRITICAL); match (NULL, gfc_match_select, ST_SELECT_CASE); + + gfc_current_ns = gfc_build_block_ns (gfc_current_ns); match (NULL, gfc_match_select_type, ST_SELECT_TYPE); + ns = gfc_current_ns; + gfc_current_ns = gfc_current_ns->parent; + gfc_free_namespace (ns); /* General statement matching: Instead of testing every possible statement, we eliminate most possibilities by peeking at the