The issue raised in PR fortran/61775 seemed to be fixed. I've read the tree dump for -fdump-tree-optimized, and gfortran seems to be generating the expected code. Valgrind also finishes without errors. I committed to code as a testcase.
2018-03-13 Steven G. Kargl <ka...@gcc.gnu.org> PR fortran/61775 * gfortran.dg/pr61775.f90: New test. -- Steve