From patchwork Sat Aug 13 13:25:48 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikael Morin X-Patchwork-Id: 109933 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 9C0FCB70BB for ; Sat, 13 Aug 2011 23:26:16 +1000 (EST) Received: (qmail 31157 invoked by alias); 13 Aug 2011 13:26:11 -0000 Received: (qmail 31136 invoked by uid 22791); 13 Aug 2011 13:26:09 -0000 X-SWARE-Spam-Status: No, hits=-1.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from smtp21.services.sfr.fr (HELO smtp21.services.sfr.fr) (93.17.128.2) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 13 Aug 2011 13:25:52 +0000 Received: from filter.sfr.fr (localhost [127.0.0.1]) by msfrf2107.sfr.fr (SMTP Server) with ESMTP id 6C8CE700017D; Sat, 13 Aug 2011 15:25:51 +0200 (CEST) Received: from gimli.local (237.183.72.86.rev.sfr.net [86.72.183.237]) by msfrf2107.sfr.fr (SMTP Server) with ESMTP id 2B4E47000179; Sat, 13 Aug 2011 15:25:51 +0200 (CEST) X-SFR-UUID: 20110813132551177.2B4E47000179@msfrf2107.sfr.fr From: Mikael Morin To: fortran@gcc.gnu.org Subject: [Patch, fortran] PR fortran/50071 Duplicate statement labels from different scoping units rejected. Date: Sat, 13 Aug 2011 15:25:48 +0200 User-Agent: KMail/1.13.5 (FreeBSD/8.2-PRERELEASE; KDE/4.5.5; amd64; ; ) Cc: "gcc-patches" MIME-Version: 1.0 Message-Id: <201108131525.48949.mikael.morin@sfr.fr> X-IsSubscribed: yes 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, this patch fixes PR 50071 where statement labels in a type definition where hooked to the parent scoping unit instead of the type scoping unit. From the standard: - statement label (3.2.5): The same statement label shall not be given to more than one statement in its scope. - scoping unit (1.3.124) BLOCK construct, _derived-type_ definition, interface body, program unit, or subprogram, excluding all nested scoping units in it. Currently we ignore the derived type definition scoping unit, and thus reject the statement label if it is the same as another one outside the derived type definition. As it can't be used anyway, it makes sense to ignore it completely. This patch puts the statement label in the derived_type->f2k_derived namespace if we are parsing a derived type definition. Regression tested on x86_64-unknown-freebsd8.2. OK for trunk? Even if it is a rejects-valid bug, I consider it as minor, and don't feel the need for backporting (but it can be discussed). Mikael *** a/symbol.c --- b/symbol.c *************** gfc_get_st_label (int labelno) *** 2127,2137 **** --- 2127,2144 ---- gfc_st_label *lp; gfc_namespace *ns; + /* A derived type definition is a separate scoping unit, so that it has its + own set of statement labels. */ + if (gfc_current_state () == COMP_DERIVED) + ns = gfc_current_block ()->f2k_derived; + else + { /* Find the namespace of the scoping unit: If we're in a BLOCK construct, jump to the parent namespace. */ ns = gfc_current_ns; while (ns->proc_name && ns->proc_name->attr.flavor == FL_LABEL) ns = ns->parent; + } /* First see if the label is already in this namespace. */ lp = ns->st_labels; 2011-08-13 Mikael Morin PR fortran/50071 * symbol.c (gfc_get_st_label): Use the derived type namespace when we are parsing a derived type definition. 2011-08-13 Mikael Morin PR fortran/50071 * gfortran.dg/duplicate_labels_2.f: New test. diff --git a/symbol.c b/symbol.c index b761cdd..4463460 100644 --- a/symbol.c +++ b/symbol.c @@ -2127,11 +2127,16 @@ gfc_get_st_label (int labelno) gfc_st_label *lp; gfc_namespace *ns; - /* Find the namespace of the scoping unit: - If we're in a BLOCK construct, jump to the parent namespace. */ - ns = gfc_current_ns; - while (ns->proc_name && ns->proc_name->attr.flavor == FL_LABEL) - ns = ns->parent; + if (gfc_current_state () == COMP_DERIVED) + ns = gfc_current_block ()->f2k_derived; + else + { + /* Find the namespace of the scoping unit: + If we're in a BLOCK construct, jump to the parent namespace. */ + ns = gfc_current_ns; + while (ns->proc_name && ns->proc_name->attr.flavor == FL_LABEL) + ns = ns->parent; + } /* First see if the label is already in this namespace. */ lp = ns->st_labels;