Bug 32867 - [4.3 Regression] ICE on nested initialization expressions
Summary: [4.3 Regression] ICE on nested initialization expressions
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: Daniel Franke
URL:
Keywords:
Depends on:
Blocks: 32834
  Show dependency treegraph
 
Reported: 2007-07-23 14:59 UTC by H.J. Lu
Modified: 2007-07-24 16:59 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-07-23 16:36:25


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2007-07-23 14:59:36 UTC
This patch

http://gcc.gnu.org/ml/gcc-cvs/2007-07/msg00685.html

causes

(gdb) r readdata.f90 -quiet -dumpbase readdata.f90 -mtune=generic -auxbase readdata -O2 -version -ffast-math -o readdata.s -fintrinsic-modules-path /export/gnu/import/rrs/126826/usr/lib/gcc/x86_64-unknown-linux-gnu/4.3.0/finclude
Starting program: /export/gnu/import/rrs/126826/usr/libexec/gcc/x86_64-unknown-linux-gnu/4.3.0/f951 readdata.f90 -quiet -dumpbase readdata.f90 -mtune=generic -auxbase readdata -O2 -version -ffast-math -o readdata.s -fintrinsic-modules-path /export/gnu/import/rrs/126826/usr/lib/gcc/x86_64-unknown-linux-gnu/4.3.0/finclude
GNU F95 version 4.3.0 20070722 (experimental) (x86_64-unknown-linux-gnu)
        compiled by GNU C version 3.4.6 20060404 (Red Hat 3.4.6-8), GMP version 4.2.1, MPFR version 2.2.1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072

Program received signal SIGSEGV, Segmentation fault.
0x00000000004072b5 in gfc_compare_string (a=0xe78f90, b=0xe79710)
    at ../../src/gcc/fortran/arith.c:1171
1171          ac = (unsigned char) ((i < alen) ? a->value.character.string[i] : ' ');
(gdb) p a->value
$1 = {logical = 15170912, integer = {{_mp_alloc = 15170912, _mp_size = 0,
      _mp_d = 0xe660fd}}, real = {{_mpfr_prec = 15170912,
      _mpfr_sign = 15098109, _mpfr_exp = 14833104, _mpfr_d = 0x0}}, complex = {
    r = {{_mpfr_prec = 15170912, _mpfr_sign = 15098109, _mpfr_exp = 14833104,
        _mpfr_d = 0x0}}, i = {{_mpfr_prec = 0, _mpfr_sign = 0, _mpfr_exp = 0,
        _mpfr_d = 0x0}}}, op = {operator = 15170912, uop = 0xe660fd,
    op1 = 0xe255d0, op2 = 0x0}, function = {actual = 0xe77d60,
    name = 0xe660fd "__trim_1", isym = 0xe255d0, esym = 0x0}, character = {
    length = 15170912, string = 0xe660fd "__trim_1"}, constructor = 0xe77d60}
(gdb) p a->value.character
$2 = {length = 15170912, string = 0xe660fd "__trim_1"}
(gdb) list
1166
1167      for (i = 0; i < len; i++)
1168        {
1169          /* We cast to unsigned char because default char, if it is signed,
1170             would lead to ac < 0 for string[i] > 127.  */
1171          ac = (unsigned char) ((i < alen) ? a->value.character.string[i] : ' ');
1172          bc = (unsigned char) ((i < blen) ? b->value.character.string[i] : ' ');
1173
1174          if (ac < bc)
1175            return -1;
(gdb) p b->value.character.string
$3 = 0xe660fd "__trim_1"
(gdb) p a->value.character.string
$4 = 0xe660fd "__trim_1"
(gdb) p i
$5 = 741123
(gdb) p len
$6 = 15180528
(gdb) bt
#0  0x00000000004072b5 in gfc_compare_string (a=0xe78f90, b=0xe79710)
    at ../../src/gcc/fortran/arith.c:1171
#1  0x0000000000407393 in gfc_compare_expr (op1=0xe78f90, op2=0xe79710)
    at ../../src/gcc/fortran/arith.c:1126
#2  0x000000000045567a in resolve_code (code=0xe78b30, ns=0xe6e770)
    at ../../src/gcc/fortran/resolve.c:4541
#3  0x00000000004558e4 in gfc_resolve_blocks (b=0xe75530, ns=0xe6e770)
    at ../../src/gcc/fortran/resolve.c:5699
#4  0x0000000000454150 in resolve_code (code=0xe71740, ns=0xe6e770)
    at ../../src/gcc/fortran/resolve.c:5758
#5  0x000000000045771b in resolve_codes (ns=0xe6e770)
    at ../../src/gcc/fortran/resolve.c:8463
#6  0x00000000004576da in resolve_codes (ns=0xe63e70)
    at ../../src/gcc/fortran/resolve.c:8455
#7  0x0000000000457755 in gfc_resolve (ns=0xe63e70)
    at ../../src/gcc/fortran/resolve.c:8482
#8  0x000000000044acac in gfc_parse_file ()
    at ../../src/gcc/fortran/parse.c:3270
#9  0x000000000046d7ce in gfc_be_parse_file (set_yydebug=<value optimized out>)
    at ../../src/gcc/fortran/f95-lang.c:301
#10 0x00000000005f9f7e in toplev_main (argc=<value optimized out>,
    argv=<value optimized out>) at ../../src/gcc/toplev.c:1044
