From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 69597 invoked by alias); 26 Oct 2015 02:07:42 -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 69460 invoked by uid 89); 26 Oct 2015 02:07:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.8 required=5.0 tests=AWL,BAYES_50,FREEMAIL_FROM,KAM_ASCII_DIVIDERS,RCVD_IN_DNSWL_NONE,RP_MATCHES_RCVD,SPF_PASS autolearn=no 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; Mon, 26 Oct 2015 02:07:40 +0000 Received: from mail.zoho.com by mx.zohomail.com with SMTP id 1445825257704326.7436928613688; Sun, 25 Oct 2015 19:07:37 -0700 (PDT) Received: from [209.169.24.247] by mail.zoho.com with HTTP;Sun, 25 Oct 2015 19:07:37 -0700 (PDT) Date: Mon, 26 Oct 2015 02:38:00 -0000 From: Louis Krupp To: "gcc-patches" , "fortran" Message-ID: <150a1e6a0b7.cab0bdc164391.7983815013798427754@zoho.com> Subject: Possible patch for PR fortran/66056 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_54073_283722873.1445825257652" User-Agent: Zoho Mail X-Zoho-Virus-Status: 1 X-SW-Source: 2015-10/txt/msg02627.txt.bz2 ------=_Part_54073_283722873.1445825257652 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Content-length: 711 The problem: Statement labels within a type declaration are put in the statement label tree belonging to the type declaration's namespace's (instead of the current namespace). When the line is otherwise empty and an error is issued, gfc_free_st_label tries to delete the label from the label tree belonging to the current namespace and then frees the label structure, leaving an invalid statement label pointer in the type declaration's namespace's label tree. When that namespace is cleaned up, bad things can happen. The attached patch stores a namespace pointer in the statement label structure so that if a label is deleted early for some reason, it will be deleted from the proper namespace. Louis ------=_Part_54073_283722873.1445825257652 Content-Type: application/octet-stream; name=empty_label_typedecl.f90 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=empty_label_typedecl.f90 Content-length: 190 ! { dg-do compile } ! { dg-options "-Werror" } subroutine s type t 1 ! { dg-error "empty statement" } end type end subroutine ! { dg-excess-errors "warnings being treated as errors" } ------=_Part_54073_283722873.1445825257652 Content-Type: text/plain; charset=us-ascii; name=patch.txt Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=patch.txt Content-length: 1443 Index: gcc/fortran/gfortran.h =================================================================== --- gcc/fortran/gfortran.h (revision 229302) +++ gcc/fortran/gfortran.h (working copy) @@ -1291,6 +1291,8 @@ typedef struct gfc_st_label tree backend_decl; locus where; + + gfc_namespace *ns; } gfc_st_label; Index: gcc/fortran/io.c =================================================================== --- gcc/fortran/io.c (revision 229302) +++ gcc/fortran/io.c (working copy) @@ -28,7 +28,7 @@ along with GCC; see the file COPYING3. If not see gfc_st_label format_asterisk = {0, NULL, NULL, -1, ST_LABEL_FORMAT, ST_LABEL_FORMAT, NULL, - 0, {NULL, NULL}}; + 0, {NULL, NULL}, NULL}; typedef struct { Index: gcc/fortran/symbol.c =================================================================== --- gcc/fortran/symbol.c (revision 229302) +++ gcc/fortran/symbol.c (working copy) @@ -2195,7 +2195,7 @@ gfc_free_st_label (gfc_st_label *label) if (label == NULL) return; - gfc_delete_bbt (&gfc_current_ns->st_labels, label, compare_st_labels); + gfc_delete_bbt (&label->ns->st_labels, label, compare_st_labels); if (label->format != NULL) gfc_free_expr (label->format); @@ -2260,6 +2260,7 @@ gfc_get_st_label (int labelno) lp->value = labelno; lp->defined = ST_LABEL_UNKNOWN; lp->referenced = ST_LABEL_UNKNOWN; + lp->ns = ns; gfc_insert_bbt (&ns->st_labels, lp, compare_st_labels); ------=_Part_54073_283722873.1445825257652--