http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47839
Richard Guenther <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Last reconfirmed| |2011.02.21 17:04:46 Ever Confirmed|0 |1 --- Comment #2 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-02-21 17:04:46 UTC --- We merge the decls during symtab merging. The prevailing one looks for example like (gdb) call debug_tree (prevailing->decl) <var_decl 0x7ffff5b3b0a0 zstart type <integer_type 0x7ffff7ee3498 int public SI size <integer_cst 0x7ffff7ed36e0 constant 32> unit size <integer_cst 0x7ffff7ed33e8 constant 4> align 32 symtab 0 alias set -1 canonical type 0x7ffff7ee3498 precision 32 min <integer_cst 0x7ffff7ed3668 -2147483648> max <integer_cst 0x7ffff7ed3690 2147483647> pointer_to_this <pointer_type 0x7ffff7ef03f0>> used public static SI file mod.f90 line 2 col 0 size <integer_cst 0x7ffff7ed36e0 32> unit size <integer_cst 0x7ffff7ed33e8 4> align 32 context <namespace_decl 0x7ffff5b31678 globalvar_mod>> while the non-prevailing one is <var_decl 0x7ffff5b3b640 zstart type <integer_type 0x7ffff7ee3498 int public SI size <integer_cst 0x7ffff7ed36e0 constant 32> unit size <integer_cst 0x7ffff7ed33e8 constant 4> align 32 symtab 0 alias set -1 canonical type 0x7ffff7ee3498 precision 32 min <integer_cst 0x7ffff7ed3668 -2147483648> max <integer_cst 0x7ffff7ed3690 2147483647> pointer_to_this <pointer_type 0x7ffff7ef03f0>> used public ignored external SI file t.f90 line 4 col 0 size <integer_cst 0x7ffff7ed36e0 32> unit size <integer_cst 0x7ffff7ed33e8 4> align 32> note that it is public and external and has a NULL DECL_CONTEXT. The C frontend for a local extern declaration has <var_decl 0x7ffff5b481e0 i type <integer_type 0x7ffff7ee6498 int public SI size <integer_cst 0x7ffff7ed36e0 constant 32> unit size <integer_cst 0x7ffff7ed33e8 constant 4> align 32 symtab 0 alias set -1 canonical type 0x7ffff7ee6498 precision 32 min <integer_cst 0x7ffff7ed3668 -2147483648> max <integer_cst 0x7ffff7ed3690 2147483647> pointer_to_this <pointer_type 0x7ffff7ef7540>> used public external common SI defer-output file t.c line 8 col 15 size <integer_cst 0x7ffff7ed36e0 32> unit size <integer_cst 0x7ffff7ed33e8 4> align 32 context <function_decl 0x7ffff5b49000 foo>> thus puts it into function context. This decl is solely used for the BLOCK tree, in the function a public external global var is used (which is then merged with the static one from the other TU). void foo (void) { extern int i; i = 0; } --- int i; Simplified Fortran testcase: MODULE globalvar_mod integer :: xstop CONTAINS END MODULE globalvar_mod --- MODULE PEC_mod CONTAINS SUBROUTINE PECapply(Ex) USE globalvar_mod, ONLY : xstop real(kind=8), dimension(1:xstop), intent(inout) :: Ex END SUBROUTINE PECapply END MODULE PEC_mod it's important that PECapply is inside a module. The decl is built by gfc_get_symbol_decl and put into the function via gfc_add_decl_to_function - which is I think in general bogus for imported decls. Its context is later cleared in pushdecl, but the variable isn't removed from BLOCK_VARS. I think we want to avoid gfc_add_decl_to_function in the first place.