[Bug fortran/51995] [OOP] Polymorphic class fails at runtime
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51995 janus at gcc dot gnu.org changed: What|Removed |Added CC||janus at gcc dot gnu.org Target Milestone|--- |4.7.0
[Bug fortran/51995] [OOP] Polymorphic class fails at runtime
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51995 --- Comment #14 from Tobias Burnus 2012-01-25 22:21:19 UTC --- Author: burnus Date: Wed Jan 25 22:21:14 2012 New Revision: 183541 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=183541 Log: 2012-01-25 Tobias Burnus PR fortran/51995 * class.c (gfc_build_class_symbol): Fix invalid freeing issue with fclass->f2k_derived. Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/class.c
[Bug fortran/51995] [OOP] Polymorphic class fails at runtime
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51995 --- Comment #13 from Dominique d'Humieres 2012-01-25 20:23:02 UTC --- Reduced test case exhibiting the ICE: MODULE factory_pattern TYPE CFactory PRIVATE CHARACTER(len=20) :: factory_type !! Descriptive name for database CLASS(Connection), POINTER :: connection_type !! Which type of database ? CONTAINS!! Note 'class' not 'type' ! PROCEDURE :: create_connection!! Connect to database END TYPE CFactory TYPE, ABSTRACT :: Connection CONTAINS PROCEDURE(generic_desc), DEFERRED, PASS(self) :: description END TYPE Connection ABSTRACT INTERFACE SUBROUTINE generic_desc(self) IMPORT :: Connection CLASS(Connection), INTENT(in) :: self END SUBROUTINE generic_desc END INTERFACE !! An Oracle connection TYPE, EXTENDS(Connection) :: OracleConnection CONTAINS PROCEDURE, PASS(self) :: description => oracle_desc END TYPE OracleConnection CONTAINS FUNCTION create_connection(self) RESULT(ptr) CLASS(CFactory) :: self CLASS(Connection), POINTER :: ptr END FUNCTION create_connection SUBROUTINE oracle_desc(self) CLASS(OracleConnection), INTENT(in) :: self END SUBROUTINE oracle_desc END MODULE factory_pattern
[Bug fortran/51995] [OOP] Polymorphic class fails at runtime
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51995 --- Comment #12 from Dominique d'Humieres 2012-01-25 19:06:40 UTC --- On x86_64-apple-darwin10 and an almost clean tree (i.e., with only the patch for pr 51985) at revision 183528, compiling testsuite/gfortran.dg/typebound_proc_25.f90 gives an ICE: [macbook] f90/bug% gfcp /opt/gcc/work/gcc/testsuite/gfortran.dg/typebound_proc_25.f90 /opt/gcc/work/gcc/testsuite/gfortran.dg/typebound_proc_25.f90:88:0: internal compiler error: in gfc_release_symbol, at fortran/symbol.c:2531 instead of the errors (the same happens on my main patched tree).
[Bug fortran/51995] [OOP] Polymorphic class fails at runtime
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51995 Tobias Burnus changed: What|Removed |Added Status|ASSIGNED|RESOLVED Resolution||FIXED --- Comment #11 from Tobias Burnus 2012-01-25 17:41:44 UTC --- FIXED on the trunk (4.7). Thanks for the bug report! See comment 8 for how to obtain a newer version.
[Bug fortran/51995] [OOP] Polymorphic class fails at runtime
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51995 --- Comment #10 from Tobias Burnus 2012-01-25 17:34:48 UTC --- Author: burnus Date: Wed Jan 25 17:34:39 2012 New Revision: 183528 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=183528 Log: 2012-01-25 Tobias Burnus PR fortran/51995 * class.c (gfc_build_class_symbol): Ensure that fclass->f2k_derived is set. 2012-01-25 Tobias Burnus PR fortran/51995 * gfortran.dg/typebound_proc_25.f90: New. Added: trunk/gcc/testsuite/gfortran.dg/typebound_proc_25.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/class.c trunk/gcc/testsuite/ChangeLog
[Bug fortran/51995] [OOP] Polymorphic class fails at runtime
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51995 --- Comment #9 from Prince 2012-01-25 13:32:50 UTC --- Using five days old gcc version 4.7.0 20120120 (experimental) (GCC), the problem still persists. I think the problem has not been fixed for the i686 architecture. Do you know of any work-around for this? Ifort 12.1 runs the program successfully without memory leak. From: burnus at gcc dot gnu.org To: jilf...@yahoo.com Sent: Wednesday, January 25, 2012 2:47 PM Subject: [Bug fortran/51995] [OOP] Polymorphic class fails at runtime http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51995 --- Comment #7 from Tobias Burnus 2012-01-25 12:47:49 UTC --- The problem seems to be the following: One properly calls match_typebound_call, which sets "base" (alias "primary") to the symtree of "db_connect" (which is of type BT_CLASS). Then it calls: gfc_match_varspec (primary=0x16cf3d0, equiv_flag=0, sub_flag=true, ppc_arg=true) There, the problem is that one has: sym = sym->ts.u.derived; if (sym->f2k_derived) But "sym" is only the class container. One needs sym->components->ts.u.derived->f2k_derived. One could simply do: --- a/gcc/fortran/primary.c +++ b/gcc/fortran/primary.c @@ -1911 +1911,2 @@ gfc_match_varspec (gfc_expr *primary, int equiv_flag, - sym = sym->ts.u.derived; + sym = (sym->ts.type == BT_CLASS) ? CLASS_DATA (sym)->ts.u.derived + : sym->ts.u.derived; But that will fail later with internal compiler error: in gfc_conv_component_ref, at fortran/trans-expr.c:1100
[Bug fortran/51995] [OOP] Polymorphic class fails at runtime
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51995 Tobias Burnus changed: What|Removed |Added Status|NEW |ASSIGNED AssignedTo|unassigned at gcc dot |burnus at gcc dot gnu.org |gnu.org | --- Comment #8 from Tobias Burnus 2012-01-25 13:29:48 UTC --- (In reply to comment #4) > I tested the program on i686 GNU/Linux running on Ubuntu-Maverick using gcc > version 4.7.0 20120118 (experimental) (GCC). > > So it is definitely a bug in gfortran. Do you have any work-around? Unfortunately, I am not aware of a workaround. I have to admit that I have not fully understood why fclass->f2k_derived gets often but not always set. However, the following patch works. Thus, you could either apply it and build your own GCC, or you wait a day after the committal and get a nightly build at http://gcc.gnu.org/wiki/GFortranBinaries - or you convince Matthias to do a new Ubuntu build. (In reply to comment #7) > There, the problem is that one has: > sym = sym->ts.u.derived; > if (sym->f2k_derived) Actually, f2k_derived should also get set for the class container. Better patch (read: actually working) patch: --- a/gcc/fortran/class.c +++ b/gcc/fortran/class.c @@ -421,6 +421,8 @@ gfc_build_class_symbol (gfc_typespec *ts, symbol_attribute *attr, c->attr.access = ACCESS_PRIVATE; c->attr.pointer = 1; } + else if (!fclass->f2k_derived) +fclass->f2k_derived = fclass->components->ts.u.derived->f2k_derived; /* Since the extension field is 8 bit wide, we can only have up to 255 extension levels. */
[Bug fortran/51995] [OOP] Polymorphic class fails at runtime
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51995 --- Comment #7 from Tobias Burnus 2012-01-25 12:47:49 UTC --- The problem seems to be the following: One properly calls match_typebound_call, which sets "base" (alias "primary") to the symtree of "db_connect" (which is of type BT_CLASS). Then it calls: gfc_match_varspec (primary=0x16cf3d0, equiv_flag=0, sub_flag=true, ppc_arg=true) There, the problem is that one has: sym = sym->ts.u.derived; if (sym->f2k_derived) But "sym" is only the class container. One needs sym->components->ts.u.derived->f2k_derived. One could simply do: --- a/gcc/fortran/primary.c +++ b/gcc/fortran/primary.c @@ -1911 +1911,2 @@ gfc_match_varspec (gfc_expr *primary, int equiv_flag, - sym = sym->ts.u.derived; + sym = (sym->ts.type == BT_CLASS) ? CLASS_DATA (sym)->ts.u.derived + : sym->ts.u.derived; But that will fail later with internal compiler error: in gfc_conv_component_ref, at fortran/trans-expr.c:1100
[Bug fortran/51995] [OOP] Polymorphic class fails at runtime
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51995 --- Comment #6 from Prince 2012-01-25 11:20:58 UTC --- Thanks for the prompt reply. I tested the program on i686 GNU/Linux running on Ubuntu-Maverick using gcc version 4.7.0 20120118 (experimental) (GCC). From: burnus at gcc dot gnu.org To: jilf...@yahoo.com Sent: Wednesday, January 25, 2012 1:05 PM Subject: [Bug fortran/51995] Polymorphic class fails at runtime http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51995 --- Comment #2 from Tobias Burnus 2012-01-25 11:05:41 UTC --- Using today's GCC 4.7 and using one one-week-old one, it compiles without any error. It seems as if the bug has been already fixed - or it only affects certain architectures. Can you provide more details about the used GCC version ("gfortran -v")? You should also try a newer version and check whether the issue still occurs.
[Bug fortran/51995] [OOP] Polymorphic class fails at runtime
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51995 Tobias Burnus changed: What|Removed |Added Keywords||rejects-valid Status|UNCONFIRMED |NEW Last reconfirmed||2012-01-25 Summary|Polymorphic class fails at |[OOP] Polymorphic class |runtime |fails at runtime Ever Confirmed|0 |1 --- Comment #5 from Tobias Burnus 2012-01-25 11:17:38 UTC --- Ignore that. I missed that one needs *both* the attachment and the program. Thus, I can actually reproduce it. Sorry for the pilot error. Thus, I am able to reproduce it both with 4.5, 4.6 and 4.7. (The program compiles with ifort 12.1 - and at a glance, I cannot spot anything which looks invalid.)