Bug 41587 - [OOP] ICE with ALLOCATABLE CLASS components
Summary: [OOP] ICE with ALLOCATABLE CLASS components
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2009-10-05 13:31 UTC by Tobias Burnus
Modified: 2012-05-06 20:32 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-02-02 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2009-10-05 13:31:06 UTC
type t0
  integer :: j = 42
end type t0
type t
  integer :: i
  class(t0), allocatable :: foo(3)
end type t

Is invalid. the "foo(3)" shall be "foo(:)" as "foo" is allocatable.
Comment 1 Dominique d'Humieres 2009-10-14 08:42:46 UTC
I don't get an ICE with the coed in comment#0. However I get one with the following (valid?) changes:

type t0
  integer :: j = 42
end type t0
type t
  integer :: i
  class(t0), allocatable :: foo(:)
end type t
type(t) :: k
allocate(t0 :: k%foo(3))
print *, k%foo%j
end

pr41587_db.f90: In function 'MAIN__':
pr41587_db.f90:9:0: internal compiler error: in gfc_conv_descriptor_data_get, at fortran/trans-array.c:147

Note that with the patch in http://gcc.gnu.org/ml/fortran/2009-10/msg00136.html , I get the following error for the code in comment#0:

pr41587.f90:6.34:

  class(t0), allocatable :: foo(3)
                                  1
Error: Allocatable component of structure at (1) must have a deferred shape
Comment 2 Paul Thomas 2009-10-17 18:09:43 UTC
Subject: Bug 41587

Author: pault
Date: Sat Oct 17 18:09:25 2009
New Revision: 152955

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=152955
Log:
2009-10-17  Janus Weil  <janus@gcc.gnu.org>
	    Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/41608
	* decl.c (gfc_match_data_decl): Add BT_CLASS for undefined type
	and empty type errors.
	* parse.c (gfc_build_block_ns): Only set recursive if parent ns
	has a proc_name.

	PR fortran/41629
	PR fortran/41618
	PR fortran/41587
	* gfortran.h : Add class_ok bitfield to symbol_attr.
	* decl.c (build_sym): Set attr.class_ok if dummy, pointer or
	allocatable.
	(build_struct): Use gfc_try 't' to carry errors past the call
	to encapsulate_class_symbol.
	(attr_decl1): For a CLASS object, apply the new attribute to
	the data component.
	* match.c (gfc_match_select_type): Set attr.class_ok for an
	assigned selector.
	* resolve.c (resolve_fl_variable_derived): Check a CLASS object
	is dummy, pointer or allocatable by testing the class_ok and
	the use_assoc attribute.

2009-10-17  Janus Weil  <janus@gcc.gnu.org>
	    Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/41629
	* gfortran.dg/class_6.f90: New test.

	PR fortran/41608
	PR fortran/41587
	* gfortran.dg/class_7.f90: New test.

	PR fortran/41618
	* gfortran.dg/class_8.f90: New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/class_6.f03
    trunk/gcc/testsuite/gfortran.dg/class_7.f03
    trunk/gcc/testsuite/gfortran.dg/class_8.f03
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/decl.c
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/match.c
    trunk/gcc/fortran/parse.c
    trunk/gcc/fortran/resolve.c
    trunk/gcc/testsuite/ChangeLog

Comment 3 Paul Thomas 2009-10-18 12:25:06 UTC
Fixed on trunk.

Thanks for the report!

Paul
Comment 4 Mikael Morin 2012-02-02 23:11:01 UTC
Author: mikael
Date: Thu Feb  2 23:10:55 2012
New Revision: 183853

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=183853
Log:
2012-02-02  Mikael Morin  <mikael@gcc.gnu.org>

	PR fortran/41587
	PR fortran/46356
	PR fortran/51754
	PR fortran/50981
	* class.c (insert_component_ref, class_data_ref_missing,
	gfc_fix_class_refs): New functions.
	* gfortran.h (gfc_fix_class_refs): New prototype.
	* trans-expr.c (gfc_conv_expr): Remove special case handling and call
	gfc_fix_class_refs instead.

