From patchwork Sun Oct 16 20:19:03 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 120067 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 2F2D7B70DC for ; Mon, 17 Oct 2011 07:19:28 +1100 (EST) Received: (qmail 25739 invoked by alias); 16 Oct 2011 20:19:23 -0000 Received: (qmail 25719 invoked by uid 22791); 16 Oct 2011 20:19:21 -0000 X-SWARE-Spam-Status: No, hits=-1.5 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from cc-smtpout3.netcologne.de (HELO cc-smtpout3.netcologne.de) (89.1.8.213) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 16 Oct 2011 20:19:06 +0000 Received: from cc-smtpin2.netcologne.de (cc-smtpin2.netcologne.de [89.1.8.202]) by cc-smtpout3.netcologne.de (Postfix) with ESMTP id DCB681271E; Sun, 16 Oct 2011 22:19:04 +0200 (CEST) Received: from [192.168.0.105] (xdsl-78-35-130-197.netcologne.de [78.35.130.197]) by cc-smtpin2.netcologne.de (Postfix) with ESMTPSA id B0AD011E65; Sun, 16 Oct 2011 22:19:03 +0200 (CEST) Message-ID: <4E9B3C37.3020103@netcologne.de> Date: Sun, 16 Oct 2011 22:19:03 +0200 From: Thomas Koenig User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; de; rv:1.9.2.17) Gecko/20110414 SUSE/3.1.10 Thunderbird/3.1.10 MIME-Version: 1.0 To: "fortran@gcc.gnu.org" , gcc-patches Subject: [patch, fortran] Some cleanup / fixes in front-end statement walker 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, working on PR 50690, I noticed a few things which are not quite right in front-end optimization statement walking: - BLOCKs were walked via their namespaces, not directly. This caused out-of-order walking, which was confusing. - current_ns was not marked static. - ASSOCIATE lists were not walked. This patch corrects these things. Regression-tested. OK for trunk? (I will not be able to commit for a few days due to business travel, unless somebody is _really_ fast :-) Thomas 2011-10-16 Thomas Koenig * frontend-passes.c (current_ns): Make static. (create_var): Note parent of newly created namespace. (optimize_namespace): Don't wak sibling namespaces if they are EXEC_BLOCK because this is handled... (gfc_code_walker): ... here. Also walk ASSOCIATE lists. Index: frontend-passes.c =================================================================== --- frontend-passes.c (Revision 179770) +++ frontend-passes.c (Arbeitskopie) @@ -60,7 +60,7 @@ static gfc_code *inserted_block, **changed_stateme /* The namespace we are currently dealing with. */ -gfc_namespace *current_ns; +static gfc_namespace *current_ns; /* If we are within any forall loop. */ @@ -261,6 +261,7 @@ create_var (gfc_expr * e) (*current_code)->next = NULL; /* Insert the BLOCK at the right position. */ *current_code = inserted_block; + ns->parent = current_ns; } else ns = inserted_block->ext.block.ns; @@ -509,8 +510,12 @@ optimize_namespace (gfc_namespace *ns) gfc_code_walker (&ns->code, cfe_code, cfe_expr_0, NULL); gfc_code_walker (&ns->code, optimize_code, optimize_expr, NULL); + /* BLOCKs are handled in the expression walker below. */ for (ns = ns->contained; ns; ns = ns->sibling) - optimize_namespace (ns); + { + if (ns->code == NULL || ns->code->op != EXEC_BLOCK) + optimize_namespace (ns); + } } /* Replace code like @@ -1143,6 +1148,7 @@ gfc_code_walker (gfc_code **c, walk_code_fn_t code gfc_code *b; gfc_actual_arglist *a; gfc_code *co; + gfc_association_list *alist; /* There might be statement insertions before the current code, which must not affect the expression walker. */ @@ -1151,6 +1157,13 @@ gfc_code_walker (gfc_code **c, walk_code_fn_t code switch (co->op) { + + case EXEC_BLOCK: + WALK_SUBCODE (co->ext.block.ns->code); + for (alist = co->ext.block.assoc; alist; alist = alist->next) + WALK_SUBEXPR (alist->target); + break; + case EXEC_DO: WALK_SUBEXPR (co->ext.iterator->var); WALK_SUBEXPR (co->ext.iterator->start);