Bug 50585 - [4.6/4.7 Regression] ICE with assumed length character array argument
Summary: [4.6/4.7 Regression] ICE with assumed length character array argument
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.6.1
: P3 normal
Target Milestone: ---
Assignee: janus
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2011-10-01 07:36 UTC by Stuart Mentzer
Modified: 2011-10-07 21:23 UTC (History)
2 users (show)

See Also:
Host: Fedora 15 x64
Target: Fedora 15 x64
Build:
Known to work: 4.5.3
Known to fail: 4.6.1, 4.7.0
Last reconfirmed: 2011-10-01 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stuart Mentzer 2011-10-01 07:36:15 UTC
Compiling these 2 routines in the same source file with gfortran -c

      SUBROUTINE SUB1( str )
      IMPLICIT NONE
      CHARACTER(len=*) :: str(2)
      CALL SUB2( str(1)(:3) )
      END SUBROUTINE SUB1

      SUBROUTINE SUB2( str )
      IMPLICIT NONE
      CHARACTER(*) :: str
      END SUBROUTINE SUB2

gives this ICE:

f951: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://bugzilla.redhat.com/bugzilla> for instructions.

with gfortran 4.6.1 on Fedora 15 (x64) and with MinGW on Win32.

The problem was also observed on 4.6.0 on Fedora 15 but was not seen on 4.5.x.

The ICE does not occur if any of these are true:
 -fno-whole-file is used
 The routines are in separate files 
 The str array is changed to a scalar
 The str length is changed to a constant
Comment 1 janus 2011-10-01 09:55:59 UTC
This is a regression: Works with 4.5, but fails with 4.6 and trunk.
Comment 2 janus 2011-10-01 10:03:33 UTC
Backtrace:

Program received signal SIGSEGV, Segmentation fault.
0x00000000004e1f73 in get_expr_storage_size (e=0x1bc4940) at /home/jweil/gcc47/trunk/gcc/fortran/interface.c:1963
1963                      || ref->u.ss.length->length->expr_type != EXPR_CONSTANT)
(gdb) bt
#0  0x00000000004e1f73 in get_expr_storage_size (e=0x1bc4940) at /home/jweil/gcc47/trunk/gcc/fortran/interface.c:1963
#1  0x00000000004e2dbf in compare_actual_formal (ap=0x1bc4fc0, formal=0x1bc48a0, ranks_must_agree=0, is_elemental=0, where=0x1bc4f58)
    at /home/jweil/gcc47/trunk/gcc/fortran/interface.c:2248
#2  0x00000000004e46ff in gfc_procedure_use (sym=0x1bc5a10, ap=0x1bc4fc0, where=0x1bc4f58) at /home/jweil/gcc47/trunk/gcc/fortran/interface.c:2877
#3  0x00000000005365a0 in resolve_global_procedure (sym=0x1bc45e0, where=0x1bc4f58, actual=0x1bc4fc0, sub=<optimized out>)
    at /home/jweil/gcc47/trunk/gcc/fortran/resolve.c:2254
#4  0x000000000053e3f8 in resolve_call (c=0x1bc4f40) at /home/jweil/gcc47/trunk/gcc/fortran/resolve.c:3656
#5  0x0000000000542a31 in resolve_code (code=0x1bc4f40, ns=<optimized out>) at /home/jweil/gcc47/trunk/gcc/fortran/resolve.c:9310
#6  0x0000000000544c7d in resolve_codes (ns=0x1bc3210) at /home/jweil/gcc47/trunk/gcc/fortran/resolve.c:13658
#7  0x000000000053617c in gfc_resolve (ns=0x1bc3210) at /home/jweil/gcc47/trunk/gcc/fortran/resolve.c:13685
#8  0x0000000000529ebf in resolve_all_program_units (gfc_global_ns_list=0x1bc3210) at /home/jweil/gcc47/trunk/gcc/fortran/parse.c:4336
#9  0x000000000052a6b7 in gfc_parse_file () at /home/jweil/gcc47/trunk/gcc/fortran/parse.c:4602
#10 0x0000000000567c1b in gfc_be_parse_file () at /home/jweil/gcc47/trunk/gcc/fortran/f95-lang.c:250
#11 0x0000000000b5b2fc in compile_file () at /home/jweil/gcc47/trunk/gcc/toplev.c:565
#12 0x0000000000b5d5b5 in do_compile () at /home/jweil/gcc47/trunk/gcc/toplev.c:1925
#13 0x0000000000b5d72c in toplev_main (argc=2, argv=0x7fffffffddc8) at /home/jweil/gcc47/trunk/gcc/toplev.c:2001
#14 0x000000000061e71c in main (argc=2, argv=0x7fffffffddc8) at /home/jweil/gcc47/trunk/gcc/main.c:36


