public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [gfortran] Fix PR 13201
@ 2004-05-31 22:50 Tobias Schlüter
  2004-06-08 23:54 ` Paul Brook
  0 siblings, 1 reply; 8+ messages in thread
From: Tobias Schlüter @ 2004-05-31 22:50 UTC (permalink / raw)
  To: GCC Fortran mailing list, patch


This patch updates the resolution stage to give an error, when a 
parameter array is never given an explicit shape. For instance, for the 
reduced testcase from the PR instead of ICEing later on, we now give:
[tobi@marktplatz tests]$ cat pr13201_2.f90
program test
   integer, parameter :: zeros(:) = (/ 0, 0 /)

   call mysub (zeros)
end program
[tobi@marktplatz tests]$ ../gcc/build-clean/gcc/f951 ./pr13201_2.f90
  In file ./pr13201_2.f90:2

   integer, parameter :: zeros(:) = (/ 0, 0 /)
                                1
Error: No shape specified for parameter array 'zeros' declared at (1)

Since code generation is not entered after errors in the frontend, the 
ICE doesn't happen any longer.

Compiled and tested on i686-pc-linux, the diff also contains a fix for 
coding style issues in the lines immediately preceding.

- Tobi

2004-05-31  Tobias Schlueter  <tobias.schlueter@physik.uni-muenchen.de>

	PR fortran/13201
	* resolve.c (resolve_symbol): Fix coding style issue. Don't
	allow parameter arrays with deferred shape.
	

Index: resolve.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/resolve.c,v
retrieving revision 1.4
diff -u -p -r1.4 resolve.c
--- resolve.c   18 May 2004 00:48:04 -0000      1.4
+++ resolve.c   31 May 2004 20:37:00 -0000
@@ -3736,9 +3736,17 @@ resolve_symbol (gfc_symbol * sym)
           || sym->as->type == AS_ASSUMED_SHAPE)
        && sym->attr.dummy == 0)
      {
-      gfc_error("Assumed %s array at %L must be a dummy argument",
-               sym->as->type == AS_ASSUMED_SIZE ? "size" : "shape",
-                &sym->declared_at);
+      gfc_error ("Assumed %s array at %L must be a dummy argument",
+                sym->as->type == AS_ASSUMED_SIZE ? "size" : "shape",
+                &sym->declared_at);
+      return;
+    }
+
+  if (sym->attr.flavor == FL_PARAMETER
+      && sym->as != NULL && sym->as->type == AS_DEFERRED)
+    {
+      gfc_error ("No shape specified for parameter array '%s' declared 
at %L",
+                sym->name, &sym->declared_at);
        return;
      }


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [gfortran] Fix PR 13201
  2004-05-31 22:50 [gfortran] Fix PR 13201 Tobias Schlüter
@ 2004-06-08 23:54 ` Paul Brook
  2004-06-09 14:00   ` Tobias Schlüter
  0 siblings, 1 reply; 8+ messages in thread
From: Paul Brook @ 2004-06-08 23:54 UTC (permalink / raw)
  To: fortran; +Cc: Tobias Schlüter, patch

> 2004-05-31  Tobias Schlueter  <tobias.schlueter@physik.uni-muenchen.de>
>
> 	PR fortran/13201
> 	* resolve.c (resolve_symbol): Fix coding style issue. Don't
> 	allow parameter arrays with deferred shape.
>
>
> Index: resolve.c
> ===================================================================
> RCS file: /cvs/gcc/gcc/gcc/fortran/resolve.c,v
> retrieving revision 1.4
> diff -u -p -r1.4 resolve.c
> --- resolve.c   18 May 2004 00:48:04 -0000      1.4
> +++ resolve.c   31 May 2004 20:37:00 -0000
> @@ -3736,9 +3736,17 @@ resolve_symbol (gfc_symbol * sym)
>
>            || sym->as->type == AS_ASSUMED_SHAPE)
>
>         && sym->attr.dummy == 0)
>       {
> -      gfc_error("Assumed %s array at %L must be a dummy argument",
> -               sym->as->type == AS_ASSUMED_SIZE ? "size" : "shape",
> -                &sym->declared_at);
> +      gfc_error ("Assumed %s array at %L must be a dummy argument",
> +                sym->as->type == AS_ASSUMED_SIZE ? "size" : "shape",
> +                &sym->declared_at);
> +      return;
> +    }
> +
> +  if (sym->attr.flavor == FL_PARAMETER
> +      && sym->as != NULL && sym->as->type == AS_DEFERRED)
> +    {
> +      gfc_error ("No shape specified for parameter array '%s' declared
> at %L",
> +                sym->name, &sym->declared_at);
>         return;
>       }

I'd prefer it if the message was change to
"Parameter '%s' at %L must have constant shape"
For consistency with other errors.
Other than that, Ok.

We also need to reject automatic arrays. I've modified the PR accordingly.

Paul

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [gfortran] Fix PR 13201
  2004-06-08 23:54 ` Paul Brook
