[FORTRAN PATCH] Consider suitable derived types copyable
Roger Sayle
roger@eyesopen.com
Thu Jan 18 02:49:00 GMT 2007
The following patch implements an extension/enhancement of my original
__buitin_memcpy patch that was suggested/recommended by Paul Thomas. This
extends the set of types considered "copyable" with memcpy to additionally
include user derived types that don't contain allocatable components.
This allows us to use memcpy in the following testcase.
type t
logical valid
integer :: x, y
end type
type (t) :: s(5)
type (t) :: d(5)
d(:) = s(:)
The trick is to use the same logic as in gfc_trans_scalar_assign, and
check the ts.derived->alloc_comp field, which indicates whether the type
contains any allocatable fields that require special handling. Presumably,
the front-end sets this field correctly for derived types containing
derived types, otherwise both the existing gfc_trans_scalar_assign and the
new code below contain potential bugs. Likewise, for derived types
containing character fields.
Presuming that the existing code is sound, the patch below simply tweaks
the recent copyable_array_p predicate to also handle BT_DERIVED.
Tested on x86_64-unknown-linux-gnu with a full "make bootstrap", including
gfortran, and regression tested with a top-level "make -k check" with no
new failures.
Ok for mainline?
2007-01-17 Roger Sayle <roger@eyesopen.com>
* trans-expr.c (copyable_array_p): Consider user derived type
without allocatable components to be copyable.
* gfortran.dg/array_memcpy_4.f90: New test case.
Roger
--
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: patchf4.txt
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20070118/277a3723/attachment.txt>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: array_memcpy_4.f90
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20070118/277a3723/attachment.f90>
More information about the Fortran
mailing list