Bug 50625 - [4.6/4.7 Regression][OOP] ALLOCATABLE attribute lost for module CLASS variables
Summary: [4.6/4.7 Regression][OOP] ALLOCATABLE attribute lost for module CLASS variables
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: 4.6.2
Assignee: janus
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2011-10-05 19:47 UTC by Tobias Burnus
Modified: 2011-10-07 21:07 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-10-05 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2011-10-05 19:47:31 UTC
The following program compiles with GCC 4.5 and ifort, but fails with GCC 4.6 and GCC 4.7 with:

if(allocated(x)) stop
             1
Error: 'array' argument of 'allocated' intrinsic at (1) must be ALLOCATABLE



module m
type t
end type t
class(t), allocatable :: x
end module m

use m
implicit none
if(allocated(x)) stop
end
Comment 1 janus 2011-10-05 20:18:58 UTC
I think the problem is that the 'class_ok' attribute is not set when loading the symbol from the module.
Comment 2 janus 2011-10-05 21:42:33 UTC
Here's an attempt to fix it:


Index: module.c
===================================================================
--- module.c    (revision 179566)
+++ module.c    (working copy)
@@ -3608,6 +3608,8 @@ mio_symbol (gfc_symbol *sym)
 
   mio_symbol_attribute (&sym->attr);
   mio_typespec (&sym->ts);
+  if (sym->ts.type == BT_CLASS)
+    sym->attr.class_ok = 1;
 
   if (iomode == IO_OUTPUT)
     mio_namespace_ref (&sym->formal_ns);


A similar thing is already being done for components (cf. 'mio_component'). However, with this patch, the test case gives me a different error:

internal compiler error: in gfc_conv_component_ref, at fortran/trans-expr.c:529
Comment 3 janus 2011-10-06 21:27:50 UTC
(In reply to comment #2)
> However, with this patch, the test case gives me a different error:
> 
> internal compiler error: in gfc_conv_component_ref, at fortran/trans-expr.c:529

... which is:

  gcc_assert (c->backend_decl);

I have no idea why the backend_decl is missing, though.

Otherwise the patch regtests cleanly.
Comment 4 janus 2011-10-06 22:19:43 UTC
(In reply to comment #2)
> However, with this patch, the test case gives me a different error:
> 
> internal compiler error: in gfc_conv_component_ref, at fortran/trans-expr.c:529

This can be fixed with an additional patchlet:


Index: gcc/fortran/trans-decl.c
===================================================================
--- gcc/fortran/trans-decl.c	(revision 179592)
+++ gcc/fortran/trans-decl.c	(working copy)
@@ -1179,7 +1179,10 @@ gfc_get_symbol_decl (gfc_symbol * sym)
     {
       gfc_component *c = CLASS_DATA (sym);
       if (!c->ts.u.derived->backend_decl)
-	gfc_find_derived_vtab (c->ts.u.derived);
+	{
+	  gfc_find_derived_vtab (c->ts.u.derived);
+	  gfc_get_derived_type (sym->ts.u.derived);
+	}
     }
 
   /* All deferred character length procedures need to retain the backend
Comment 5 janus 2011-10-07 14:40:21 UTC
Author: janus
Date: Fri Oct  7 14:40:14 2011
New Revision: 179660

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=179660
Log:
2011-10-07  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/50625
	* class.c (gfc_build_class_symbol): Fix whitespace.
	* module.c (mio_symbol): Set 'class_ok' attribute.
	* trans-decl.c (gfc_get_symbol_decl): Make sure the backend_decl has
	been built for class symbols.


2011-10-07  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/50625
	* gfortran.dg/class_46.f03: New.

Added:
    trunk/gcc/testsuite/gfortran.dg/class_46.f03
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/class.c
    trunk/gcc/fortran/module.c
    trunk/gcc/fortran/trans-decl.c
    trunk/gcc/testsuite/ChangeLog
Comment 6 janus 2011-10-07 14:42:15 UTC
Fixed on trunk with r179660.
Comment 7 janus 2011-10-07 21:01:06 UTC
Author: janus
Date: Fri Oct  7 21:01:02 2011
New Revision: 179696

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=179696
Log:
2011-10-07  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/50585
	* interface.c (get_expr_storage_size): Check if 'length' component is
	associated.

	PR fortran/50625
	* class.c (gfc_build_class_symbol): Fix whitespace.
	* module.c (mio_symbol): Set 'class_ok' attribute.
	* trans-decl.c (gfc_get_symbol_decl): Make sure the backend_decl has
	been built for class symbols.


2011-10-07  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/50585
	* gfortran.dg/assumed_charlen_arg_2.f90: New.

	PR fortran/50625
	* gfortran.dg/class_46.f03: New.

Added:
    branches/gcc-4_6-branch/gcc/testsuite/gfortran.dg/assumed_charlen_arg_2.f90
    branches/gcc-4_6-branch/gcc/testsuite/gfortran.dg/class_46.f03
Modified:
    branches/gcc-4_6-branch/gcc/fortran/ChangeLog
    branches/gcc-4_6-branch/gcc/fortran/class.c
    branches/gcc-4_6-branch/gcc/fortran/interface.c
    branches/gcc-4_6-branch/gcc/fortran/module.c
    branches/gcc-4_6-branch/gcc/fortran/trans-decl.c
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
Comment 8 janus 2011-10-07 21:07:33 UTC
Fixed on trunk and 4.6. Closing.