#11 0x00000033b381c3fb in __libc_start_main () from /lib64/tls/libc.so.6
---Type <return> to continue, or q <return> to quit---
#12 0x00000000004053da in _start ()
(gdb)

Daniel, does it ring a bell?
Comment 1 H.J. Lu 2007-07-23 15:02:16 UTC
(gdb) p b->value.character
$10 = {length = 15180528, string = 0xe660fd "__trim_1"}
(gdb) p a->value.character
$11 = {length = 15170912, string = 0xe660fd "__trim_1"}

The length field doesn't look right.
Comment 2 Daniel Franke 2007-07-23 15:08:46 UTC
Not yet.

http://gcc.gnu.org/ml/gcc-patches/2007-07/msg01652.html

is an update for the quoted patch, it might help to the extend that you get an error, not an ice. 

What does the corresponding Fortran code look like?
Comment 3 H.J. Lu 2007-07-23 16:09:13 UTC
(In reply to comment #2)
> Not yet.
> 
> http://gcc.gnu.org/ml/gcc-patches/2007-07/msg01652.html
> 
> is an update for the quoted patch, it might help to the extend that you get an
> error, not an ice.

It makes no difference.

> 
> What does the corresponding Fortran code look like?

I am working on a small testcase.

Comment 4 H.J. Lu 2007-07-23 16:23:19 UTC
Here is a small testcase:

[hjl@gnu-26 459.GemsFDTD]$ cat foo.f90 
MODULE Readdata_mod
IMPLICIT NONE
Private
Public  Parser
integer, parameter                    :: nkeywords = 2
character(80), PARAMETER, dimension(1:nkeywords) :: keywords = &
 (/'PROBLEMSIZE                                  ',            &
   'NFTRANS_TD                                   '/)

CONTAINS
SUBROUTINE Parser(nx, ny, keyword)
  integer, intent(inout) :: nx, ny
  character(80), intent(inout) :: keyword
  select case (keyword)
  case (trim(keywords(1))) ! PROBLEMSIZE
    nx = 1
  case (trim(keywords(2))) !'NFTRANS_TD'
    ny = 1
  end select
END SUBROUTINE Parser
END MODULE Readdata_mod
[hjl@gnu-26 459.GemsFDTD]$ ../126826/usr/bin/gfortran       -O2 -ffast-math        -DSPEC_CPU_LP64          -S  foo.f90
foo.f90:0: 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.
[hjl@gnu-26 459.GemsFDTD]$  
Comment 5 H.J. Lu 2007-07-23 16:31:28 UTC
A smaller testcase:

[hjl@gnu-26 459.GemsFDTD]$ cat foo.f90 
SUBROUTINE Parser(nx, ny, keyword)
  character(80), PARAMETER, dimension(1:2) :: keywords = &
   (/'PROBLEMSIZE', &
     'NFTRANS_TD'/)
  integer, intent(inout) :: nx, ny
  character(80), intent(inout) :: keyword
  select case (keyword)
  case (trim(keywords(1))) ! PROBLEMSIZE
    nx = 1
  case (trim(keywords(2))) !'NFTRANS_TD'
    ny = 1
  end select
END SUBROUTINE Parser
[hjl@gnu-26 459.GemsFDTD]$ ../126826/usr/bin/gfortran       -O2 -ffast-math        -DSPEC_CPU_LP64          -S  foo.f90
foo.f90:0: 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.
[hjl@gnu-26 459.GemsFDTD]$ 
Comment 6 Daniel Franke 2007-07-23 16:36:25 UTC
Confirmed. Will look into it.
As it works with scalars, I think I forgot to take arrays into account ...
Comment 7 Joost VandeVondele 2007-07-23 18:46:21 UTC
(In reply to comment #5)
>   character(80), PARAMETER, dimension(1:2) :: keywords = &
>    (/'PROBLEMSIZE', &
>      'NFTRANS_TD'/)


it is probably not related to the ICE, but the above is invalid F95. 
Error: test.f90, line 2: Array constructor values have differing CHARACTER lengths (11 and 10). gfortran should error out on this.
Comment 8 Daniel Franke 2007-07-23 18:50:08 UTC
> it is probably not related to the ICE, but the above is invalid F95. 
> Error: test.f90, line 2: Array constructor values have differing CHARACTER
> lengths (11 and 10). gfortran should error out on this.

This is PR29267 (and PR32707 is probably a dupe).
Comment 9 Daniel Franke 2007-07-23 19:42:01 UTC
Currently regtesting the patch below without problem so far.
H.J. could you please verify that it fixes your problem?

Index: expr.c
===================================================================
--- expr.c      (revision 126826)
+++ expr.c      (working copy)
@@ -2121,7 +2132,7 @@
        }

       if (m == MATCH_YES)
-       t = SUCCESS;
+       t =  gfc_simplify_expr (e, 0);

       break;
Comment 10 H.J. Lu 2007-07-23 19:53:03 UTC
(In reply to comment #9)
> Currently regtesting the patch below without problem so far.
> H.J. could you please verify that it fixes your problem?
> 
> Index: expr.c
> ===================================================================
> --- expr.c      (revision 126826)
> +++ expr.c      (working copy)
> @@ -2121,7 +2132,7 @@
>         }
> 
>        if (m == MATCH_YES)
> -       t = SUCCESS;
> +       t =  gfc_simplify_expr (e, 0);
> 
>        break;
> 

It passed my small testcase. The full test will take several hours.
Comment 11 Daniel Franke 2007-07-23 20:08:32 UTC
Patch in comment #9 passed regression testing on i686-pc-linux-gnu.
Comment 12 H.J. Lu 2007-07-24 03:33:30 UTC
(In reply to comment #9)
> Currently regtesting the patch below without problem so far.
> H.J. could you please verify that it fixes your problem?
> 
> Index: expr.c
> ===================================================================
> --- expr.c      (revision 126826)
> +++ expr.c      (working copy)
> @@ -2121,7 +2132,7 @@
>         }
> 
>        if (m == MATCH_YES)
> -       t = SUCCESS;
> +       t =  gfc_simplify_expr (e, 0);
> 
>        break;
> 

I have verified that 459.GemsFDTD is compiled correctly with this patch.
Thanks.
Comment 13 patchapp@dberlin.org 2007-07-24 08:45:13 UTC
Subject: Bug number PR32867

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2007-07/msg01713.html
Comment 14 Daniel Franke 2007-07-24 16:57:12 UTC
Subject: Bug 32867

Author: dfranke
Date: Tue Jul 24 16:57:02 2007
New Revision: 126882

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=126882
Log:
gcc/fortran:
2007-07-24  Daniel Franke  <franke.daniel@gmail.com>

	PR fortran/32867
	* expr.c (check_init_expr): Simplify matched functions.

gcc/testsuite:
2007-07-24  Daniel Franke  <franke.daniel@gmail.com>

	PR fortran/32867
	* fortran.dg/initialization_10.f90: New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/initialization_10.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/expr.c
    trunk/gcc/testsuite/ChangeLog

Comment 15 Daniel Franke 2007-07-24 16:59:34 UTC
Changed the title to reflect the actual problem.
Closing as fixed.