public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch, Fortran, OOP] PR 44962: [OOP] ICE with specification  expression SIZE(<CLASS>)
@ 2010-07-18 16:36 Janus Weil
  2010-07-18 17:28 ` Steve Kargl
  2010-07-20 21:39 ` Tobias Burnus
  0 siblings, 2 replies; 16+ messages in thread
From: Janus Weil @ 2010-07-18 16:36 UTC (permalink / raw)
  To: gfortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1345 bytes --]

Hi all,

the cause of this PR was that the array spec of a vtype's PPC was not
correctly resolved. The attached patch corrects this and does some
related cleanup in three places:

1) In resolve_fl_derived, I'm replacing a piece of code by a call to
gfc_resolve_array_spec, which should do exactly the same checks. Plus:
It should correctly resolve the array spec for PPCs.

2) In resolve_array_bound, I'm modifying an error message which
assumed that the expression of the array bound is always a variable
(which is clearly wrong and results in an ICE when the expression is
not a variable).

3) In gfc_is_constant_expr, I'm adding a special case for the RAND()
and IRAND() intrinsic functions, which were detected to be constant
before. [I'm assuming that a "constant expression" is something that
can be reduced to a constant at compile time, which the random
functions are clearly not.]

The patch was regtested on x86_64-unknown-linux-gnu. Ok for trunk?

Cheers,
Janus



2010-07-18  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/44962
	* array.c (resolve_array_bound): Modify error message.
	* expr.c (gfc_is_constant_expr): Detect RAND() and IRAND() as
	non-constant.
	* resolve.c (resolve_fl_derived): Call gfc_resolve_array_spec.


2010-07-18  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/44962
	* gfortran.dg/typebound_proc_17.f03: New.

