Bug 36476 - ICE: len=* CHARACTER array with separate PARAMETER statement
Summary: ICE: len=* CHARACTER array with separate PARAMETER statement
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.1
: P3 normal
Target Milestone: ---
Assignee: Tobias Burnus
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2008-06-09 14:04 UTC by Walter Zimmer
Modified: 2008-06-13 13:14 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2008-06-12 19:26:48


Attachments
Patch; TODO: Create test cases (incl. for kind=4) (436 bytes, patch)
2008-06-12 18:32 UTC, Tobias Burnus
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Walter Zimmer 2008-06-09 14:04:49 UTC
The following code triggers an ICE even with gfortran 4.3.1:
=================================================================
bash$ gfortran -v
Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-4.3.1/configure --with-pkgversion='DLR MF/AP UPAS 2008-06-09' --with-bugurl=walter.zimmer@dlr.de --prefix=/local/upas/inst-devel --enable-languages=c,c++,fortran --with-gmp-include=/local/upas/compile/gmp-4.2.2 --with-gmp-lib=/local/upas/compile/gmp-4.2.2/.libs --with-mpfr-include=/local/upas/compile/mpfr-2.3.1 --with-mpfr-lib=/local/upas/compile/mpfr-2.3.1/.libs
Thread model: posix
gcc version 4.3.1 (DLR MF/AP UPAS 2008-06-09)
bash$ cat funny.F
      SUBROUTINE FUNNY_STRINGS

      character*256   STRING

      CHARACTER (len=*) MY_STRING(1:3)
      PARAMETER ( MY_STRING =  (/ "A" , "B", "C" /) )

      STRING = MY_STRING(1)

      RETURN
      END
bash$ gfortran -c funny.F
funny.F: In function ‘funny_strings’:
funny.F:1: internal compiler error: in gfc_get_symbol_decl, at fortran/trans-decl.c:1031
=================================================================

I suspect this is valid code, but at the end this is not the point as an ICE should not happen here.

Maybe it's related to bug id 36322, as an array is also used there, but the line number in gfc_get_symbol_decl is different, so I suspect not.

This ICE is also triggered with gfortran 4.3.0 and 4.1.2.
Comment 1 Tobias Burnus 2008-06-09 16:40:32 UTC
CONFIRM. The failing assert is:
          gcc_assert (!sym->value);

Work around: Use the following syntax
   CHARACTER (len=*), PARAMETER :: MY_STRING(1:3) = (/ "A" , "B", "C" /)

or explicitly give the length of the character length:
   CHARACTER (len=1) MY_STRING(1:3)
Comment 2 Walter Zimmer 2008-06-10 08:11:55 UTC
The workaround works fine, many thanks!
Comment 3 Tobias Burnus 2008-06-12 18:32:18 UTC
Created attachment 15758 [details]
Patch; TODO: Create test cases (incl. for kind=4)
Comment 4 Tobias Burnus 2008-06-12 19:26:48 UTC
> TODO: Create test cases (incl. for kind=4)
And with -std=f95: checking for equal string lengths. Also the initialization by an other parameter should be checked. I will work on a test case in the next days.

Comment 5 Tobias Burnus 2008-06-13 13:05:10 UTC
Subject: Bug 36476

Author: burnus
Date: Fri Jun 13 13:04:26 2008
New Revision: 136754

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=136754
Log:
2008-06-13  Tobias Burnus  <burnus@net-b.de>

        PR fortran/36476
        * decl.c (do_parm): Handle init expression for len=*.

2008-06-13  Tobias Burnus  <burnus@net-b.de>

        PR fortran/36476
        * gfortran.dg/parameter_array_init_4.f90: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/parameter_array_init_4.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/decl.c
    trunk/gcc/testsuite/ChangeLog

Comment 6 Tobias Burnus 2008-06-13 13:14:40 UTC
FIXED on the trunk (4.4.0).

Thanks for the report.