Using the following invalid program, one gets an ICE NAG f95: Assignment to Z in PURE procedure BAR gfortran: segmentation fault. subroutine foo () integer :: z contains pure function bar (a) integer, intent(in) :: a integer :: bar z = 45 ! <<<<<<<<<<< bar = a end function bar end subroutine foo
Seemingly the error is detected and only on writing the error the segmentation fault occurs: ==494== Invalid read of size 8 ==494== at 0x41D398: show_locus (error.c:171) ==494== by 0x41D29D: error_print (error.c:521) ==494== by 0x41DB1E: gfc_error (error.c:759) ==494== by 0x45B930: resolve_code (resolve.c:5871) ==494== by 0x45BB10: resolve_codes (resolve.c:8472) ==494== by 0x45BACF: resolve_codes (resolve.c:8464) ==494== by 0x45BB54: gfc_resolve (resolve.c:8491) ==494== by 0x44E507: gfc_parse_file (parse.c:3271) ==494== by 0x472FBD: gfc_be_parse_file (f95-lang.c:301) ==494== by 0x6B4BC3: toplev_main (toplev.c:1044) ==494== by 0x52BEB43: (below main) (in /lib64/libc-2.6.so)
Others cannot reproduce it (on i686 & x86_64), but here I can with gfortran-4.1 & 4.2 of SUSE, with the vanilla 4.2 and with 4.3. The problem is for whatever reason the "&code->expr->where" argument to gfc_error(). In error_print the "loc" argument is not NULL, but loc->lb->* point to invalid locations, which gave an memory access error (segfault) in show_locus when accessing lb->file. 484 loc = va_arg (argp, locus *); 486 if (have_l1) (gdb) p loc $8 = (locus *) 0xfdc13a (gdb) p loc->lb $9 = (gfc_linebuf *) 0x610072616200736e (gdb) p loc->lb->file Cannot access memory at address 0x6100726162007376 (gdb) p loc->lb->line Cannot access memory at address 0x610072616200738a (gdb) p loc->lb->file Cannot access memory at address 0x6100726162007376 But no problem for others.
This is a translation bug: msgid "Cannot assign to variable '%s' in PURE procedure at %L" msgstr "In PURE-Prozedur bei %L kann nicht an Variable »%s« zugewiesen werden" As %L / %s is reverted, gfortran crashes. Solution: Replace %L ... %s by %2$L ... %1$s I reported the bug to the DE language team.