This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
[PATCH] Issue diagnostics when passing assumed-size array to assumed-shape argument
- From: Jakub Jelinek <jakub at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org, fortran at gcc dot gnu dot org
- Date: Fri, 21 Oct 2005 11:50:48 -0400
- Subject: [PATCH] Issue diagnostics when passing assumed-size array to assumed-shape argument
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
While playing with OpenMP variable length remapping, I have noticed
gfortran doesn't complain on the attached testcase.
I was worried what should I do if assumed-shape array is passed
assumed-size array and therefore it wouldn't have an upper bound.
While assumed-size arrays are forbidden in OpenMP private clauses,
assumed-shape arrays are not.
But the standard (in 12.4.1.1) explicitly forbids that:
"If a dummy argument is an assumed-shape array, the actual argument shall
not be an assumed-size array or a scalar (including an array element
designator or an array element substring designator)."
We already issue error for scalar passed to assumed-shape array
and this patch handles the rest.
Ok for HEAD?
2005-10-21 Jakub Jelinek <jakub@redhat.com>
* interface.c (compare_actual_formal): Issue error when attempting
to pass an assumed-size array as assumed-shape array argument.
* gfortran.dg/assumed_dummy_2.f90: New test.
--- gcc/fortran/interface.c.jj 2005-10-21 16:43:26.000000000 +0200
+++ gcc/fortran/interface.c 2005-10-21 17:23:29.000000000 +0200
@@ -1235,6 +1235,21 @@ compare_actual_formal (gfc_actual_arglis
return 0;
}
+ if (f->sym->as
+ && f->sym->as->type == AS_ASSUMED_SHAPE
+ && a->expr->expr_type == EXPR_VARIABLE
+ && a->expr->symtree->n.sym->as
+ && a->expr->symtree->n.sym->as->type == AS_ASSUMED_SIZE
+ && (a->expr->ref == NULL
+ || (a->expr->ref->type == REF_ARRAY
+ && a->expr->ref->u.ar.type == AR_FULL)))
+ {
+ if (where)
+ gfc_error ("Actual argument for '%s' cannot be an assumed-size"
+ " array at %L", f->sym->name, where);
+ return 0;
+ }
+
if (a->expr->expr_type != EXPR_NULL
&& compare_pointer (f->sym, a->expr) == 0)
{
--- gcc/testsuite/gfortran.dg/assumed_dummy_2.f90.jj 2005-10-21 16:48:01.000000000 +0200
+++ gcc/testsuite/gfortran.dg/assumed_dummy_2.f90 2005-10-21 16:50:57.000000000 +0200
@@ -0,0 +1,15 @@
+! { dg-do compile }
+
+ double precision :: arr(5, 8)
+ call bar (arr)
+contains
+ subroutine foo (arr)
+ double precision :: arr(:,:)
+ arr(3, 4) = 24
+ end subroutine foo
+ subroutine bar (arr)
+ double precision :: arr(5,*)
+ call foo (arr) ! { dg-error "cannot be an assumed-size array" }
+ call foo (arr (:, :8))
+ end subroutine
+end
Jakub