Bug 32703 - ICE with [trim(character_variable)]
Summary: ICE with [trim(character_variable)]
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: 4.3.0
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks: 19276 32834
  Show dependency treegraph
 
Reported: 2007-07-09 15:29 UTC by Vivek Rao
Modified: 2007-08-31 06:21 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-07-10 20:54:24


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vivek Rao 2007-07-09 15:29:50 UTC
For the program

program array_char
implicit none
character (len=1) :: x
x = "a"
print*,[trim(x)]
end program array_char

compiling on Windows XP with

gfortran -v xconcat.f90

produces an ICE:

Driving: gfortran -v xconcat.f90 -lgfortranbegin -lgfortran
Using built-in specs.
Target: i386-pc-mingw32
Configured with: ../trunk/configure --prefix=/mingw --enable-languages=c,fortran --with-gmp=/home/coudert/local --disable-nls --with-ld=/mingw/bin/ld --with-as=/mingw/bin/as --disable-werror --enable-bootstrap --enable-threads --build=i386-pc-mingw32 --disable-shared --enable-libgomp
Thread model: win32
gcc version 4.3.0 20070706 (experimental)
 c:/programs/gfortran/bin/../libexec/gcc/i386-pc-mingw32/4.3.0/f951.exe xconcat.f90 -quiet -dumpbase xconcat.f90 -mtune=i386 -auxbase xconcat -version -fintrinsic-modules-path c:/programs/gfortran/bin/../lib/gcc/i386-pc-mingw32/4.3.0/finclude -o C:\DOCUME~1\vrao\LOCALS~1\Temp/cc8grzTr.s
GNU F95 version 4.3.0 20070706 (experimental) (i386-pc-mingw32)
	compiled by GNU C version 4.3.0 20070706 (experimental), GMP version 4.2.1, MPFR version 2.2.1.
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
xconcat.f90: In function 'MAIN__':
xconcat.f90:4: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.

The program works if the line

print*,[trim(x)]

is replaced with

print*,[x]

or 

print*,trim(x)
Comment 1 Asher Langton 2007-07-09 18:32:52 UTC
Confirmed.  The segfault occurs on trans-array.c:1380 because e->ts->cl is null.
Comment 2 Paul Thomas 2007-07-10 20:54:24 UTC
My coming character patch fixes this.  I'll take it.

Paul
Comment 3 Paul Thomas 2007-08-30 22:11:14 UTC
Subject: Bug 32703

Author: pault
Date: Thu Aug 30 22:10:55 2007
New Revision: 127939

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=127939
Log:
2007-08-31  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/31879
	PR fortran/31197
	PR fortran/31258
	PR fortran/32703
	* gfortran.h : Add prototype for gfc_resolve_substring_charlen.
	* resolve.c (gfc_resolve_substring_charlen): New function.
	(resolve_ref): Call gfc_resolve_substring_charlen.
	(gfc_resolve_character_operator): New function.
	(gfc_resolve_expr): Call the new functions in cases where the
	character length is missing.
	* iresolve.c (cshift, eoshift, merge, pack, reshape, spread,
	transpose, unpack): Call gfc_resolve_substring_charlen for
	source expressions that are character and have a reference.
	* trans.h (gfc_trans_init_string_length) Change name to
	gfc_conv_string_length; modify references in trans-expr.c,
	trans-array.c and trans-decl.c.
	* trans-expr.c (gfc_trans_string_length): Handle case of no
	backend_decl.
	(gfc_conv_aliased_arg): Remove code for treating substrings
	and replace with call to gfc_trans_string_length.
	* trans-array.c (gfc_conv_expr_descriptor): Remove code for
	treating strings and call gfc_trans_string_length instead.

2007-08-31  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/31879
	* gfortran.dg/char_length_7.f90: New test.
	* gfortran.dg/char_length_9.f90: New test.
	* gfortran.dg/char_assign_1.f90: Add extra warning.

	PR fortran/31197
	PR fortran/31258
	* gfortran.dg/char_length_8.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/char_length_7.f90
    trunk/gcc/testsuite/gfortran.dg/char_length_8.f90
    trunk/gcc/testsuite/gfortran.dg/char_length_9.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/iresolve.c
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/trans-array.c
    trunk/gcc/fortran/trans-decl.c
    trunk/gcc/fortran/trans-expr.c
    trunk/gcc/fortran/trans.h
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/char_assign_1.f90

Comment 4 Paul Thomas 2007-08-30 22:18:35 UTC
This no longer segfaults and it generates correct code for valid fortran.  However,

program array_char
implicit none
character (len=2) :: x, y
x = "a "
y = "cd"
print*,[trim(x),trim(y)]
end program array_char

does not generate the runtime error that it should, so I am leaving this PR open.  I have unassigned myself for now but might well return to this soon.

Paul 
Comment 5 Tobias Burnus 2007-08-31 06:10:04 UTC
(In reply to comment #4)
> does not generate the runtime error that it should, so I am leaving this PR
> open.  I have unassigned myself for now but might well return to this soon.

I think it should be enough to give this diagnostic only with -fbounds-check. Additionally, I filled PR 33254 to track this.

I would thus suggest to close this PR as fixed - or at least remove remove the blocking of PR32834.
Comment 6 Tobias Burnus 2007-08-31 06:21:15 UTC
(Close the bug myself.)

The ICE mentioned in the subject is FIXED for the trunk.

As said, PR 33254 tracks the run-time diagnostic for different string lengths in array constructors.