From patchwork Sat Nov 19 09:12:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janus Weil X-Patchwork-Id: 696819 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tLTg23QX0z9t1P for ; Sat, 19 Nov 2016 20:13:17 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="Kea6zdVN"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; q=dns; s=default; b=QO87ZC6uGcI9ZPn byJWwvVhJ7oyU518AWh2WLR/eBJjibODXpXEKcL4V7Wqr839RIreRCdMM4UUiprE tiOuT6xlxyQG3LhFGY885/xO63OANCgBamdeWMeMRYw1bj83zJFmsDuuXPe5U1cN NHZMhMLxLaE2wOL2Y8AyvuAkuSu0= 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 :mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; s=default; bh=gApVmhrV/tMAsVNx6p4db VeQjSQ=; b=Kea6zdVNxbyOql2EEiX/so6uqZbAifIDrUGfjvqy5GXaMCXDzGjs1 BAhQNzK/UPfkYZlAeApGA112XxybD6Tao9FjwD6KjYs6Rs8rTMXYKr90/+hXZ4QX iaKru13Lj/F3sFrQsPKEk++DhsyxDnNTJrtEsKmSrqBlFMvdzOhVIw= Received: (qmail 32917 invoked by alias); 19 Nov 2016 09:12:56 -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 32852 invoked by uid 89); 19 Nov 2016 09:12:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.4 required=5.0 tests=AWL, BAYES_00, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=suspicion, HX-Received:Sat, sk:gfc_is_, claims X-Spam-User: qpsmtpd, 3 recipients X-HELO: mail-yb0-f194.google.com Received: from mail-yb0-f194.google.com (HELO mail-yb0-f194.google.com) (209.85.213.194) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 19 Nov 2016 09:12:45 +0000 Received: by mail-yb0-f194.google.com with SMTP id v78so10332302ybe.0; Sat, 19 Nov 2016 01:12:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=fVULYBMIS/LHgSa0ID98LFcUqNBUv+Ktpleu/qfBbEs=; b=Qqf7ZyP1CyRFO7otUsA+SxwY6TR4Szc6H5ytv9kYWfM+TtrFJi2uaOSScMDi4Ay99u 1WsUOwgPHEPwDosy3pgerO2mJUf4CF1t4B3ykAmZhFCyFnrIirGZZX0Tv6PY0kk1UR6M Pvpreli0gJSJvshnmkoGgs0pUf7nkuCXiZ47+GKAZEfRLM8epnsm2v+Ml+HBsdIAG2vH fbqslReS9SnJo5affyDghVCa6MzEyXvAI5bJB6u+qfnKJ8x28M1YUYL0EvkNaMAj2o9n 997MGP+dF8F2zLe88ZxM0y+r3517jXZuUAAqbdgU/Uewh0yN0TWIzbyJplepz1ArSJMM v20A== X-Gm-Message-State: AKaTC03Z8tXTQXiJIlKZIuEEdenVW5rONhq1CtckckDDDfDdsNqyxU5rpKp82mSOYdRuFEdAb8Jsrq3M8s8MjA== X-Received: by 10.37.68.132 with SMTP id r126mr2051365yba.7.1479546763110; Sat, 19 Nov 2016 01:12:43 -0800 (PST) MIME-Version: 1.0 Received: by 10.129.52.2 with HTTP; Sat, 19 Nov 2016 01:12:42 -0800 (PST) In-Reply-To: References: <2709BC01-540E-4BB6-8266-355357EA7138@lps.ens.fr> From: Janus Weil Date: Sat, 19 Nov 2016 10:12:42 +0100 Message-ID: Subject: Re: [Patch, Fortran] PR 78392: ICE in gfc_trans_auto_array_allocation, at fortran/trans-array.c:5979 To: =?UTF-8?Q?Dominique_d=27Humi=C3=A8res?= Cc: gfortran , gcc-patches , Jerry DeLisle Hi all, > I previously assumed that the test case for this PR would be legal, > but by now I think that's wrong. The test case should be rejected, and > we already have checking mechanisms for this (see > resolve_fl_variable), but apparently they are not working. > > My current suspicion is that 'gfc_is_constant_expr' has a bug, because > it claims the call to the function 'get_i' to be a constant > expression. This is not true, because get_i() can not be reduced to a > compile-time constant. some more reading in the standard confirms this suspicion: In gfc_is_constant_expr there is a piece of code which claims that specification functions are constant. That is certainly not true, and so what I'm doing in the attached fix is to remove that code and add some references to the standard to make things clearer. The code that I'm removing has last been touched in this commit by Jerry six years ago: https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=166520 However, this did not introduce the bug in the first place (not sure when that happened). In any case the new patch in the attachment regtests cleanly and correctly rejects the original test case as well as one of the cases mentioned by Dominique. Ok for trunk? Cheers, Janus 2016-11-19 Janus Weil PR fortran/78392 * expr.c (gfc_is_constant_expr): Specification functions are not compile-time constants. Update documentation (add reference to F08 standard), add a FIXME. (external_spec_function): Add reference to F08 standard. * resolve.c (resolve_fl_variable): Ditto. 2016-11-19 Janus Weil PR fortran/78392 * gfortran.dg/constant_shape.f90: New test case. Index: gcc/fortran/expr.c =================================================================== --- gcc/fortran/expr.c (Revision 242620) +++ gcc/fortran/expr.c (Arbeitskopie) @@ -883,8 +883,9 @@ done: } -/* Function to determine if an expression is constant or not. This - function expects that the expression has already been simplified. */ +/* Determine if an expression is constant in the sense of F08:7.1.12. + * This function expects that the expression has already been simplified. + * FIXME: Return a bool, not an int. */ int gfc_is_constant_expr (gfc_expr *e) @@ -891,7 +892,6 @@ gfc_is_constant_expr (gfc_expr *e) { gfc_constructor *c; gfc_actual_arglist *arg; - gfc_symbol *sym; if (e == NULL) return 1; @@ -920,25 +920,6 @@ gfc_is_constant_expr (gfc_expr *e) return 0; } - /* Specification functions are constant. */ - /* F95, 7.1.6.2; F2003, 7.1.7 */ - sym = NULL; - if (e->symtree) - sym = e->symtree->n.sym; - if (e->value.function.esym) - sym = e->value.function.esym; - - if (sym - && sym->attr.function - && sym->attr.pure - && !sym->attr.intrinsic - && !sym->attr.recursive - && sym->attr.proc != PROC_INTERNAL - && sym->attr.proc != PROC_ST_FUNCTION - && sym->attr.proc != PROC_UNKNOWN - && gfc_sym_get_dummy_args (sym) == NULL) - return 1; - if (e->value.function.isym && (e->value.function.isym->elemental || e->value.function.isym->pure @@ -2741,7 +2722,8 @@ restricted_args (gfc_actual_arglist *a) /************* Restricted/specification expressions *************/ -/* Make sure a non-intrinsic function is a specification function. */ +/* Make sure a non-intrinsic function is a specification function, + * see F08:7.1.11.5. */ static bool external_spec_function (gfc_expr *e) Index: gcc/fortran/resolve.c =================================================================== --- gcc/fortran/resolve.c (Revision 242620) +++ gcc/fortran/resolve.c (Arbeitskopie) @@ -11831,8 +11831,8 @@ resolve_fl_variable (gfc_symbol *sym, int mp_flag) && !sym->attr.pointer && is_non_constant_shape_array (sym)) { - /* The shape of a main program or module array needs to be - constant. */ + /* F08:C541. The shape of an array defined in a main program or module + * needs to be constant. */ gfc_error ("The module or main program array %qs at %L must " "have constant shape", sym->name, &sym->declared_at); specification_expr = saved_specification_expr;