The problem is:

(gdb) p ref->u.ss.length->length
$3 = (struct gfc_expr *) 0x0
Comment 3 janus 2011-10-01 10:09:56 UTC
Simple fix:

Index: gcc/fortran/interface.c
===================================================================
--- gcc/fortran/interface.c     (revision 179412)
+++ gcc/fortran/interface.c     (working copy)
@@ -1959,7 +1959,7 @@
            {
              /* The string length is the substring length.
                 Set now to full string length.  */
-             if (ref->u.ss.length == NULL
+             if (!ref->u.ss.length || !ref->u.ss.length->length
                  || ref->u.ss.length->length->expr_type != EXPR_CONSTANT)
                return 0;
Comment 4 Dominique d'Humieres 2011-10-01 10:15:31 UTC
> This is a regression: Works with 4.5, but fails with 4.6 and trunk.

4.5 gives a segmentation fault with  -fwhole-file (4.4 does not accept this option).
Comment 5 janus 2011-10-01 10:24:42 UTC
(In reply to comment #4)
> 4.5 gives a segmentation fault with  -fwhole-file (4.4 does not accept this
> option).

Well, then one can even argue that it's a regression in 4.5, too.

IIRC, -fwhole-file is default since 4.6, right? However, if this is true, it is not documented in the manual:

http://gcc.gnu.org/onlinedocs/gcc-4.6.1/gfortran/Code-Gen-Options.html#Code-Gen-Options
Comment 6 janus 2011-10-01 11:24:46 UTC
(In reply to comment #5)
> IIRC, -fwhole-file is default since 4.6, right? However, if this is true, it is
> not documented in the manual:
> 
> http://gcc.gnu.org/onlinedocs/gcc-4.6.1/gfortran/Code-Gen-Options.html#Code-Gen-Options

Apparently I do remember correctly, as http://gcc.gnu.org/gcc-4.6/changes.html confirms.


Also the patch in comment #3 regtests cleanly. Will commit as obvious.
Comment 7 janus 2011-10-01 11:41:49 UTC
Author: janus
Date: Sat Oct  1 11:41:41 2011
New Revision: 179413

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=179413
Log:
2011-10-01  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/50585
	* interface.c (get_expr_storage_size): Check if 'length' component is
	associated.


2011-10-01  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/50585
	* gfortran.dg/assumed_charlen_arg_2.f90: New.

Added:
    trunk/gcc/testsuite/gfortran.dg/assumed_charlen_arg_2.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/interface.c
    trunk/gcc/testsuite/ChangeLog
Comment 8 janus 2011-10-01 12:13:04 UTC
Fixed on trunk with r179413. Backport to 4.6 (and 4.5?) pending ...
Comment 9 janus 2011-10-07 21:01:06 UTC
Author: janus
Date: Fri Oct  7 21:01:02 2011
New Revision: 179696

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=179696
Log:
2011-10-07  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/50585
	* interface.c (get_expr_storage_size): Check if 'length' component is
	associated.

	PR fortran/50625
	* class.c (gfc_build_class_symbol): Fix whitespace.
	* module.c (mio_symbol): Set 'class_ok' attribute.
	* trans-decl.c (gfc_get_symbol_decl): Make sure the backend_decl has
	been built for class symbols.


2011-10-07  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/50585
	* gfortran.dg/assumed_charlen_arg_2.f90: New.

	PR fortran/50625
	* gfortran.dg/class_46.f03: New.

Added:
    branches/gcc-4_6-branch/gcc/testsuite/gfortran.dg/assumed_charlen_arg_2.f90
    branches/gcc-4_6-branch/gcc/testsuite/gfortran.dg/class_46.f03
Modified:
    branches/gcc-4_6-branch/gcc/fortran/ChangeLog
    branches/gcc-4_6-branch/gcc/fortran/class.c
    branches/gcc-4_6-branch/gcc/fortran/interface.c
    branches/gcc-4_6-branch/gcc/fortran/module.c
    branches/gcc-4_6-branch/gcc/fortran/trans-decl.c
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
Comment 10 janus 2011-10-07 21:23:47 UTC
Fixed on 4.6 and trunk. Closing.

Thanks for the report!