This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug fortran/67422] memcpy incorrectly used to copy (potentially) overlapping assumed-size arrays


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]