Currently, gfortran ships (trans*.c) MODULEs directly while it waits until the end for subroutines, functions and PROGRAM. The latter are then first all resolved and afterwards the middle-end code is generated. In the PR this shows an issue: The a module procedure calls an external subroutine - which exists as gsym. In trans-decl one therefore uses the symbol information from gsym, which causes an ICE as the latter has not yet been resolved. The solution is to first resolve the whole translation unit (file) before starting to generate middle end code. The only disadvantage is that it increases the required memory, however, it might be easier to re-use the module data later when gfortran stops reading module files all the time. I am also not 100% sure that I free all structures, though the patch probably frees most. Build and regtested on x86-64-linux. OK for the trunk - and after some grace period - for the 4.6 branch? Tobias PS: The code works with -fno-whole-file as then the code is always generated immediately. (Additionally, gsym is not used then.) PPS: There are still three open 4.6/4.7 regressions - besides this one and the -frealloc-lhs issue Paul is working on. We should really fix those before 4.6.1 is released and Linux distributions and others start to heavily using 4.6.x.