Bug 42650 - F90: DT function with in-line DT definition and RESULT is rejected
F90: DT function with in-line DT definition and RESULT is rejected
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: fortran
4.5.0
: P3 normal
: ---
Assigned To: Tobias Burnus
: rejects-valid
Depends on:
Blocks: 32834
  Show dependency treegraph
 
Reported: 2010-01-07 16:48 UTC by Tobias Burnus
Modified: 2010-02-02 14:27 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2010-02-01 22:46:13


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2010-01-07 16:48:49 UTC
The one of following valid Fortran 90 functions is rejected: While the first function "func" works and has function name = result name, the second ("func2"), which uses RESULT(), is rejected with the error message:

Error: The type for function 'func2' at (1) is not accessible


type(t) function func()
  type t
    sequence
    integer :: i = 5
  end type t
end function func

type(t) function func2() result(res)
  type t
    sequence
    integer :: i = 5
  end type t
end function func2
Comment 1 Paul Thomas 2010-01-08 05:47:58 UTC
type(t) function func2() result(res)
  type t
    sequence
    integer :: i = 5
  end type t
  res%i = 2
end function func2

causes a segmentation fault!

Confirmed

Paul
Comment 2 Tobias Burnus 2010-02-01 22:16:56 UTC
The problem is somehow that for the second parsing using decl.c's gfc_match_decl_type_spec one has in:

  else if (ts->kind == -1)
    {
      int iface = gfc_state_stack->previous->state != COMP_INTERFACE
                    || gfc_current_ns->has_import_set;
      if (gfc_find_symbol (name, NULL, iface, &sym))
        {
          gfc_error ("Type name '%s' at %C is ambiguous", name);
          return MATCH_ERROR;
        }

the result  sym == NULL with RESULT() but not without RESULT(); while "iface==1" and name == "t" for both cases.
Comment 3 Tobias Burnus 2010-02-01 22:46:13 UTC
Patch:

Index: gcc/fortran/parse.c
===================================================================
--- gcc/fortran/parse.c   (Revision 156433)
+++ gcc/fortran/parse.c
@@ -111,7 +111,7 @@ decode_specification_statement (void)
   match ("import", gfc_match_import, ST_IMPORT);
   match ("use", gfc_match_use, ST_USE);

-  if (gfc_current_block ()->ts.type != BT_DERIVED)
+  if (gfc_current_block ()->result->ts.type != BT_DERIVED)
     goto end_of_block;

   match (NULL, gfc_match_st_function, ST_STATEMENT_FUNCTION);
Comment 4 Tobias Burnus 2010-02-02 13:06:04 UTC
Subject: Bug 42650

Author: burnus
Date: Tue Feb  2 13:05:50 2010
New Revision: 156449

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=156449
Log:
2010-02-02  Tobias Burnus  <burnus@net-b.de>

        PR fortran/42650
        * parse.c (decode_specification_statement): Use sym->result not
        * sym.

2010-02-02  Tobias Burnus  <burnus@net-b.de>

        PR fortran/42650
        * gfortran.dg/func_result_5.f90: New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/func_result_5.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/parse.c
    trunk/gcc/testsuite/ChangeLog

Comment 5 Tobias Burnus 2010-02-02 14:27:40 UTC
Subject: Bug 42650

Author: burnus
Date: Tue Feb  2 14:27:24 2010
New Revision: 156450

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=156450
Log:
2010-02-02  Tobias Burnus  <burnus@net-b.de>

        PR fortran/42650
        * parse.c (decode_specification_statement): Use sym->result not
        * sym.

2010-02-02  Tobias Burnus  <burnus@net-b.de>

        PR fortran/42650
        * gfortran.dg/func_result_5.f90: New test.


Added:
    branches/gcc-4_4-branch/gcc/testsuite/gfortran.dg/func_result_5.f90
Modified:
    branches/gcc-4_4-branch/gcc/fortran/ChangeLog
    branches/gcc-4_4-branch/gcc/fortran/parse.c
    branches/gcc-4_4-branch/gcc/testsuite/ChangeLog

Comment 6 Tobias Burnus 2010-02-02 14:27:59 UTC
FIXED on the trunk (4.5) and 4.4 branch.