[Bug fortran/59450] [OOP] ICE for Array Valued Function combined with Deferred Specification Function

2013-12-10 Thread janus at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59450

janus at gcc dot gnu.org changed:

   What|Removed |Added

 Status|NEW |ASSIGNED
   Assignee|unassigned at gcc dot gnu.org  |janus at gcc dot gnu.org


[Bug fortran/59450] [OOP] ICE for Array Valued Function combined with Deferred Specification Function

2013-12-10 Thread janus at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59450

--- Comment #4 from janus at gcc dot gnu.org ---
(In reply to janus from comment #2)
> Draft patch which fixes the error (not regtested):

Does regtest cleanly.


[Bug fortran/59450] [OOP] ICE for Array Valued Function combined with Deferred Specification Function

2013-12-10 Thread janus at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59450

--- Comment #3 from janus at gcc dot gnu.org ---
Additional problem (unrelated to the ICE): Removing 'pure' in comment 1 yields
the error:

integer, dimension( this%get_num() ) :: array
   1
Error: Function 'this' at (1) must be PURE


An error about missing pureness is correct in principle, but there are two
problems with this:
1) The function name in the error message is wrong: There is no function named
'this'.
2) The error appears twice.


[Bug fortran/59450] [OOP] ICE for Array Valued Function combined with Deferred Specification Function

2013-12-10 Thread janus at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59450

--- Comment #2 from janus at gcc dot gnu.org ---
Draft patch which fixes the error (not regtested):


Index: gcc/fortran/module.c
===
--- gcc/fortran/module.c(revision 205857)
+++ gcc/fortran/module.c(working copy)
@@ -3358,12 +3358,24 @@ mio_expr (gfc_expr **ep)
 {
   e->value.function.name
 = mio_allocated_string (e->value.function.name);
-  flag = e->value.function.esym != NULL;
+  if (e->value.function.esym)
+flag = 1;
+  else if (e->ref)
+flag = 2;
+  else
+flag = 0;
   mio_integer (&flag);
-  if (flag)
-mio_symbol_ref (&e->value.function.esym);
-  else
-write_atom (ATOM_STRING, e->value.function.isym->name);
+  switch (flag)
+{
+case 1:
+  mio_symbol_ref (&e->value.function.esym);
+  break;
+case 2:
+  mio_ref_list (&e->ref);
+  break;
+default:
+  write_atom (ATOM_STRING, e->value.function.isym->name);
+}
 }
   else
 {
@@ -3372,10 +3384,15 @@ mio_expr (gfc_expr **ep)
   free (atom_string);

   mio_integer (&flag);
-  if (flag)
-mio_symbol_ref (&e->value.function.esym);
-  else
+  switch (flag)
 {
+case 1:
+  mio_symbol_ref (&e->value.function.esym);
+  break;
+case 2:
+  mio_ref_list (&e->ref);
+  break;
+default:
   require_atom (ATOM_STRING);
   e->value.function.isym = gfc_find_function (atom_string);
   free (atom_string);


[Bug fortran/59450] [OOP] ICE for Array Valued Function combined with Deferred Specification Function

2013-12-10 Thread janus at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59450

janus at gcc dot gnu.org changed:

   What|Removed |Added

   Keywords||ice-on-valid-code
 Status|UNCONFIRMED |NEW
   Last reconfirmed||2013-12-10
 CC||janus at gcc dot gnu.org
Summary|ICE for Array Valued|[OOP] ICE for Array Valued
   |Function combined with  |Function combined with
   |Deferred Specification  |Deferred Specification
   |Function|Function
 Ever confirmed|0   |1

--- Comment #1 from janus at gcc dot gnu.org ---
Confirmed. Thanks for the bug report.

Here is a variant with a non-abstract class which shows the same ICE (with
every version I tried - from 4.6 to trunk):


module classes

  implicit none

  type :: base_class
   contains
 procedure, nopass :: get_num
  end type

contains

  pure integer function get_num()
  end function

  function get_array( this ) result(array)
class(base_class), intent(in) :: this
integer, dimension( this%get_num() ) :: array
  end function

end module