Bug 58026 - [F03] Bad error recovery for allocatable component of undeclared type
Summary: [F03] Bad error recovery for allocatable component of undeclared type
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.9.0
: P5 normal
Target Milestone: 4.9.0
Assignee: janus
URL:
Keywords: error-recovery
Depends on:
Blocks: Finalization
  Show dependency treegraph
 
Reported: 2013-07-30 06:21 UTC by Joost VandeVondele
Modified: 2014-01-12 11:12 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-07-30 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Joost VandeVondele 2013-07-30 06:21:27 UTC
Following invalid testcase yields and ICE with current trunk.

> cat small.f90
  type sysmtx_t
     type(ext_complex_t), allocatable :: S(:)       ! Block scales
  end type sysmtx_t
contains
  subroutine init (this, n, n_e, n_i, n_o)
    class(sysmtx_t), intent(out) :: this

> gfortran small.f90
small.f90:2.40:

     type(ext_complex_t), allocatable :: S(:)       ! Block scales
                                        1
Error: Derived type at (1) has not been previously defined and so cannot appear in a derived type definition
f951: internal compiler error: in generate_finalization_wrapper, at fortran/class.c:1521
0x54f091 generate_finalization_wrapper
	../../gcc/gcc/fortran/class.c:1520
0x54f091 gfc_find_derived_vtab(gfc_symbol*)
	../../gcc/gcc/fortran/class.c:2394
0x54fc82 gfc_build_class_symbol(gfc_typespec*, symbol_attribute*, gfc_array_spec**, bool)
Comment 1 Dominique d'Humieres 2013-07-30 08:26:55 UTC
The ICE has been introduced between revisions 198750 (2013-05-09) and 199418 (2013-05-29): r199409?
Comment 2 Tobias Burnus 2013-07-30 11:42:31 UTC
Failing is the following assert in generate_finalization_wrapper:

  /* If there is no new finalizer and no new allocatable, return with
     an expr to the ancestor's one.  */
  if (!expr_null_wrapper && !finalizable_comp
      && (!derived->f2k_derived || !derived->f2k_derived->finalizers))
    {
      gcc_assert (ancestor_wrapper && ancestor_wrapper->ref == NULL
                  && ancestor_wrapper->expr_type == EXPR_VARIABLE);
Comment 3 janus 2013-07-30 12:19:14 UTC
Slightly modified test case:


  type sysmtx_t
     type(ext_complex_t), allocatable :: S(:)
  end type
contains
  subroutine init (this)
    class(sysmtx_t) :: this 
  end subroutine
end
Comment 4 janus 2013-07-30 12:21:46 UTC
Draft patch:

Index: gcc/fortran/decl.c
===================================================================
--- gcc/fortran/decl.c	(revision 201331)
+++ gcc/fortran/decl.c	(working copy)
@@ -4286,12 +4286,10 @@ gfc_match_data_decl (void)
 	      || current_ts.u.derived->attr.zero_comp))
 	goto ok;
 
-      /* Now we have an error, which we signal, and then fix up
-	 because the knock-on is plain and simple confusing.  */
       gfc_error_now ("Derived type at %C has not been previously defined "
 		     "and so cannot appear in a derived type definition");
-      current_attr.pointer = 1;
-      goto ok;
+      m = MATCH_ERROR;
+      goto cleanup;
     }
 
 ok:
Comment 5 janus 2013-07-30 14:26:10 UTC
(In reply to janus from comment #4)
> Draft patch:

... seems to regtest cleanly.
Comment 6 janus 2013-11-25 20:48:15 UTC
For the record: The code that I'm proposing to remove in comment 4 has been added by Paul in r105913:

http://gcc.gnu.org/viewcvs/gcc?view=revision&revision=105913
Comment 7 Tobias Burnus 2013-11-25 20:57:36 UTC
(In reply to janus from comment #6)
> For the record: The code that I'm proposing to remove in comment 4 has been
> added by Paul in r105913:

For PR24158 (ice-on-invalid-code), which was on 2005-10-26.
Comment 8 janus 2014-01-09 10:49:03 UTC
At r206460, I don't see the ICE any more. Possibly is has been fixed by r206379 (for PR59589)? Can someone confirm that it's gone?


The output I now get for comment 3 (with 4.8 and trunk) is as follows:

$ gfortran-4.9 c3.f90 
c3.f90:3.40:

     type(ext_complex_t), allocatable :: S(:)
                                        1
Error: Derived type at (1) has not been previously defined and so cannot appear in a derived type definition
c3.f90:3.45:

     type(ext_complex_t), allocatable :: S(:)
                                             1
Error: The pointer component 's' of 'sysmtx_t' at (1) is a type that has not been declared
c3.f90:3.45:

     type(ext_complex_t), allocatable :: S(:)
                                             1
Error: The pointer component 's' of 'sysmtx_t' at (1) is a type that has not been declared
c3.f90:3.45:

     type(ext_complex_t), allocatable :: S(:)
                                             1
Error: The pointer component 's' of 'sysmtx_t' at (1) is a type that has not been declared


The first error is perfectly ok, but the following three (about a 'pointer component') are bogus. They are indeed removed by the patch in comment 4, so I think applying that patch still makes sense.
Comment 9 janus 2014-01-09 13:45:08 UTC
(In reply to Tobias Burnus from comment #7)
> > For the record: The code that I'm proposing to remove in comment 4 has been
> > added by Paul in r105913:
> 
> For PR24158 (ice-on-invalid-code), which was on 2005-10-26.

Btw: The corresponding test cases are

derived_recursion.f90
implicit_actual.f90

The patch does not change the diagnostics for these cases (in particular there is no 'confusing knock-on).
Comment 10 janus 2014-01-09 14:14:12 UTC
(In reply to janus from comment #8)
> At r206460, I don't see the ICE any more. Possibly is has been fixed by
> r206379 (for PR59589)? Can someone confirm that it's gone?

Reverting r206379 brings back the ICE, so indeed this revision has fixed it apparently.

So: The ICE regression is fixed and only the error-recovery problem of comment 8 persists.
Comment 11 janus 2014-01-09 14:27:57 UTC
Further reduced test case for the error recovery:

type sysmtx_t
   type(ext_complex_t), allocatable :: S(:)
end type
end


Trunk (and 4.4 - 4.8) yield:


c3.f90:3.40:

     type(ext_complex_t), allocatable :: S(:)
                                        1
Error: Derived type at (1) has not been previously defined and so cannot appear in a derived type definition
c3.f90:3.45:

     type(ext_complex_t), allocatable :: S(:)
                                             1
Error: The pointer component 's' of 'sysmtx_t' at (1) is a type that has not been declared



With the patch in comment 4 the second error, which is bogus, is removed.
Comment 12 janus 2014-01-12 11:09:05 UTC
Author: janus
Date: Sun Jan 12 11:08:31 2014
New Revision: 206564

URL: http://gcc.gnu.org/viewcvs?rev=206564&root=gcc&view=rev
Log:
2014-01-12  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/58026
	* decl.c (gfc_match_data_decl): Improve error recovery.


2014-01-12  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/58026
	* gfortran.dg/alloc_comp_basics_6.f90: New.

Added:
    trunk/gcc/testsuite/gfortran.dg/alloc_comp_basics_6.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/decl.c
    trunk/gcc/testsuite/ChangeLog
Comment 13 janus 2014-01-12 11:12:05 UTC
(In reply to janus from comment #10)
> So: The ICE regression is fixed and only the error-recovery problem of
> comment 8 persists.

... which is fixed on 4.9 trunk by r206564. Closing.