This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/67422] memcpy incorrectly used to copy (potentially) overlapping assumed-size arrays
- From: "kargl at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 01 Sep 2015 14:11:48 +0000
- Subject: [Bug fortran/67422] memcpy incorrectly used to copy (potentially) overlapping assumed-size arrays
- Auto-submitted: auto-generated
- References: <bug-67422-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67422
kargl at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |kargl at gcc dot gnu.org
Resolution|INVALID |FIXED
--- Comment #3 from kargl at gcc dot gnu.org ---
(In reply to Boris Carlsson from comment #0)
> The assembler code implementation for
>
> subroutine move_buggy(a, b, n)
> integer :: n, i
> integer, dimension(*) :: a, b
> do i = 1, n
> a(i) = b(i)
> end do
> end subroutine move_buggy
>
> generated with
>
> gfortran -S move_buggy.f90 -O3
>
> or more "condensed" with
>
> gfortran -S move_buggy.f90 -O1 -ftree-loop-distribute-patterns
> -foptimize-sibling-calls -fstrict-overflow
>
> will replace the loop with a call to memcpy. memcpy is not guaranteed to
> work if the memory locations for a and b overlap, which could be the case
> here. Thus, the above code will not execute as expected (depending on the
> implementation of memcpy) when these optimizations are used. Thus, memcpy
> should not be used here.
>
> The bug is present in gfortran 5.2.1 and 4.9.3 (details below) but NOT in
> 4.7.2.
>
The memory locations for a and b cannot overlap in standard conforming
code. This restriction goes back to at least Fortran 77, and it is a
restriction on the programmer not the compiler.