http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48112
--- Comment #4 from Tobias Burnus <burnus at gcc dot gnu.org> 2011-04-26 10:18:23 UTC --- Rev. 159475 works, Rev. 159476 fails, which is the following commit: URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=159476 Log: 2010-05-17 Janus Weil <ja...@gcc.gnu.org> PR fortran/44044 * resolve.c (resolve_fl_var_and_proc): Move error messages here from ... (resolve_fl_variable_derived): ... this place. (resolve_symbol): Make sure function symbols (and their result variables) are not resolved twice. The crucial part of the patch is: + /* Avoid double resolution of function result symbols. */ + if ((sym->result || sym->attr.result) && (sym->ns != gfc_current_ns)) + return; * * * If one places a break point, one sees first: (gdb) p sym->name $5 = 0x2aaaaab40ea8 "test1" (gdb) p sym->ns->sym_root->name $8 = 0x2aaaaab40ea8 "test1" (gdb) p ((sym->result || sym->attr.result) && (sym->ns != gfc_current_ns)) $10 = 0 and then next: (gdb) p sym->name $14 = 0x2aaaaab40ea0 "test" (gdb) p sym->ns->sym_root->name $15 = 0x2aaaaab40ea0 "test" (gdb) p gfc_current_ns->sym_root->name $16 = 0x2aaaaab40ea8 "test1" And hence: (gdb) p ((sym->result || sym->attr.result) && (sym->ns != gfc_current_ns)) $17 = 1 and finally: (gdb) p sym->name $26 = 0x2aaaaab40ea8 "test1" (gdb) p sym->ns->sym_root->name $27 = 0x2aaaaab40ea8 "test1" (gdb) p gfc_current_ns->sym_root->name $28 = 0x2aaaaab40ea0 "test" (gdb) p ((sym->result || sym->attr.result) && (sym->ns != gfc_current_ns)) $25 = 1 Seemingly, the ICE occurs unless both resolutions happen. (I wonder whether one could use {sym->ns,gfc_current_namespace}->resolved to decide whether one should continue or not; currently, one finds the values "-1" and "0".)