Summary: | [F03] ICE with allocatable length character in interface block | ||
---|---|---|---|
Product: | gcc | Reporter: | shadowblade |
Component: | fortran | Assignee: | Not yet assigned to anyone <unassigned> |
Status: | RESOLVED FIXED | ||
Severity: | normal | CC: | burnus, dtemirbulatov, janus |
Priority: | P3 | Keywords: | ice-on-valid-code |
Version: | 4.7.0 | ||
Target Milestone: | --- | ||
Host: | Target: | ||
Build: | Known to work: | ||
Known to fail: | Last reconfirmed: | 2011-06-21 20:21:29 | |
Bug Depends on: | |||
Bug Blocks: | 45170 |
Description
shadowblade
2011-06-15 23:14:13 UTC
I get: test.f90:19:0: internal compiler error: tree check: expected tree that contains 'typed' structure, have '�' in fold_convert_loc, at fold-const.c:1859 ==14082== Invalid read of size 1 ==14082== at 0x72F9B2: fold_convert_loc (fold-const.c:1859) ==14082== by 0xA7D3F6: build_range_type_1 (tree.c:7170) ==14082== by 0x5C8C69: gfc_get_character_type_len_for_eltype (trans-types.c:977) ==14082== by 0x59EA63: gfc_conv_procedure_call (trans-expr.c:3538) ==14082== by 0x59F271: gfc_conv_function_expr (trans-expr.c:4082) ==14082== by 0x597D01: gfc_trans_assignment_1 (trans-expr.c:6112) In trans-expr.c:3538: (gdb) p *ts.u.cl $2 = {length = 0x0, next = 0x0, length_from_typespec = 215 '\327', backend_decl = 0x1535340, passed_length = 0x2aaaacdd7f00, resolved = 6764539} I wonder whether the 3538 type = gfc_get_character_type (ts.kind, ts.u.cl); should be rather: type = gfc_get_character_type (ts.kind, ts->deferred ? NULL_TREE : ts.u.cl); The same error occurs for the test case in PR 49112 comment 7: module datetime_mod implicit none private type :: DateTime contains procedure :: getFormattedString end type contains function getTimeString(dt, FMT) result(string) character(:), allocatable :: string class(DateTime), intent(IN) :: dt integer, optional, intent(IN) :: FMT string = dt%getFormattedString(2, FMT) end function function getFormattedString(this, FILTER, FMT) & result(string) character(:), allocatable :: string class(DateTime), intent(IN) :: this integer, optional, intent(IN) :: FILTER, FMT end function end module c7.f90: In function ‘gettimestring’: c7.f90:18:0: internal compiler error: tree check: expected tree that contains ‘typed’ structure, have ‘’ in fold_convert_loc, at fold-const.c:1859 (In reply to comment #1) > I wonder whether the > 3538 type = gfc_get_character_type (ts.kind, ts.u.cl); > should be rather: > type = gfc_get_character_type (ts.kind, ts->deferred ? NULL_TREE : ts.u.cl); Well, with this: Index: gcc/fortran/trans-expr.c =================================================================== --- gcc/fortran/trans-expr.c (revision 175256) +++ gcc/fortran/trans-expr.c (working copy) @@ -3535,7 +3535,8 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * else if (ts.type == BT_CHARACTER) { /* Pass the string length. */ - type = gfc_get_character_type (ts.kind, ts.u.cl); + type = gfc_get_character_type (ts.kind, + ts.deferred ? NULL_TREE : ts.u.cl); type = build_pointer_type (type); /* Return an address to a char[0:len-1]* temporary for I run into another segfault: #0 0x0000000000575a6d in gfc_evaluate_now_loc (loc=2308, expr=0x0, pblock=0x7fffffffd560) at /home/jweil/gcc47/trunk/gcc/fortran/trans.c:126 #1 0x0000000000575b40 in gfc_evaluate_now (expr=0x0, pblock=0x7fffffffd560) at /home/jweil/gcc47/trunk/gcc/fortran/trans.c:139 #2 0x00000000005ca23b in gfc_trans_assignment_1 (expr1=0x1af3df0, expr2=0x1af3eb0, init_flag=0 '\000', dealloc=1 '\001') at /home/jweil/gcc47/trunk/gcc/fortran/trans-expr.c:6117 Slightly reduced/modified test case, giving a different error: abstract interface function messageProcedure() character(:), allocatable :: messageProcedure end function end interface type :: ctype procedure(messageProcedure), pointer, nopass :: getMessage end type type(ctype) :: this character :: message message = this%getMessage() end internal compiler error: vector VEC(tree,base) index domain error, in gfc_conv_procedure_call at fortran/trans-expr.c:3387 Comment #4 can be fixed with the following patch: Index: gcc/fortran/trans-expr.c =================================================================== --- gcc/fortran/trans-expr.c (revision 175256) +++ gcc/fortran/trans-expr.c (working copy) @@ -3381,7 +3381,7 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * we take the character length of the first argument for the result. For dummies, we have to look through the formal argument list for this function and use the character length found there.*/ - if (ts.deferred && (sym->attr.allocatable || sym->attr.pointer)) + if (ts.deferred) cl.backend_decl = gfc_create_var (gfc_charlen_type_node, "slen"); else if (!sym->attr.dummy) cl.backend_decl = VEC_index (tree, stringargs, 0); @@ -6112,7 +6112,7 @@ gfc_trans_assignment_1 (gfc_expr * expr1, gfc_expr gfc_conv_expr (&rse, expr2); /* Stabilize a string length for temporaries. */ - if (expr2->ts.type == BT_CHARACTER) + if (expr2->ts.type == BT_CHARACTER && !expr2->ts.deferred) string_length = gfc_evaluate_now (rse.string_length, &rse.pre); else string_length = NULL_TREE; The combined patches of comment #3 and #5 regtest cleanly, but do not fully fix the original test case, cf. comment #3. Author: burnus Date: Sun May 13 10:52:32 2012 New Revision: 187436 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=187436 Log: 2012-05-13 Alessandro Fanfarillo <fanfarillo.gcc@gmail.com> Tobias Burnus <burnus@net-b.de> PR fortran/52158 PR fortran/45170 PR fortran/49430 * resolve.c (resolve_fl_derived0): Deferred character length procedure components are supported. * trans-expr.c (gfc_conv_procedure_call): Handle TBP with deferred-length results. (gfc_string_to_single_character): Add a new check to prevent NULL read. (gfc_conv_procedure_call): Remove unuseful checks on symbol's attributes. Add new checks to prevent NULL read on string length. 2012-05-13 Alessandro Fanfarillo <fanfarillo.gcc@gmail.com> PR fortran/45170 * gfortran.dg/deferred_type_param_3.f90: New. * gfortran.dg/deferred_type_proc_pointer_1.f90: New. * gfortran.dg/deferred_type_proc_pointer_2.f90: New. Added: trunk/gcc/testsuite/gfortran.dg/deferred_type_param_3.f90 trunk/gcc/testsuite/gfortran.dg/deferred_type_proc_pointer_1.f90 trunk/gcc/testsuite/gfortran.dg/deferred_type_proc_pointer_2.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/resolve.c trunk/gcc/fortran/trans-expr.c trunk/gcc/testsuite/ChangeLog FIXED on the trunk (GCC 4.8). Thanks for the bug report and sorry for taking nearly one year to get it fixed. (gdb) call debug_rtx(insn) (insn:TI 454 460 607 (set (reg:SI 2 r2 [orig:433 buf+2 ] [433]) (zero_extend:SI (mem/u/c/i:QI (symbol_ref/u:SI ("*.LC0") [flags 0x2]) [0 S1 A8]))) cr_parse-reduced.ii:111 168 {*arm_zero_extendqisi2_v6} (nil)) oh, sorry please ignore my comment |