Bug 49050 - ICE with deferred character length derived type component
Summary: ICE with deferred character length derived type component
Status: RESOLVED DUPLICATE of bug 51976
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-18 17:57 UTC by kargl
Modified: 2012-01-24 08:04 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.6.1, 4.7.0
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description kargl 2011-05-18 17:57:07 UTC
The following code gives an ICE.  I haven't check it against
the standard yet to determine if this is valid or invalid 
code.  Nonetheless, it should not ICE.

module simple_module
   implicit none
   type :: item_type
     character(len=:), allocatable :: key
   end type item_type
end module simple_module

program test_simple
   use simple_module
   implicit none
   type(item_type) :: item
! ICE
   item = item_type('key')
!   item%key = 'key'
end program
Comment 1 kargl 2011-05-18 18:04:23 UTC
ev.f90: In function 'test_simple':
ev.f90:8:0: internal compiler error: in gfc_get_derived_type, at fortran/trans-types.c:2298
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.

(gdb) bt
#0  gfc_get_derived_type (derived=0x202097380)
    at ../../gcc4x/gcc/fortran/trans-types.c:2325
#1  0x00000000005451cc in gfc_get_module_backend_decl (sym=0x202097700)
    at ../../gcc4x/gcc/fortran/trans-decl.c:690
#2  0x00000000005881eb in gfc_get_derived_type (derived=0x202097700)
    at ../../gcc4x/gcc/fortran/trans-types.c:2216
#3  0x0000000000588752 in gfc_typenode_for_spec (spec=0x202097c60)
    at ../../gcc4x/gcc/fortran/trans-types.c:1049
#4  0x000000000058888b in gfc_sym_type (sym=0x202097c40)
    at ../../gcc4x/gcc/fortran/trans-types.c:1983
#5  0x00000000005498e5 in gfc_get_symbol_decl (sym=0x202097c40)
    at ../../gcc4x/gcc/fortran/trans-decl.c:1303
#6  0x000000000054a722 in generate_local_decl (sym=0x202097c40)
    at ../../gcc4x/gcc/fortran/trans-decl.c:4207
#7  0x00000000005155de in traverse_ns (st=0x2020073d0, 
    func=0x54a460 <generate_local_decl>)
    at ../../gcc4x/gcc/fortran/symbol.c:3333
#8  0x00000000005155cf in traverse_ns (st=0x202007310, 
    func=0x54a460 <generate_local_decl>)
    at ../../gcc4x/gcc/fortran/symbol.c:3330
#9  0x00000000005155cf in traverse_ns (st=0x202007340, 
    func=0x54a460 <generate_local_decl>)
    at ../../gcc4x/gcc/fortran/symbol.c:3330
#10 0x000000000054c834 in gfc_generate_function_code (ns=0x2021ab600)
    at ../../gcc4x/gcc/fortran/trans-decl.c:4900
#11 0x00000000004ed9da in gfc_parse_file ()
    at ../../gcc4x/gcc/fortran/parse.c:4271
#12 0x000000000052466e in gfc_be_parse_file ()
    at ../../gcc4x/gcc/fortran/f95-lang.c:250
#13 0x0000000000877ca2 in do_compile () at ../../gcc4x/gcc/toplev.c:570
#14 0x00000000008788c5 in toplev_main (argc=2, argv=0x7fffffffd508)

(gdb) list
2321            {
2322              if (c->ts.type == BT_CHARACTER)
2323                {
2324                  /* Evaluate the string length.  */
2325                  gfc_conv_const_charlen (c->ts.u.cl);
2326                  gcc_assert (c->ts.u.cl->backend_decl);
2327                }
2328
2329              field_type = gfc_typenode_for_spec (&c->ts);
2330            }

(gdb) print c->ts.u.cl->backend_decl
$6 = 0x0
(gdb) print *c->ts.u.cl
$8 = {length = 0x0, next = 0x0, length_from_typespec = 0 '\0', 
  backend_decl = 0x0, passed_length = 0x0, resolved = 1}
Comment 2 Tobias Burnus 2011-05-18 18:29:49 UTC
See also: PR 45170.

It is known that deferred character length components do not work - they have not been implemented. I think we really should add a gfc_error("Sorry not implemented") as it is not the first such bug has been reported.

 * * *

By the way, the documentation states this - albeit a bit hidden:

http://gcc.gnu.org/gcc-4.6/changes.html#fortran
http://gcc.gnu.org/wiki/GFortran#GCC4.6
 "Deferred type parameter: For scalar allocatable and pointer variables
  the character length can be deferred."
 (In particular: For components and for arrays, the length cannot be deferred.)

And a bit more explicitly:
  http://gcc.gnu.org/wiki/Fortran2003Status
  http://gcc.gnu.org/onlinedocs/gfortran/Fortran-2003-status.html
Comment 3 Tobias Burnus 2011-05-18 18:31:39 UTC
For a variant (original, longer version), see:
  http://gcc.gnu.org/ml/fortran/2011-05/msg00129.html

(That program compiles and runs w/o valgrind errors with ifort 11.1)
Comment 4 Tobias Burnus 2011-12-15 15:18:39 UTC
Author: burnus
Date: Thu Dec 15 15:18:33 2011
New Revision: 182372

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=182372
Log:
2011-12-15  Tobias Burnus  <burnus@net-b.de>

        PR fortran/51550
        PR fortran/47545
        PR fortran/49050
        PR fortran/51075
        * resolve.c (resolve_fl_derived0): Print not-implemented error
        for deferred-length character components.


Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/resolve.c
Comment 5 Tobias Burnus 2011-12-15 15:25:39 UTC
Author: burnus
Date: Thu Dec 15 15:25:32 2011
New Revision: 182373

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=182373
Log:
2011-12-15  Tobias Burnus  <burnus@net-b.de>

        PR fortran/51550
        PR fortran/47545
        PR fortran/49050
        PR fortran/51075
        * resolve.c (resolve_fl_derived0): Print not-implemented error
        for deferred-length character components.


Modified:
    branches/gcc-4_6-branch/gcc/fortran/ChangeLog
    branches/gcc-4_6-branch/gcc/fortran/resolve.c
Comment 6 Tobias Burnus 2012-01-24 08:04:35 UTC
The ICE is fixed - but deferred-length character components are not supported: Instead of an internal compiler error, one now gets a "not yet implemented" error.

Its implementation of is now tracked at PR 51976.

*** This bug has been marked as a duplicate of bug 51976 ***