This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Support ENTRY in FUNCTIONs (PR fortran/13082)


Jakub Jelinek wrote:
> 2005-04-08  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR fortran/13082
> 	* trans.h (current_function_namespace): Declare.
> 	* trans-expr.c (gfc_conv_variable): Handle return values in functions
> 	with alternate entry points.
> 	* resolve.c (resolve_entries): Set result of entry master.
> 	If all entries have the same type, set entry master's type
> 	to that common type.
> 	* decl.c (gfc_match_entry): Set entry->result properly for
> 	function ENTRY.
> 	* trans-decl.c (current_function_namespace): New global variable.
> 	(build_entry_thunks): Save, set and restore
> 	current_function_namespace.  Handle return values in entry
> 	thunks if all entries have the same type.  Clear BT_CHARACTER's
> 	ts.cl->backend_decl, so that it is not shared between multiple
> 	contexts.
> 	(gfc_get_fake_result_decl): Use DECL_ARGUMENTS from
> 	current_function_decl instead of sym->backend_decl.  Skip over
> 	entry master's entry id argument.
> 	(gfc_generate_function_code): Save, set and restore
> 	current_function_namespace.  For entry master returning
> 	CHARACTER, copy ts.cl->backend_decl to all entry result syms.
> 
> 	* gfortran.dg/entry_3.f90: New test.
> 	* gfortran.dg/entry_4.f90: New test.

Unfortunately, this fails a few simple tests I've put it through:
[tobi@marktplatz tests]$ cat entry.f90
   module m
   contains
   function f(x)
     f = x
     return
   entry g(y)
     g = y
     return
   end function
   end module
[tobi@marktplatz tests]$ ~/src/gcc-new/build/gcc/f951 entry.f90
-fdump-tree-original
 f

entry.f90:27: internal compiler error: in convert_move, at expr.c:339
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.

[tobi@marktplatz tests]$ cat entry2.f90
   module m
   contains
   function f(x)
     real :: f, g
     f = x
     return
   entry g(y)
     g = y
     return
   end function
   end module

[tobi@marktplatz tests]$ ~/src/gcc-new/build/gcc/f951 entry.f90
-fdump-tree-original
 In file entry.f90:34

   entry g(y)
         1
 Internal Error at (1):
 insert_bbt(): Duplicate key found!

[tobi@marktplatz tests]$ cat entry3.f90
function c(a)
character*5 :: b, c
c = "HALLO"
return
entry b()
b = "BLUBB"
return
end function c
[tobi@marktplatz tests]$ ~/src/gcc-new/build/gcc/f951 entry.f90
-fdump-tree-original
 c
 b
 master.0.c

entry.f90:77: internal compiler error: tree check: expected class
‘declaration’, have ‘constant’ (integer_cst) in gfc_add_decl_to_function, at
fortran/trans-decl.c:151
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.

(This one really surprised me, given that your testcase for characters works)

Also you have no testcase for entries with derived type, they do seem to work
outside of modules, but I'd rather this is tested.  I attached a simple testcase.

The third bug is a showstopper.  While entries within modules are not as
important (the usual application of entries seems to be getting module-like
encapsulation, so there's no point of using them inside modules), we should
definitely should get them right outside of modules.

I have no idea what the reason for the first bug is, the second bug points to
a deficiency in symbol handling which is not your fault, apparently the
resolution of contained functions and entries interact badly.

For my education: you assume that current_function_namespace is initialized to
NULL.  Is this a valid assumption?

WRT to the whole series: this work is highly appreciated.  In the third patch
I'd prefer if you gave an error if the user uses an invalid combination of
types, otherwise you're introducing an accepts-invalid bug.  I'm fine with a
failing assertion, given the second of my bugs, resolution will have to be
rewritten anyway.

- Tobi
! { dg-do run }
module m
type t
  integer i
  real x(5)
end type t
end module m

function f(i)
  use m
  type(t) :: f,g
  f % i = i
  return
  entry g(x)
  g%x = x
end function f

use m
type (t):: f,g, res

res = f(42)
if (res%i /= 42) call abort
res = g(1.)
if (any (res%x /= 1.)) call abort
end



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]