The testcase in gcc/testsuite/gfortran.dg/poly_run_2.f90 gives explicit cobounds for the argument A to procedure s(). Those are not taken into account, at least not in the way given (excerpt): type t end type t class(t), allocatable :: A[:,:] allocate (A[1:4,-5:*]) call s(A) contains subroutine s(x) class(t) :: x[4,2:*] if (any (lcobound(x) /= [1, 2])) call abort () if (num_images() == 1) then if (any (ucobound(x) /= [4, 2])) call abort () ! Fails else if (ucobound(x,dim=1) /= 4) call abort () end if end subroutine s end Note: The testcase in general is made non-functional by the if(allocated(A)) stop as second line, as it is living in trunk upto r242691.
Confirmed from 4.9 up to trunk (7.0) when compiled with -fcoarray=lib -lcaf_single ("works" with -fcoarray=single). When compiled with 4.8, I get at run time a lot of ... Program received signal SIGABRT: Process abort signal. Backtrace for this error: Program received signal SIGABRT: Process abort signal. Backtrace for this error: ... Program received signal SIGABRT: Process abort signal. Backtrace for this error: Segmentation fault
Another issue I noticed is that with -O2 the code allocate (A[1:4,-5:*]) if (.not. allocated(A)) error stop stops instead of continuing like it does with all other levels of optimization.
Patch proposed in https://gcc.gnu.org/pipermail/fortran/2024-July/060646.html . Waiting for review.
The master branch has been updated by Andre Vehreschild <vehre@gcc.gnu.org>: https://gcc.gnu.org/g:18f3b223b97011c2eab71c8e48c3a38a12ff8f65 commit r15-2137-g18f3b223b97011c2eab71c8e48c3a38a12ff8f65 Author: Andre Vehreschild <vehre@gcc.gnu.org> Date: Thu Dec 31 10:40:30 2020 +0100 Fortran: Fix Explicit cobounds of a procedures parameter not respected [PR78466] Explicit cobounds of class array procedure parameters were not taken into account. Furthermore were different cobounds in distinct procedure parameter lists mixed up, i.e. the last definition was taken for all. The bounds are now regenerated when tree's and expr's bounds do not match. PR fortran/78466 PR fortran/80774 gcc/fortran/ChangeLog: * array.cc (gfc_compare_array_spec): Take cotype into account. * class.cc (gfc_build_class_symbol): Coarrays are also arrays. * gfortran.h (IS_CLASS_COARRAY_OR_ARRAY): New macro to detect regular and coarray class arrays. * interface.cc (compare_components): Take codimension into account. * resolve.cc (resolve_symbol): Improve error message. * simplify.cc (simplify_bound_dim): Remove duplicate. * trans-array.cc (gfc_trans_array_cobounds): Coarrays are also arrays. (gfc_trans_array_bounds): Same. (gfc_trans_dummy_array_bias): Same. (get_coarray_as): Get the as having a non-zero codim. (is_explicit_coarray): Detect explicit coarrays. (gfc_conv_expr_descriptor): Create a new descriptor for explicit coarrays. * trans-decl.cc (gfc_build_qualified_array): Coarrays are also arrays. (gfc_build_dummy_array_decl): Same. (gfc_get_symbol_decl): Same. (gfc_trans_deferred_vars): Same. * trans-expr.cc (class_scalar_coarray_to_class): Get the descriptor from the correct location. (gfc_conv_variable): Pick up the descriptor when needed. * trans-types.cc (gfc_is_nodesc_array): Coarrays are also arrays. (gfc_get_nodesc_array_type): Indentation fix only. (cobounds_match_decl): Match a tree's bounds to the expr's bounds and return true, when they match. (gfc_get_derived_type): Create a new type tree/descriptor, when the cobounds of the existing declaration and expr to not match. This happends for class arrays in parameter list, when there are different cobound declarations. gcc/testsuite/ChangeLog: * gfortran.dg/coarray/poly_run_1.f90: Activate old test code. * gfortran.dg/coarray/poly_run_2.f90: Activate test. It was stopping before and passing without an error.