Bug 15326 - [4.0 only] ICE with assumed length character strings
Summary: [4.0 only] ICE with assumed length character strings
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: tree-ssa
: P2 normal
Target Milestone: 4.1.0
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
: 15958 16236 16941 19927 23654 25012 (view as bug list)
Depends on:
Blocks: 19276 15809 18883 19242 19292 22518
  Show dependency treegraph
 
Reported: 2004-05-06 16:48 UTC by Tobias Schlüter
Modified: 2005-11-24 06:06 UTC (History)
10 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.1.0
Known to fail: 4.0.2
Last reconfirmed: 2005-08-31 20:42:48


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Schlüter 2004-05-06 16:48:15 UTC
[tobi@marktplatz tests]$ cat reduced.f90
  program Decapitation
    implicit none
    integer, parameter :: STRING_LENGTH = 80
    character (len = STRING_LENGTH) :: Text_1, Text_2
    Text_2 = Decap (Text_1)
    stop
  contains
    function Decap (String) result (New_String)
      character (len = *), intent(in) :: String
      character (len = Len(String)) :: New_String
      return
    end function Decap
  end program Decapitation
[tobi@marktplatz tests]$ gfortran reduced.f90
f951: ../../gcc/gcc/fortran/trans-expr.c:1000: gfc_conv_function_call: Assertion
`sym->ts.cl && sym->ts.cl->length && sym->ts.cl->length->expr_type ==
EXPR_CONSTANT' failed.
reduced.f90: In function `MAIN__':
reduced.f90:5: internal compiler error: Aborted
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
[tobi@marktplatz tests]$
Comment 1 Tobias Schlüter 2004-05-06 17:08:40 UTC
This is different from PR15324 in that the function call is affected, not only
the function itself.
Comment 2 Andrew Pinski 2004-05-06 18:02:29 UTC
Confirmed.
Comment 3 Andrew Pinski 2004-06-13 09:25:02 UTC
*** Bug 15958 has been marked as a duplicate of this bug. ***
Comment 4 Andrew Pinski 2004-06-27 20:29:30 UTC
*** Bug 16236 has been marked as a duplicate of this bug. ***
Comment 5 Andrew Pinski 2004-08-09 15:56:08 UTC
*** Bug 16941 has been marked as a duplicate of this bug. ***
Comment 6 Tobias Schlüter 2004-09-25 15:04:09 UTC
Patch here: http://gcc.gnu.org/ml/fortran/2004-09/msg00253.html
Comment 7 Tobias Schlüter 2004-10-10 21:04:04 UTC
The patch is wrong because it does only solve part of the problem.

With the testcase from the mailing list posting referred to above, we get code
like this:
  {
    logical4 D.464;
    char[1 .. .d] * pstr.0;

    pstr.0 = (char[1 .. .d] *) _gfortran_internal_malloc (.d);
    d (pstr.0, .d, &t1, 10);
where .d is used uninitialized.

If the function D from the testcase is declared external, with no interface, we
hit the same assertion as without the patch.
Comment 8 Tobias Schlüter 2004-10-10 21:08:07 UTC
Subject: Re:  ICE with assumed length character strings

tobi at gcc dot gnu dot org wrote:
> If the function D from the testcase is declared external, with no interface, we
> hit the same assertion as without the patch.
> 
Ugh, messed up when editing. This is meant to read:
"If the function D from the testcase is external, not contained, we hit the
same assertion as without the patch."

Comment 9 Andrew Pinski 2005-02-12 16:56:49 UTC
*** Bug 19927 has been marked as a duplicate of this bug. ***
Comment 10 Andrew Pinski 2005-08-31 15:15:22 UTC
*** Bug 23654 has been marked as a duplicate of this bug. ***
Comment 11 rsandifo@gcc.gnu.org 2005-08-31 20:42:47 UTC
Working on a patch.
Comment 12 CVS Commits 2005-09-08 18:46:26 UTC
Subject: Bug 15326

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	rsandifo@gcc.gnu.org	2005-09-08 18:46:06

Modified files:
	gcc/fortran    : ChangeLog trans-array.c trans-expr.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gfortran.dg: char_result_1.f90 char_result_2.f90 
	                           char_result_3.f90 char_result_4.f90 
	                           char_result_5.f90 char_result_6.f90 
	                           char_result_7.f90 char_result_8.f90 

Log message:
	PR fortran/15326
	* trans-array.c (gfc_add_loop_ss_code): Set ss->string_length in
	the GFC_SS_FUNCTION case too.
	* trans-expr.c (gfc_conv_function_val): Allow symbols to be bound
	to function pointers as well as function decls.
	(gfc_interface_sym_mapping, gfc_interface_mapping): New structures.
	(gfc_init_interface_mapping, gfc_free_interface_mapping)
	(gfc_get_interface_mapping_charlen, gfc_get_interface_mapping_array)
	(gfc_set_interface_mapping_bounds, gfc_add_interface_mapping)
	(gfc_finish_interface_mapping, gfc_apply_interface_mapping_to_cons)
	(gfc_apply_interface_mapping_to_ref)
	(gfc_apply_interface_mapping_to_expr)
	(gfc_apply_interface_mapping): New functions.
	(gfc_conv_function_call): Evaluate the arguments before working
	out where the result should go.  Make the null pointer case provide
	the string length in parmse.string_length.  Cope with non-constant
	string lengths, using the above functions to evaluate such lengths.
	Use a temporary typespec; don't assign to sym->cl->backend_decl.
	Don't assign to se->string_length when returning a cached array
	descriptor.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/ChangeLog.diff?cvsroot=gcc&r1=1.540&r2=1.541
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/trans-array.c.diff?cvsroot=gcc&r1=1.56&r2=1.57
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/trans-expr.c.diff?cvsroot=gcc&r1=1.59&r2=1.60
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.6030&r2=1.6031
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/char_result_1.f90.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/char_result_2.f90.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/char_result_3.f90.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/char_result_4.f90.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/char_result_5.f90.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/char_result_6.f90.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/char_result_7.f90.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/char_result_8.f90.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 13 rsandifo@gcc.gnu.org 2005-09-08 18:51:12 UTC
Patch committed to trunk.
Comment 14 Thomas Koenig 2005-09-18 19:52:56 UTC
Not fixed in 4.0:

$ cat > reduced.f90
  program Decapitation
    implicit none
    integer, parameter :: STRING_LENGTH = 80
    character (len = STRING_LENGTH) :: Text_1, Text_2
    Text_2 = Decap (Text_1)
    stop
  contains
    function Decap (String) result (New_String)
      character (len = *), intent(in) :: String
      character (len = Len(String)) :: New_String
      return
    end function Decap
  end program Decapitation
$ gfortran reduced.f90
reduced.f90: In function 'MAIN__':
reduced.f90:11: internal compiler error: in gfc_conv_function_call, at
fortran/trans-expr.c:1108
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
$ gfortran -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../gcc-4.0/configure --prefix=/home/ig25
--enable-languages=c,fortran
Thread model: posix
gcc version 4.0.2 20050917 (prerelease)
Comment 15 Andrew Pinski 2005-09-18 20:27:15 UTC
All of these are fixed in 4.1.0. Since 4.0.2 is the last 4.0 release before a 4.1.0 release will be made, 
4.0.2 and 4.0.1 were special releases for gfrotran.  4.0.3 should be a normal release for GCC and 
gfortran in that regressions are the only changes.
Comment 16 Andrew Pinski 2005-11-24 06:06:45 UTC
*** Bug 25012 has been marked as a duplicate of this bug. ***