2012-02-02  Mikael Morin  <mikael@gcc.gnu.org>

	PR fortran/41587
	* gfortran.dg/class_array_10.f03: New test.

	PR fortran/46356
	* gfortran.dg/class_array_11.f03: New test.

	PR fortran/51754
	* gfortran.dg/class_array_12.f03: New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/class_array_10.f03
    trunk/gcc/testsuite/gfortran.dg/class_array_11.f03
    trunk/gcc/testsuite/gfortran.dg/class_array_12.f03
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/class.c
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/trans-expr.c
    trunk/gcc/testsuite/ChangeLog
Comment 5 Mikael Morin 2012-02-02 23:37:09 UTC
(In reply to comment #1)
> I don't get an ICE with the coed in comment#0. However I get one with the
> following (valid?) changes:
> 
> type t0
>   integer :: j = 42
> end type t0
> type t
>   integer :: i
>   class(t0), allocatable :: foo(:)
> end type t
> type(t) :: k
> allocate(t0 :: k%foo(3))
> print *, k%foo%j
> end
> 
> pr41587_db.f90: In function 'MAIN__':
> pr41587_db.f90:9:0: internal compiler error: in gfc_conv_descriptor_data_get,
> at fortran/trans-array.c:147
> 
The ICE is gone, but the program above prints 0 0 42 instead of 42 42 42.
Reopening...
Comment 6 Tobias Burnus 2012-02-03 07:34:27 UTC
(In reply to comment #5)
> The ICE is gone, but the program above prints 0 0 42 instead of 42 42 42.
> Reopening...

For completeness: comment 0 is also not fixed. The program is accepted although it is invalid. The following error message is missing: "Allocatable component of structure at (1) must have a deferred shape"
Comment 7 Paul Thomas 2012-02-06 14:20:22 UTC
As of yesterday, the testcase in comment #1 compiles and runs successfully.  We now just need the error message for the original problem.

Cheers

Paul
Comment 8 Tobias Burnus 2012-04-23 12:59:24 UTC
(In reply to comment #7)
> As of yesterday, the testcase in comment #1 compiles and runs
> successfully.  We now just need the error message for the original problem.


Untested patch:

--- a/gcc/fortran/decl.c
+++ b/gcc/fortran/decl.c
@@ -1626,5 +1626,8 @@ build_struct (const char *name, gfc_charlen *cl, gfc_expr

-  if (c->attr.pointer)
+  if (c->attr.pointer
+          || (c->ts.type == BT_CLASS && CLASS_DATA (c)
+              && CLASS_DATA (c)->attr.class_pointer))
     {
-      if (c->as->type != AS_DEFERRED)
+      if ((c->ts.type == BT_CLASS && CLASS_DATA (c)->as->type != AS_DEFERRED)
+         || (c->ts.type != BT_CLASS &&  c->as->type != AS_DEFERRED))
        {
@@ -1635,5 +1638,8 @@ build_struct (const char *name, gfc_charlen *cl, gfc_expr 
     }
-  else if (c->attr.allocatable)
+  else if (c->attr.allocatable
+          || (c->ts.type == BT_CLASS && CLASS_DATA (c)
+              && CLASS_DATA (c)->attr.allocatable))
     {
-      if (c->as->type != AS_DEFERRED)
+      if ((c->ts.type == BT_CLASS && CLASS_DATA (c)->as->type != AS_DEFERRED)
+         || (c->ts.type != BT_CLASS &&  c->as->type != AS_DEFERRED))
        {
Comment 9 Tobias Burnus 2012-05-06 20:30:13 UTC
Author: burnus
Date: Sun May  6 20:30:05 2012
New Revision: 187214

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=187214
Log:
2012-05-06  Tobias Burnus  <burnus@net-b.de>

        PR fortran/41587
        * decl.c (build_struct): Don't ignore FAILED status.

2012-05-06  Tobias Burnus  <burnus@net-b.de>

        PR fortran/41587
        * gfortran.dg/class_array_13.f90: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/class_array_13.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/decl.c
    trunk/gcc/testsuite/ChangeLog
Comment 10 Tobias Burnus 2012-05-06 20:32:55 UTC
(In reply to comment #7)
> As of yesterday, the testcase in comment #1 compiles and runs successfully.  We
> now just need the error message for the original problem.

Which has now been FIXED on the 4.8 trunk. (The other issues were fixed on the 4.7 trunk.)