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
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)
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)
(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.
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.
Things are messed up in parse.c(gfc_fixup_sibling_symbols) ...
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
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
Fixed in trunk. Closing.