[patch, fortran] Fix wrong-code regression with netcdf and SPEC due to argument repacking
Thomas Koenig
tkoenig@netcologne.de
Wed May 29 11:16:00 GMT 2019
Hello world,
the attached patch fixes the wrong-code regression due to the
inline argument repacking patch, r271377.
What had gone wrong? gfortran used to pack and unpack arrays
unconditionally passed to old-style assumed size or . For code like
module t2
implicit none
contains
subroutine foo(a)
real, dimension(*) :: a
end subroutine foo
end module t2
module t1
use t2
implicit none
contains
subroutine bar(a)
real, dimension(:) :: a
call foo(a)
end subroutine bar
end module t1
program main
use t1
call bar([1.0, 2.0])
end program main
this meant that an (always contiguous) array constructor was
passed down to an assumed shape array, which then passed it
on to an assumed size, explicit shape or adjustable array.
Packing was not problematic (apart from performance), but
unpacking tried to write into the array constructor.
So, this patch inserts a run-time check for contiguous arrays
and does not do packing/unpacking in that case.
Thanks to Toon and Martin for finding an open test case which
actually failed, and for help with debugging.
(Always repacking also likely impacted performance when it didn't
lead to wrong code, we will have to see how performance is with
this version).
OK for trunk?
Regards
Thomas
2019-05-29 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/90539
* gfortran.h (gfc_has_dimen_vector_ref): Add prototype.
* trans.h (gfc_conv_subref_array_arg): Add argument check_contiguous.
(gfc_conv_is_contiguous_expr): Add prototype.
* frontend-passes.c (has_dimen_vector_ref): Remove prototype,
rename to
(gfc_has_dimen_vector_ref): New function name.
(matmul_temp_args): Use gfc_has_dimen_vector_ref.
(inline_matmul_assign): Likewise.
* trans-array.c (gfc_conv_array_parameter): Also check for absence
of a vector subscript before calling gfc_conv_subref_array_arg.
Pass additional argument to gfc_conv_subref_array_arg.
* trans-expr.c (gfc_conv_subref_array_arg): Add argument
check_contiguous. If that is true, check if the argument
is contiguous and do not repack in that case.
* trans-intrinsic.c (gfc_conv_intrinsic_is_contiguous): Split
away most of the work into, and call
(gfc_conv_intrinsic_is_coniguous_expr): New function.
2019-05-29 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/90539
* gfortran.dg/internal_pack_21.f90: Adjust scan patterns.
* gfortran.dg/internal_pack_22.f90: New test.
* gfortran.dg/internal_pack_23.f90: New test.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: p4b.diff
Type: text/x-patch
Size: 11730 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20190529/d759305a/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: internal_pack_23.f90
Type: text/x-fortran
Size: 480 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20190529/d759305a/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: internal_pack_22.f90
Type: text/x-fortran
Size: 884 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20190529/d759305a/attachment-0002.bin>
More information about the Fortran
mailing list