https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82243
Bug ID: 82243 Summary: -fcheck=bounds not checking, and behaving differently with different real kinds Product: gcc Version: 6.3.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: john.harper at vuw dot ac.nz Target Milestone: --- -fcheck=bounds doesn't complain if LHS and RHS of real array assignments in a subroutine are different shapes. Gfortran's behaviour depends on kind(s). ! array section assigned to array constructor of wrong shape in subroutine. ! Run-time abort if mp = kind(1d0) but no error message if mp = kind(1.0) ! Should gfortran -fcheck=bounds pick up the error? module globals implicit none integer,parameter:: mp = kind(1d0) contains subroutine finds( n,s) integer,intent(in)::n real(mp),intent(out)::s(0:) real(mp),dimension(0:n/2+1):: even integer:: i even = 1.0_mp s(0) = even(1) s(2:n-1:2) = [(even(i),i=1,n/2)] print *,'Sizes: LHS',size(s(2:n-1:2)),'RHS',size(even(1:n/2)) end subroutine finds end module globals program gfbug3 use globals, only: mp,finds implicit none integer:: n = 40 real(mp),allocatable:: s(:) allocate(s(0:n)) print *,merge('Single','Double',mp==kind(1.0))//' precision' call finds(n,s) print "(20F3.0)",s(0::2) end program gfbug3 The output did reveal the offending line: cayley[~/Jfh] % gfortran -g -fcheck=bounds gfbug3.f90 cayley[~/Jfh] % ./a.out Double precision *** Error in `./a.out': double free or corruption (!prev): 0x00000000012fb170 *** ======= Backtrace: ========= /usr/lib/libc.so.6(+0x70c4b)[0x7f1e39b76c4b] /usr/lib/libc.so.6(+0x76fe6)[0x7f1e39b7cfe6] /usr/lib/libc.so.6(+0x777de)[0x7f1e39b7d7de] ./a.out[0x400e13] ./a.out[0x401365] ./a.out[0x4015f9] /usr/lib/libc.so.6(__libc_start_main+0xf1)[0x7f1e39b26291] ./a.out[0x40088a] ======= Memory map: ======== 00400000-00402000 r-xp 00000000 00:2b 11619110 /am/roxy/home/harper/Jfh/a.out 00601000-00602000 r--p 00001000 00:2b 11619110 /am/roxy/home/harper/Jfh/a.out 00602000-00603000 rw-p 00002000 00:2b 11619110 /am/roxy/home/harper/Jfh/a.out 012f8000-01319000 rw-p 00000000 00:00 0 [heap] 7f1e34000000-7f1e34021000 rw-p 00000000 00:00 0 7f1e34021000-7f1e38000000 ---p 00000000 00:00 0 7f1e39b06000-7f1e39c9b000 r-xp 00000000 08:03 1221622 /usr/lib/libc-2.24.so 7f1e39c9b000-7f1e39e9a000 ---p 00195000 08:03 1221622 /usr/lib/libc-2.24.so 7f1e39e9a000-7f1e39e9e000 r--p 00194000 08:03 1221622 /usr/lib/libc-2.24.so 7f1e39e9e000-7f1e39ea0000 rw-p 00198000 08:03 1221622 /usr/lib/libc-2.24.so 7f1e39ea0000-7f1e39ea4000 rw-p 00000000 00:00 0 7f1e39ea4000-7f1e39ee3000 r-xp 00000000 08:03 1222012 /usr/lib/libquadmath.so.0.0.0 7f1e39ee3000-7f1e3a0e2000 ---p 0003f000 08:03 1222012 /usr/lib/libquadmath.so.0.0.0 7f1e3a0e2000-7f1e3a0e3000 r--p 0003e000 08:03 1222012 /usr/lib/libquadmath.so.0.0.0 7f1e3a0e3000-7f1e3a0e4000 rw-p 0003f000 08:03 1222012 /usr/lib/libquadmath.so.0.0.0 7f1e3a0e4000-7f1e3a0fa000 r-xp 00000000 08:03 1221717 /usr/lib/libgcc_s.so.1 7f1e3a0fa000-7f1e3a2f9000 ---p 00016000 08:03 1221717 /usr/lib/libgcc_s.so.1 7f1e3a2f9000-7f1e3a2fa000 r--p 00015000 08:03 1221717 /usr/lib/libgcc_s.so.1 7f1e3a2fa000-7f1e3a2fb000 rw-p 00016000 08:03 1221717 /usr/lib/libgcc_s.so.1 7f1e3a2fb000-7f1e3a3fe000 r-xp 00000000 08:03 1221842 /usr/lib/libm-2.24.so 7f1e3a3fe000-7f1e3a5fd000 ---p 00103000 08:03 1221842 /usr/lib/libm-2.24.so 7f1e3a5fd000-7f1e3a5fe000 r--p 00102000 08:03 1221842 /usr/lib/libm-2.24.so 7f1e3a5fe000-7f1e3a5ff000 rw-p 00103000 08:03 1221842 /usr/lib/libm-2.24.so 7f1e3a5ff000-7f1e3a72d000 r-xp 00000000 08:03 1221728 /usr/lib/libgfortran.so.3.0.0 7f1e3a72d000-7f1e3a92d000 ---p 0012e000 08:03 1221728 /usr/lib/libgfortran.so.3.0.0 7f1e3a92d000-7f1e3a92e000 r--p 0012e000 08:03 1221728 /usr/lib/libgfortran.so.3.0.0 7f1e3a92e000-7f1e3a930000 rw-p 0012f000 08:03 1221728 /usr/lib/libgfortran.so.3.0.0 7f1e3a930000-7f1e3a953000 r-xp 00000000 08:03 1221559 /usr/lib/ld-2.24.so 7f1e3ab30000-7f1e3ab34000 rw-p 00000000 00:00 0 7f1e3ab51000-7f1e3ab52000 rw-p 00000000 00:00 0 7f1e3ab52000-7f1e3ab53000 r--p 00022000 08:03 1221559 /usr/lib/ld-2.24.so 7f1e3ab53000-7f1e3ab54000 rw-p 00023000 08:03 1221559 /usr/lib/ld-2.24.so 7f1e3ab54000-7f1e3ab55000 rw-p 00000000 00:00 0 7ffd0abcc000-7ffd0abed000 rw-p 00000000 00:00 0 [stack] 7ffd0abf2000-7ffd0abf4000 r--p 00000000 00:00 0 [vvar] 7ffd0abf4000-7ffd0abf6000 r-xp 00000000 00:00 0 [vdso] ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall] Program received signal SIGABRT: Process abort signal. Backtrace for this error: #0 0x7f1e39b390af in ??? #1 0x7f1e39b3904f in ??? #2 0x7f1e39b3a479 in ??? #3 0x7f1e39b76c4f in ??? #4 0x7f1e39b7cfe5 in ??? #5 0x7f1e39b7d7dd in ??? #6 0x400e12 in __globals_MOD_finds at /home/harper/Jfh/gfbug3.f90:15 #7 0x401364 in gfbug3 at /home/harper/Jfh/gfbug3.f90:27 #8 0x4015f8 in main at /home/harper/Jfh/gfbug3.f90:21 Abort