From patchwork Sun Jul 28 12:57:48 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 262587 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 6BFF42C0114 for ; Sun, 28 Jul 2013 22:58:12 +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=TwuH68vtSfXQ30KRbT6F4m+lXraFswRVNo8VGYFU6UsBfk LFlNvnfmwgEQO3FpDtwYCaCrWcmJLoaWNfxHfZlXv0xBC803WPufbKtiAaD1rFAJ wvdoIQmfQX1b5MGmB1/3Y8LUWierB/l2Xiw0jY7ZFvljPT4pOO0mFgf0xyjZo= 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=XljNyWmQvGCM50aSeqqATemNkJc=; b=TLH1IkF7styvFT6JbTQ7 ZLUy2Lgwxb1V4GBiMPhP/DGNinHUGg6KPfo6I4UBrlLn5iJkLwFMa13KfOEvDrhn G9c5SmaL51c58RJeoMl9pPGmoxl3dBjI4At1XsMoA/ifNs/qQkc0d9ueUsZIde2F IziLXIOXPWlGog3rjxqwZpU= Received: (qmail 30642 invoked by alias); 28 Jul 2013 12:58:00 -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 30625 invoked by uid 89); 28 Jul 2013 12:58:00 -0000 X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_NO, RDNS_NONE autolearn=no version=3.3.1 X-Spam-User: qpsmtpd, 2 recipients Received: from Unknown (HELO cc-smtpout2.netcologne.de) (89.1.8.212) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Sun, 28 Jul 2013 12:57:58 +0000 Received: from cc-smtpin1.netcologne.de (cc-smtpin1.netcologne.de [89.1.8.201]) by cc-smtpout2.netcologne.de (Postfix) with ESMTP id D21BD124D4; Sun, 28 Jul 2013 14:57:50 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by cc-smtpin1.netcologne.de (Postfix) with ESMTP id B213511D7E; Sun, 28 Jul 2013 14:57:50 +0200 (CEST) Received: from [78.35.158.36] (helo=cc-smtpin1.netcologne.de) by localhost with ESMTP (eXpurgate 4.0.0) (envelope-from ) id 51f5154e-0b65-7f0000012729-7f0000019497-1 for ; Sun, 28 Jul 2013 14:57:50 +0200 Received: from [192.168.0.110] (xdsl-78-35-158-36.netcologne.de [78.35.158.36]) by cc-smtpin1.netcologne.de (Postfix) with ESMTPSA; Sun, 28 Jul 2013 14:57:49 +0200 (CEST) Message-ID: <51F5154C.20604@netcologne.de> Date: Sun, 28 Jul 2013 14:57:48 +0200 From: Thomas Koenig User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130620 Thunderbird/17.0.7 MIME-Version: 1.0 To: "fortran@gcc.gnu.org" , gcc-patches Subject: [patch, fortran] PR Detect same values in vector expression subscripts X-Virus-Found: No Hello world, this patch yields an error for identical values in vector expression subscripts. The algorithm is O(n**2) because a) It would be impossible to detect a([i,i]) otherwise b) This is not likely to be a performance bottleneck because people don't use large vector indices. (as noted by the different comments in the PR). Regression-tested. OK for trunk? Thomas 2013-07-28 Thomas Koenig PR fortran/58009 * expr.c (gfc_check_vardef_context): Check for same values in vector expression subscripts. 2013-07-28 Thomas Koenig PR fortran/58009 * gfortran.dg/vector_subsript_7.f90: New test. Index: expr.c =================================================================== --- expr.c (Revision 200743) +++ expr.c (Arbeitskopie) @@ -4700,6 +4700,8 @@ gfc_check_vardef_context (gfc_expr* e, bool pointe bool unlimited; symbol_attribute attr; gfc_ref* ref; + bool retval; + int i; if (e->expr_type == EXPR_VARIABLE) { @@ -4922,5 +4924,54 @@ gfc_check_vardef_context (gfc_expr* e, bool pointe } } - return true; + /* Check for same value in vector expression subscript. */ + retval = true; + + if (e->rank > 0) + for (ref = e->ref; ref != NULL; ref = ref->next) + if (ref->type == REF_ARRAY && ref->u.ar.type == AR_SECTION) + for (i = 0; irank; i++) + if (ref->u.ar.dimen_type[i] == DIMEN_VECTOR) + { + gfc_expr *arr = ref->u.ar.start[i]; + if (arr->expr_type == EXPR_ARRAY) + { + gfc_constructor *c, *n; + gfc_expr *ec, *en; + + for (c = gfc_constructor_first (arr->value.constructor); + c != NULL; c = gfc_constructor_next (c)) + { + if (c == NULL || c->iterator != NULL) + continue; + + ec = c->expr; + + for (n = gfc_constructor_next (c); n != NULL; + n = gfc_constructor_next (n)) + { + if (n->iterator != NULL) + continue; + + en = n->expr; + if (gfc_dep_compare_expr (ec, en) == 0) + { + gfc_error_now ("Elements with the same value at %L" + " and %L in vector subscript" + " in a variable definition" + " context (%s)", &(ec->where), + &(en->where), context); + retval = false; + + /* Do not issue O(n**2) errors for n occurrences + of the same value. */ + break; + + } + } + } + } + } + + return retval; }