https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84506
--- Comment #7 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> --- The problem is not related to the newunit functions or neunit alloc stuff. In the call to st_inquire we are passing the correct value of -10 for the unit number. However, the dump-original we have: { struct __st_parameter_inquire inquire_parm.3; integer(kind=8) D.3772; inquire_parm.3.common.filename = &"pr84506.f90"[1]{lb: 1 sz: 1}; inquire_parm.3.common.line = 7; inquire_parm.3.strm_pos_out = &ipos; inquire_parm.3.common.flags = 8192; inquire_parm.3.common.unit = (integer(kind=4)) iunit; D.3772 = iunit; if (D.3772 < 0 || D.3772 > 2147483647) { inquire_parm.3.common.unit = -3; } _gfortran_st_inquire (&inquire_parm.3); } The test is checking the range to be within a kind=4 integer limits and we are passing -3 to the inquire statement. The correct unit number is -10 as provided by newunit. (gdb) r Starting program: /home/jerry/dev/test/pr84506/a.out Breakpoint 1, testinquire () at pr84506.f90:7 7 inquire(iUnit, pos=iPos) (gdb) p iUnit $2 = -10 (gdb) s _gfortran_st_inquire (iqp=0x7fffffffd930) at ../../../trunk/libgfortran/io/inquire.c:775 775 library_start (&iqp->common); (gdb) p iqp->common.unit $3 = -3