$ cat bounds-check.f90 program main integer, parameter :: n=10 integer :: m,i integer a(n), b(n) call foo(a,m) do i=1,m b(i) = a(i)*a(i) end do print *,b(1:m) end program main
subroutine foo(a) integer a(10) a = 2 m = 12 end subroutine foo $ gfortran -fbounds-check -fdump-tree-optimized -O2 -S bounds-check.f90 gets me (from the .t71.optimized file): bb 0>: foo (&a, &m); D.474 = m; if (D.474 > 0) goto <L38>; else goto <L10>; <L38>:; ivtmp.19 = 0; <L0>:; if (__builtin_expect (ivtmp.19 > 9, 0) != 0) goto <L2>; else goto <L7>; <L2>:; _gfortran_runtime_error ("Array reference out of bounds", "bounds-check.f90", 5); _gfortran_runtime_error ("Array reference out of bounds", "bounds-check.f90", 5); _gfortran_runtime_error ("Array reference out of bounds", "bounds-check.f90", 5); <L7>:; D.499 = *&a[ivtmp.19]; *&b[ivtmp.19] = D.499 * D.499; ivtmp.19 = ivtmp.19 + 1; if ((<unnamed type>) D.474 == ivtmp.19) goto <L10>; else goto <L0>; which is still present in the assembly code: .L16: movl $5, %ecx movl $.LC0, %edx movl %ecx, 8(%esp) movl %edx, 4(%esp) movl $.LC1, (%esp) call _gfortran_runtime_error movl $5, %eax movl %eax, 8(%esp) movl $.LC0, %eax movl %eax, 4(%esp) movl $.LC1, (%esp) call _gfortran_runtime_error movl $5, %eax movl %eax, 8(%esp) movl $.LC0, %eax movl %eax, 4(%esp) movl $.LC1, (%esp) call _gfortran_runtime_error jmp .L5 Maybe it would help if _gfortran_runtime_error was marked as non-returning. -- Summary: Triple call to _gfortran_runtime_error with -fbounds- check Product: gcc Version: 4.1.0 Status: UNCONFIRMED Severity: enhancement Priority: P2 Component: fortran AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: tkoenig at gcc dot gnu dot org CC: gcc-bugs at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21027