https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117791
--- Comment #6 from anlauf at gcc dot gnu.org --- Furthermore, replacing the line write(*,*) 'line 4:',array(:, sort_2(i(1:2)) ) by an expression with explicit parentheses around the array argument write(*,*) 'line 4:',(array(:, sort_2(i(1:2)) )) fixes the problem. I suspect the optimization for array-I/O is interfering with bounds-checking.