@ 2004-06-09 14:00   ` Tobias Schlüter
  2004-06-09 16:43     ` Jonathan Lennox
  0 siblings, 1 reply; 8+ messages in thread
From: Tobias Schlüter @ 2004-06-09 14:00 UTC (permalink / raw)
  To: Paul Brook; +Cc: fortran, patch


Here's what I committed. I changed the check to "sym->as->type != 
AS_EXPLICIT", as this seems correct and caused no adverse effects. I 
also fixed an additional typo in the comment directly following.

- Tobi

Index: resolve.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/resolve.c,v
retrieving revision 1.4
diff -u -p -r1.4 resolve.c
--- resolve.c   18 May 2004 00:48:04 -0000      1.4
+++ resolve.c   9 Jun 2004 12:30:29 -0000
@@ -3736,14 +3736,22 @@ resolve_symbol (gfc_symbol * sym)
           || sym->as->type == AS_ASSUMED_SHAPE)
        && sym->attr.dummy == 0)
      {
-      gfc_error("Assumed %s array at %L must be a dummy argument",
-               sym->as->type == AS_ASSUMED_SIZE ? "size" : "shape",
-                &sym->declared_at);
+      gfc_error ("Assumed %s array at %L must be a dummy argument",
+                sym->as->type == AS_ASSUMED_SIZE ? "size" : "shape",
+                 &sym->declared_at);
+      return;
+    }
+
+  if (sym->attr.flavor == FL_PARAMETER
+      && sym->as != NULL && sym->as->type != AS_EXPLICIT)
+    {
+      gfc_error ("Parameter array '%s' at %L must have an explicit shape",
+                sym->name, &sym->declared_at);
        return;
      }

    /* Make sure that character string variables with assumed length are
-     dummy argument.  */
+     dummy arguments.  */

    if (sym->attr.flavor == FL_VARIABLE && !sym->attr.result
        && sym->ts.type == BT_CHARACTER

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [gfortran] Fix PR 13201
  2004-06-09 14:00   ` Tobias Schlüter
@ 2004-06-09 16:43     ` Jonathan Lennox
  2004-06-09 16:57       ` Joseph S. Myers
  0 siblings, 1 reply; 8+ messages in thread
From: Jonathan Lennox @ 2004-06-09 16:43 UTC (permalink / raw)
  To: Tobias Schlüter; +Cc: Paul Brook, fortran, patch

Tobias Schlüter writes:
> +      gfc_error ("Assumed %s array at %L must be a dummy argument",
> +                sym->as->type == AS_ASSUMED_SIZE ? "size" : "shape",
> +                 &sym->declared_at);

I know this isn't your code -- you're just re-indenting it -- but I noticed
that this error message is problematic from an I18N perspective.  Presumably
there should be two separate error messages issued?

-- 
Jonathan Lennox
lennox@cs.columbia.edu

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [gfortran] Fix PR 13201
  2004-06-09 16:43     ` Jonathan Lennox
@ 2004-06-09 16:57       ` Joseph S. Myers
  0 siblings, 0 replies; 8+ messages in thread
From: Joseph S. Myers @ 2004-06-09 16:57 UTC (permalink / raw)
  To: Jonathan Lennox; +Cc: Tobias Schlüter, Paul Brook, fortran, patch

On Wed, 9 Jun 2004, Jonathan Lennox wrote:

> Tobias Schlüter writes:
> > +      gfc_error ("Assumed %s array at %L must be a dummy argument",
> > +                sym->as->type == AS_ASSUMED_SIZE ? "size" : "shape",
> > +                 &sym->declared_at);
> 
> I know this isn't your code -- you're just re-indenting it -- but I noticed
> that this error message is problematic from an I18N perspective.  Presumably
> there should be two separate error messages issued?

I suggest adding this as a comment to bug 15586, which tracks gfortran's
lack of support for i18n.

-- 
Joseph S. Myers
jsm@polyomino.org.uk

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [gfortran] Fix PR 13201
  2004-07-09 21:30 ` Paul Brook
@ 2004-07-09 22:36   ` Tobias Schlüter
  0 siblings, 0 replies; 8+ messages in thread
From: Tobias Schlüter @ 2004-07-09 22:36 UTC (permalink / raw)
  To: Paul Brook; +Cc: fortran, patch

Paul Brook wrote:
> 
> The standard calls variables whose size is not known at compile time 
> "automatic objects".  My suggested wording is:
> 
> "Parameter array '%s' at %L cannot be automatic or assumed shape"
> 

I changed the error message to that wording. I also changed the name of
the new function to 'gfc_is_compile_time_shape'. For reference, here's
what I committed after verifying that it still builds.

I'll add a testcase in a minute.

- Tobi

Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/ChangeLog,v
retrieving revision 1.104
diff -u -p -r1.104 ChangeLog
--- ChangeLog   9 Jul 2004 14:54:43 -0000       1.104
+++ ChangeLog   9 Jul 2004 21:18:54 -0000
@@ -1,4 +1,12 @@
 2004-07-09  Tobias Schlueter  <tobias.schlueter@physik.uni-muenchen.de>
+
+       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_compile_time_shape): New function.
+       * gfortran.h (gfc_is_compile_time_shape): Add prototype.
+
+2004-07-09  Tobias Schlueter  <tobias.schlueter@physik.uni-muenchen.de>

        PR fortran/15481
        PR fortran/13372
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 21:18:54 -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_compile_time_shape (gfc_array_spec *);

 /* interface.c -- FIXME: some of these should be in symbol.c */
 void gfc_free_interface (gfc_interface *);
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 21:19:06 -0000
@@ -1973,3 +1973,22 @@ gfc_find_array_ref (gfc_expr * e)

   return &ref->u.ar;
 }
+
+
+/* Find out if an array shape is known at compile time.  */
+
+int
+gfc_is_compile_time_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: 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 21:19:06 -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_compile_time_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 cannot be automatic "
+                "or assumed shape", sym->name, &sym->declared_at);
+         return;
     }

   /* Make sure that character string variables with assumed length are

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [gfortran] Fix PR 13201
  2004-07-09 21:13 Tobias Schlüter
@ 2004-07-09 21:30 ` Paul Brook
  2004-07-09 22:36   ` Tobias Schlüter
  0 siblings, 1 reply; 8+ messages in thread
From: Paul Brook @ 2004-07-09 21:30 UTC (permalink / raw)
  To: fortran; +Cc: Tobias Schlüter, patch

On Friday 09 July 2004 21:30, Tobias Schlüter wrote:
> 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.

The standard calls variables whose size is not known at compile time 
"automatic objects".  My suggested wording is:

"Parameter array '%s' at %L cannot be automatic or assumed shape"

Assumed size already triggers a different error elsewhere.

> Built and tested on i686-pc-linux.
>
> - Tobi
>
> 2004-07-09  Tobias Schlueter  <tobias.schlueter@physik.uni-muenchen.de>
>
> 	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.

Ok.

Paul

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [gfortran] Fix PR 13201
@ 2004-07-09 21:13 Tobias Schlüter
  2004-07-09 21:30 ` Paul Brook
  0 siblings, 1 reply; 8+ messages in thread
From: Tobias Schlüter @ 2004-07-09 21:13 UTC (permalink / raw)
  To: patch, GCC Fortran mailing list


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  <tobias.schlueter@physik.uni-muenchen.de>
	
	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 *);

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2004-07-09 21:26 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-31 22:50 [gfortran] Fix PR 13201 Tobias Schlüter
2004-06-08 23:54 ` Paul Brook
2004-06-09 14:00   ` Tobias Schlüter
2004-06-09 16:43     ` Jonathan Lennox
2004-06-09 16:57       ` Joseph S. Myers
2004-07-09 21:13 Tobias Schlüter
2004-07-09 21:30 ` Paul Brook
2004-07-09 22:36   ` Tobias Schlüter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).