http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57096
--- Comment #3 from janus at gcc dot gnu.org 2013-04-28 13:19:03 UTC --- The simplest test case I found contains two files: ModA.f03: --------- module ModA implicit none integer, allocatable :: gA end module ModA test.f03: --------- subroutine init() use moda implicit none print *,ga end subroutine To trigger the bug, they need to be compiled with: gfortran -std=f2003 -c ModA.f03 gfortran -fdump-tree-original -c test.f03 The "-std=f2003" is required to reproduce, and also two separate files (though I'm not sure why). One then gets the following dump: init () { extern integer(kind=4) * ga; try { ga = 0B; { struct __st_parameter_dt dt_parm.0; dt_parm.0.common.filename = &"test.f03"[1]{lb: 1 sz: 1}; dt_parm.0.common.line = 5; dt_parm.0.common.flags = 128; dt_parm.0.common.unit = 6; _gfortran_st_write (&dt_parm.0); _gfortran_transfer_integer_write (&dt_parm.0, ga, 4); _gfortran_st_write_done (&dt_parm.0); } } finally { if (ga != 0B) { __builtin_free ((void *) ga); } } } which shows that 'gA' is both nullified at the beginning and deallocated at the end. Same behavior with 4.7, 4.8 and trunk. Removing the -std=f2003 or putting the module into the same file as the subroutine makes the auto-deallocation (and nullification) go away. Puzzling. The patch in comment 2 fixes it and regtests cleanly.