Bug 32710 - ICE: namelist and subroutine with the same name
Summary: ICE: namelist and subroutine with the same name
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: ice-on-valid-code
Depends on:
Blocks: 32834
  Show dependency treegraph
 
Reported: 2007-07-09 21:49 UTC by Janus Weil
Modified: 2007-07-22 16:38 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.1.3 4.2.1 4.3.0
Last reconfirmed: 2007-07-21 18:20:59


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Janus Weil 2007-07-09 21:49:49 UTC
program samename

contains


  subroutine readInput
    implicit none
    integer:: a,b,c
    NAMELIST /name/ a,b,c
    read(5,nml=name)
  end subroutine readInput


  subroutine name()

  end subroutine name


end program


this code fails with the following error (gfortran 4.3 and 4.1.3):

samename.f90: In function ‘readinput’:
samename.f90:6: internal compiler error: Segmentation fault

for gfortran 4.2 the error message is:

samename.f90: In function ‘readinput’:
samename.f90:6: internal compiler error: in gfc_typenode_for_spec, at fortran/trans-types.c:693


just defining the namelist works fine, only the read statement triggers the ICE
Comment 1 Tobias Burnus 2007-07-09 21:57:56 UTC
Works for me with 4.3.0; I can reproduce the ICE with 4.2 and 4.1.

valgrind with 4.3.0 shows:
==18422== Invalid read of size 8
==18422==    at 0x4A3FB2: build_dt (trans-io.c:1592)
==18422==    by 0x47819E: gfc_trans_code (trans.c:670)
==18422==    by 0x48CCFE: gfc_generate_function_code (trans-decl.c:3224)
==18422==    by 0x48CF84: gfc_generate_function_code (trans-decl.c:2838)
==18422==    by 0x44E0C3: gfc_parse_file (parse.c:3279)
==18422==    by 0x47279D: gfc_be_parse_file (f95-lang.c:301)
==18422==    by 0x6B3733: toplev_main (toplev.c:1051)
==18422==    by 0x52BEB43: (below main) (in /lib64/libc-2.6.so)
==18422==  Address 0x40E1F50 is 0 bytes inside a block of size 392 free'd
==18422==    at 0x4C2291B: free (in /usr/lib64/valgrind/amd64-linux/vgpreload_memcheck.so)
==18422==    by 0x44BBBA: gfc_fixup_sibling_symbols (parse.c:2774)
==18422==    by 0x44DAD4: parse_contained (parse.c:2858)
==18422==    by 0x44DDEC: parse_progunit (parse.c:2980)
==18422==    by 0x44E094: gfc_parse_file (parse.c:3217)
==18422==    by 0x47279D: gfc_be_parse_file (f95-lang.c:301)
==18422==    by 0x6B3733: toplev_main (toplev.c:1051)
==18422==    by 0x52BEB43: (below main) (in /lib64/libc-2.6.so)
Comment 2 Tobias Burnus 2007-07-09 22:34:48 UTC
If one moves "subroutine name()" before "readinput", valgrind shows no problems. (And no ICE occurs with 4.2 and 4.1.)

This occures for dt->namelist->name, which is "name" (len 4)
==18422==    at 0x4A3FB2: build_dt (trans-io.c:1592)
Comment 3 Daniel Franke 2007-07-21 18:20:59 UTC
(gdb) bt
#0  0xb7dc39f3 in strlen () from /lib/libc.so.6
#1  0x080ee408 in build_dt (function=0xb7cdc600, code=0x8937610) at ../../../gcc/gcc/fortran/trans-io.c:1257
#2  0x080be6ce in gfc_trans_code (code=0x8937610) at ../../../gcc/gcc/fortran/trans.c:670
#3  0x080d55e2 in gfc_generate_function_code (ns=0x8936830) at ../../../gcc/gcc/fortran/trans-decl.c:3266
#4  0x080d5887 in gfc_generate_function_code (ns=0x89362a8) at ../../../gcc/gcc/fortran/trans-decl.c:2847
#5  0x0809354d in gfc_parse_file () at ../../../gcc/gcc/fortran/parse.c:3286
#6  0x080b892d in gfc_be_parse_file (set_yydebug=0) at ../../../gcc/gcc/fortran/f95-lang.c:301
#7  0x0832a690 in toplev_main (argc=2, argv=0xbfa58814) at ../../../gcc/gcc/toplev.c:1044
#8  0x080ff5ff in main (argc=Cannot access memory at address 0x0
) at ../../../gcc/gcc/main.c:35

I'll have a look.
Comment 4 Daniel Franke 2007-07-21 20:32:52 UTC
Dumping the parse tree shows that somewhere the symbol of the subroutine gets hooked into the NML-part of the READ statement:

namelist 'foo', subroutine 'foo2':
    Namespace: A-H: (REAL 4) I-N: (INTEGER 4) O-Z: (REAL 4)
    procedure name = readinput
    symtree: readinput  Ambig 0 from namespace MAIN__
    symtree: foo  Ambig 0
    symbol foo (UNKNOWN 0)(NAMELIST UNKNOWN-INTENT UNKNOWN-ACCESS UNKNOWN-PROC UNKNOWN)

    READ UNIT=5 NML=foo
    DT_END

namelist 'foo', subroutine 'foo':
    Namespace: A-H: (REAL 4) I-N: (INTEGER 4) O-Z: (REAL 4)
    procedure name = readinput
    symtree: readinput  Ambig 0 from namespace MAIN__
    symtree: foo  Ambig 0 from namespace MAIN__

    READ UNIT=5 NML=`rзи`rзиллprзиprзиxrзиxrзиrзиrзиrзиrзиrзиrзиrзиrзиаrзиаrзиšrзиšrзи░rзи░rзиžrзиžrзи└rзи└rзи╚rзи╚rзилrзилrзипrзипrзиЯrзиЯrзиУrзиУrзи­rзи­rзиЭrзиЭrзи
    DT_END


Note the wrong namespace association of 'foo' in the second dump.
Comment 5 Daniel Franke 2007-07-21 23:42:47 UTC
Things are messed up in parse.c(gfc_fixup_sibling_symbols) ...
Comment 6 patchapp@dberlin.org 2007-07-22 09:20:26 UTC
Subject: Bug number PR32710

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/msg01640.html
Comment 7 Daniel Franke 2007-07-22 16:37:26 UTC
Subject: Bug 32710

Author: dfranke
Date: Sun Jul 22 16:37:12 2007
New Revision: 126828

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

	PR fortran/32710
	* parse.c (gfc_fixup_sibling_symbols): No replacement of symbols if
	the current is a namelist.

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

	PR fortran/32710
	* gfortran.dg/namelist_30.f90: New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/namelist_30.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/parse.c
    trunk/gcc/testsuite/ChangeLog

Comment 8 Daniel Franke 2007-07-22 16:38:32 UTC
Fixed in trunk. Closing.