From 1a3920654f92b83a206d62f4eddcf1f5c28a91de Mon Sep 17 00:00:00 2001 From: "Steven G. Kargl" Date: Tue, 6 Aug 2019 19:46:29 +0000 Subject: re PR fortran/42546 (ALLOCATED statement typo in the docs and for scalar variables) 2019-08-01 Steven G. Kargl PR fortran/42546 * check.c(gfc_check_allocated): Add comment pointing to ... * intrinsic.c(sort_actual): ... the checking done here. 2019-08-01 Steven G. Kargl PR fortran/42546 * gfortran.dg/allocated_1.f90: New test. * gfortran.dg/allocated_2.f90: Ditto. From-SVN: r274147 --- gcc/fortran/ChangeLog | 6 ++++++ gcc/fortran/check.c | 4 ++++ gcc/fortran/intrinsic.c | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) (limited to 'gcc/fortran') diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 9835cbb..b88437a 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2019-08-06 Steven G. Kargl + + PR fortran/42546 + * check.c(gfc_check_allocated): Add comment pointing to ... + * intrinsic.c(sort_actual): ... the checking done here. + 2019-08-05 Steven g. Kargl PR fortran/91372 diff --git a/gcc/fortran/check.c b/gcc/fortran/check.c index 0204961..370a3c8 100644 --- a/gcc/fortran/check.c +++ b/gcc/fortran/check.c @@ -1340,6 +1340,10 @@ gfc_check_all_any (gfc_expr *mask, gfc_expr *dim) } +/* Limited checking for ALLOCATED intrinsic. Additional checking + is performed in intrinsic.c(sort_actual), because ALLOCATED + has two mutually exclusive non-optional arguments. */ + bool gfc_check_allocated (gfc_expr *array) { diff --git a/gcc/fortran/intrinsic.c b/gcc/fortran/intrinsic.c index c21fbdd..d0f7c10 100644 --- a/gcc/fortran/intrinsic.c +++ b/gcc/fortran/intrinsic.c @@ -4180,6 +4180,40 @@ sort_actual (const char *name, gfc_actual_arglist **ap, if (f == NULL && a == NULL) /* No arguments */ return true; + /* ALLOCATED has two mutually exclusive keywords, but only one + can be present at time and neither is optional. */ + if (strcmp (name, "allocated") == 0 && a->name) + { + if (strcmp (a->name, "scalar") == 0) + { + if (a->next) + goto whoops; + if (a->expr->rank != 0) + { + gfc_error ("Scalar entity required at %L", &a->expr->where); + return false; + } + return true; + } + else if (strcmp (a->name, "array") == 0) + { + if (a->next) + goto whoops; + if (a->expr->rank == 0) + { + gfc_error ("Array entity required at %L", &a->expr->where); + return false; + } + return true; + } + else + { + gfc_error ("Invalid keyword %qs in %qs intrinsic function at %L", + a->name, name, &a->expr->where); + return false; + } + } + for (;;) { /* Put the nonkeyword arguments in a 1:1 correspondence */ if (f == NULL) @@ -4199,6 +4233,7 @@ sort_actual (const char *name, gfc_actual_arglist **ap, if (a == NULL) goto do_sort; +whoops: gfc_error ("Too many arguments in call to %qs at %L", name, where); return false; -- cgit v1.1