https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92569
--- Comment #3 from Bill Lipa <dojo at masterleep dot com> --- Thanks for looking at it. I studied it further and it seems that -O2 is the culprit. Could you please try to reproduce with -O2? $ gfortran -O2 res.f $ ./a.out At line 8 of file res.f (unit = 1, file = 'resultav4.dat') Fortran runtime error: Read past ENDFILE record Error termination. Backtrace: #0 0x10221ea14 #1 0x10221f2c2 #2 0x10221fbca #3 0x10234fe06 #4 0x102349a14 #5 0x10234b673 #6 0x10234bf75 #7 0x10234fa6c #8 0x10234fb69 #9 0x102202cb0 #10 0x102202dde $ gfortran res.f $ ./a.out # data records = 3