From 8e1be7efcb1c68dd82e2b2c1bcf3e5ace245654d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Rui=20Faustino=20de=20Sousa?= Date: Sun, 30 Aug 2020 17:28:08 +0000 Subject: [PATCH] =?utf8?q?=092020-8-20=20=20Jos=C3=A9=20Rui=20Faustino=20d?= =?utf8?q?e=20Sousa=20=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit gcc/fortran/ChangeLog: PR fortran/94110 * interface.c (gfc_compare_actual_formal): Add code to also raise the actual argument cannot be an assumed-size array error when the dummy arguments are deferred-shape or assumed-rank pointer. gcc/testsuite/ChangeLog: PR fortran/94110 * gfortran.dg/PR94110.f90: New test. --- gcc/fortran/interface.c | 5 +- gcc/testsuite/gfortran.dg/PR94110.f90 | 88 +++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/PR94110.f90 diff --git a/gcc/fortran/interface.c b/gcc/fortran/interface.c index 7985fc70fd4..020cdd73df8 100644 --- a/gcc/fortran/interface.c +++ b/gcc/fortran/interface.c @@ -3303,7 +3303,10 @@ gfc_compare_actual_formal (gfc_actual_arglist **ap, gfc_formal_arglist *formal, return false; } - if (f->sym->as && f->sym->as->type == AS_ASSUMED_SHAPE + if (f->sym->as + && (f->sym->as->type == AS_ASSUMED_SHAPE + || f->sym->as->type == AS_DEFERRED + || (f->sym->as->type == AS_ASSUMED_RANK && f->sym->attr.pointer)) && a->expr->expr_type == EXPR_VARIABLE && a->expr->symtree->n.sym->as && a->expr->symtree->n.sym->as->type == AS_ASSUMED_SIZE diff --git a/gcc/testsuite/gfortran.dg/PR94110.f90 b/gcc/testsuite/gfortran.dg/PR94110.f90 new file mode 100644 index 00000000000..9ec70ec857e --- /dev/null +++ b/gcc/testsuite/gfortran.dg/PR94110.f90 @@ -0,0 +1,88 @@ +! { dg-do compile } +! +! Test the fix for PR94110 +! + +program asa_p + + implicit none + + integer, parameter :: n = 7 + + integer :: p(n) + integer :: s + + p = 1 + s = sumf_as(p) + if (s/=n) stop 1 + s = sumf_ar(p) + if (s/=n) stop 2 + stop + +contains + + function sumf_as(a) result(s) + integer, target, intent(in) :: a(*) + + integer :: s + + s = sum_as(a) ! { dg-error "Actual argument for .a. cannot be an assumed-size array" } + s = sum_p_ds(a) ! { dg-error "Actual argument for .a. cannot be an assumed-size array" } + s = sum_p_ar(a) ! { dg-error "Actual argument for .a. cannot be an assumed-size array" } + return + end function sumf_as + + function sumf_ar(a) result(s) + integer, target, intent(in) :: a(..) + + integer :: s + + select rank(a) + rank(*) + s = sum_as(a) ! { dg-error "Actual argument for .a. cannot be an assumed-size array" } + s = sum_p_ds(a) ! { dg-error "Actual argument for .a. cannot be an assumed-size array" } + s = sum_p_ar(a) ! { dg-error "Actual argument for .a. cannot be an assumed-size array" } + rank default + stop 3 + end select + return + end function sumf_ar + + function sum_as(a) result(s) + integer, intent(in) :: a(:) + + integer :: s + + s = sum(a) + return + end function sum_as + + function sum_p_ds(a) result(s) + integer, pointer, intent(in) :: a(:) + + integer :: s + + s = -1 + if(associated(a))& + s = sum(a) + return + end function sum_p_ds + + function sum_p_ar(a) result(s) + integer, pointer, intent(in) :: a(..) + + integer :: s + + s = -1 + select rank(a) + rank(1) + if(associated(a))& + s = sum(a) + rank default + stop 4 + end select + return + end function sum_p_ar + +end program asa_p + -- 2.30.2