From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13908 invoked by alias); 9 Jul 2004 20:30:56 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 13882 invoked from network); 9 Jul 2004 20:30:55 -0000 Received: from unknown (HELO geburtsjahr.neunzehnhunderteinundachtzig.de) (217.160.92.50) by sourceware.org with SMTP; 9 Jul 2004 20:30:55 -0000 Received: from bauernhof (p54802415.dip.t-dialin.net [84.128.36.21]) by geburtsjahr.neunzehnhunderteinundachtzig.de (Postfix) with ESMTP id 10C5F8FC72; Fri, 9 Jul 2004 22:31:47 +0200 (CEST) Received: from physik.uni-muenchen.de (unknown [192.168.1.6]) by bauernhof (Postfix) with ESMTP id C63C163151; Fri, 9 Jul 2004 22:30:35 +0200 (CEST) Message-ID: <40EF0064.90805@physik.uni-muenchen.de> Date: Fri, 09 Jul 2004 21:13:00 -0000 From: =?ISO-8859-1?Q?Tobias_Schl=FCter?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040506 MIME-Version: 1.0 To: patch , GCC Fortran mailing list Subject: [gfortran] Fix PR 13201 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-SW-Source: 2004-07/txt/msg01002.txt.bz2 My previous fixlet for PR 13201 didn't catch the general case of a parameter array not having a constant shape. This followup patch fixes that omission. Looking the patch over, I think a better name than 'constant shape' is probably called for. I'm open to suggestions how to concisely say 'explicit shape, determined at compile time by means of constants'. I will definitely enhance the comment in array.c. Built and tested on i686-pc-linux. - Tobi 2004-07-09 Tobias Schlueter PR fortran/13201 * resolve.c (resolve_symbol): Verify that the shape of a parameter array is not only explicit, but also constant. * array.c (gfc_is_constant_shape): New function. * gfortran.h (gfc_is_constant_shape): Add prototype. Index: resolve.c =================================================================== RCS file: /cvs/gcc/gcc/gcc/fortran/resolve.c,v retrieving revision 1.9 diff -u -p -r1.9 resolve.c --- resolve.c 9 Jul 2004 14:53:39 -0000 1.9 +++ resolve.c 9 Jul 2004 20:23:42 -0000 @@ -3745,12 +3745,14 @@ resolve_symbol (gfc_symbol * sym) return; } - if (sym->attr.flavor == FL_PARAMETER - && sym->as != NULL && sym->as->type != AS_EXPLICIT) + /* A parameter array's shape needs to be constant. */ + + if (sym->attr.flavor == FL_PARAMETER && sym->as != NULL + && !gfc_is_constant_shape (sym->as)) { - gfc_error ("Parameter array '%s' at %L must have an explicit shape", - sym->name, &sym->declared_at); - return; + gfc_error ("Parameter array '%s' at %L must have an explicit, " + "constant shape", sym->name, &sym->declared_at); + return; } /* Make sure that character string variables with assumed length are Index: array.c =================================================================== RCS file: /cvs/gcc/gcc/gcc/fortran/array.c,v retrieving revision 1.5 diff -u -p -r1.5 array.c --- array.c 21 Jun 2004 17:16:25 -0000 1.5 +++ array.c 9 Jul 2004 20:23:42 -0000 @@ -1973,3 +1973,22 @@ gfc_find_array_ref (gfc_expr * e) return &ref->u.ar; } + + +/* Find out if an array shape is constant. */ + +int +gfc_is_constant_shape (gfc_array_spec *as) +{ + int i; + + if (as->type != AS_EXPLICIT) + return 0; + + for (i = 0; i < as->rank; i++) + if (!gfc_is_constant_expr (as->lower[i]) + || !gfc_is_constant_expr (as->upper[i])) + return 0; + + return 1; +} Index: gfortran.h =================================================================== RCS file: /cvs/gcc/gcc/gcc/fortran/gfortran.h,v retrieving revision 1.17 diff -u -p -r1.17 gfortran.h --- gfortran.h 4 Jul 2004 17:00:11 -0000 1.17 +++ gfortran.h 9 Jul 2004 20:23:42 -0000 @@ -1645,6 +1645,7 @@ void gfc_insert_constructor (gfc_expr *, gfc_constructor *gfc_get_constructor (void); tree gfc_conv_array_initializer (tree type, gfc_expr * expr); try spec_size (gfc_array_spec *, mpz_t *); +int gfc_is_constant_shape (gfc_array_spec *); /* interface.c -- FIXME: some of these should be in symbol.c */ void gfc_free_interface (gfc_interface *);