[-- Attachment #2: pr44962_v2.diff --]
[-- Type: application/octet-stream, Size: 2722 bytes --]

Index: gcc/fortran/array.c
===================================================================
--- gcc/fortran/array.c	(revision 162282)
+++ gcc/fortran/array.c	(working copy)
@@ -302,8 +302,7 @@ resolve_array_bound (gfc_expr *e, int check_consta
 
   if (check_constant && gfc_is_constant_expr (e) == 0)
     {
-      gfc_error ("Variable '%s' at %L in this context must be constant",
-		 e->symtree->n.sym->name, &e->where);
+      gfc_error ("Array bound at %L must be constant", &e->where);
       return FAILURE;
     }
 
Index: gcc/fortran/expr.c
===================================================================
--- gcc/fortran/expr.c	(revision 162282)
+++ gcc/fortran/expr.c	(working copy)
@@ -925,10 +925,18 @@ gfc_is_constant_expr (gfc_expr *e)
       /* Call to intrinsic with at least one argument.  */
       if (e->value.function.isym && e->value.function.actual)
 	{
-	  for (arg = e->value.function.actual; arg; arg = arg->next)
-	    if (!gfc_is_constant_expr (arg->expr))
+	  switch (e->value.function.isym->id)
+	    {
+	    case GFC_ISYM_IRAND:
+	    case GFC_ISYM_RAND:
+	      /* RNG functions are by definition not constant.  */
 	      return 0;
-
+	    default:
+	      /* Check for constant arguments.  */
+	      for (arg = e->value.function.actual; arg; arg = arg->next)
+		if (!gfc_is_constant_expr (arg->expr))
+		  return 0; 
+	    }
 	  return 1;
 	}
       else
Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c	(revision 162282)
+++ gcc/fortran/resolve.c	(working copy)
@@ -10733,7 +10733,6 @@ resolve_fl_derived (gfc_symbol *sym)
 {
   gfc_symbol* super_type;
   gfc_component *c;
-  int i;
 
   super_type = gfc_get_derived_super_type (sym);
   
@@ -11089,25 +11088,10 @@ resolve_fl_derived (gfc_symbol *sym)
 	    && sym != c->ts.u.derived)
 	add_dt_to_dt_list (c->ts.u.derived);
 
-      if (c->attr.pointer || c->attr.proc_pointer || c->attr.allocatable
-	  || c->as == NULL)
-	continue;
-
-      for (i = 0; i < c->as->rank; i++)
-	{
-	  if (c->as->lower[i] == NULL
-	      || (resolve_index_expr (c->as->lower[i]) == FAILURE)
-	      || !gfc_is_constant_expr (c->as->lower[i])
-	      || c->as->upper[i] == NULL
-	      || (resolve_index_expr (c->as->upper[i]) == FAILURE)
-	      || !gfc_is_constant_expr (c->as->upper[i]))
-	    {
-	      gfc_error ("Component '%s' of '%s' at %L must have "
-			 "constant array bounds",
-			 c->name, sym->name, &c->loc);
-	      return FAILURE;
-	    }
-	}
+      if (gfc_resolve_array_spec (c->as, !(c->attr.pointer
+					   || c->attr.proc_pointer
+					   || c->attr.allocatable)) == FAILURE)
+	return FAILURE;
     }
 
   /* Resolve the type-bound procedures.  */

[-- Attachment #3: typebound_proc_17.f03 --]
[-- Type: application/octet-stream, Size: 596 bytes --]

! { dg-do compile }
!
! PR 44962: [OOP] ICE with specification expression SIZE(<CLASS>)
!
! Contributed by Satish.BD <bdsatish@gmail.com>


module array

type :: t_array
  real, dimension(10) :: coeff
contains
  procedure :: get_coeff
end type t_array

contains

function get_coeff(self) result(coeff)
  class(t_array), intent(in) :: self
  real, dimension(size(self%coeff)) :: coeff !! The SIZE here carashes !!
end function get_coeff

end module array


type :: t2
  real, dimension(irand()+5) :: co2  ! { dg-error "must be constant" }
end type

end

! { dg-final { cleanup-modules "array" } }

^ permalink raw reply	[flat|nested] 16+ messages in thread
* Re: [Patch, Fortran, OOP] PR 44962: [OOP] ICE with specification expression SIZE(<CLASS>)
@ 2010-07-18 18:54 Dominique Dhumieres
  0 siblings, 0 replies; 16+ messages in thread
From: Dominique Dhumieres @ 2010-07-18 18:54 UTC (permalink / raw)
  To: fortran; +Cc: sgk, janus, gcc-patches

If I have read correctly the gfortran manual, RAND and IRAND are GNU
extensions for compatibility with g77. Is it worth any effort to
include them in post f90 use?

Dominique

^ permalink raw reply	[flat|nested] 16+ messages in thread
* Re: [Patch, Fortran, OOP] PR 44962: [OOP] ICE with specification expression SIZE(<CLASS>)
@ 2010-07-26  7:20 Dominique Dhumieres
  0 siblings, 0 replies; 16+ messages in thread
From: Dominique Dhumieres @ 2010-07-26  7:20 UTC (permalink / raw)
  To: fortran; +Cc: gcc-patches, burnus, janus

Janus,

I just noticed that you have changed the test typebound_proc_17.f03
between revisions of your patch:

--- typebound_proc_17_old.f03	2010-07-26 07:45:13.000000000 +0200
+++ /opt/gcc/work/gcc/testsuite/gfortran.dg/typebound_proc_17.f03	2010-07-26 07:15:54.000000000 +0200
@@ -24,14 +24,11 @@ end module array
 
 
 type :: t2
-  real, dimension(irand()+5) :: co2  ! { dg-error "must be constant" }
+  real, dimension(iabs(-3)+2) :: com
 end type
 
-type(t2) :: a
+real, dimension(irand()+2) :: r2   ! { dg-error "must have constant shape" }
 
-print *, size(a%co2)
-a%co2 = 1.0
-print *, a
 end
 
 ! { dg-final { cleanup-modules "array" } }

(where I have added the last 4 '-' lines for testing as commented below).

With the latest patch the line

  real, dimension(irand()+5) :: co2  ! { dg-error "must be constant" }

in "type :: t2" no longer triggers the error. Is it according the last lines
of f2008 [7.1.11] quoted by Tobias Burnus? If yes, is it normal that
"print *, size(a%co2)" yields 0?

Also when compiled with -std=f2003, both versions give the error:

real, dimension(irand()+*) :: *   ! { dg-error "must *" }
                1
Error: Specification function 'irand' at (1) must be PURE

Has this constraint been removed in f2008?

Finally, as I said in a previous post, the *rand functions are
g77 extensions and their use should probably discouraged in
post f90 codes. If the issues raised by Tobias appear only
for these functions, is it really necessary to spend too
much time on them?

Cheers,

Dominique

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

end of thread, other threads:[~2010-07-29 21:00 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-18 16:36 [Patch, Fortran, OOP] PR 44962: [OOP] ICE with specification expression SIZE(<CLASS>) Janus Weil
2010-07-18 17:28 ` Steve Kargl
2010-07-18 17:55   ` Janus Weil
2010-07-18 18:46     ` Steve Kargl
2010-07-18 19:00       ` Janus Weil
2010-07-20 21:39 ` Tobias Burnus
2010-07-21 21:23   ` Janus Weil
2010-07-21 22:20     ` Janus Weil
2010-07-21 22:48     ` Tobias Burnus
2010-07-22 20:58       ` Janus Weil
2010-07-23 11:37         ` Janus Weil
2010-07-26  6:15         ` Tobias Burnus
2010-07-29 20:18           ` Janus Weil
2010-07-29 21:07             ` Janus Weil
2010-07-18 18:54 Dominique Dhumieres
2010-07-26  7:20 Dominique Dhumieres

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).