From 84cccff60a978174271a30042bf7841d2ae436eb Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Fri, 24 Sep 2021 19:10:15 +0200 Subject: Fortran - improve checking for intrinsics allowed in constant expressions gcc/fortran/ChangeLog: PR fortran/102458 * expr.c (is_non_constant_intrinsic): Check for intrinsics excluded in constant expressions (F2018:10.1.2). (gfc_is_constant_expr): Use that check. gcc/testsuite/ChangeLog: PR fortran/102458 * gfortran.dg/pr102458.f90: New test. --- gcc/fortran/expr.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'gcc/fortran/expr.c') diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c index 604e63e..5ad1c4f 100644 --- a/gcc/fortran/expr.c +++ b/gcc/fortran/expr.c @@ -990,6 +990,34 @@ done: } +/* Standard intrinsics listed under F2018:10.1.2 (6), which are excluded in + constant expressions, except TRANSFER (c.f. item (8)), which would need + separate treatment. */ + +static bool +is_non_constant_intrinsic (gfc_expr *e) +{ + if (e->expr_type == EXPR_FUNCTION + && e->value.function.isym) + { + switch (e->value.function.isym->id) + { + case GFC_ISYM_COMMAND_ARGUMENT_COUNT: + case GFC_ISYM_GET_TEAM: + case GFC_ISYM_NULL: + case GFC_ISYM_NUM_IMAGES: + case GFC_ISYM_TEAM_NUMBER: + case GFC_ISYM_THIS_IMAGE: + return true; + + default: + return false; + } + } + return false; +} + + /* Determine if an expression is constant in the sense of F08:7.1.12. * This function expects that the expression has already been simplified. */ @@ -1023,6 +1051,10 @@ gfc_is_constant_expr (gfc_expr *e) gcc_assert (e->symtree || e->value.function.esym || e->value.function.isym); + /* Check for intrinsics excluded in constant expressions. */ + if (e->value.function.isym && is_non_constant_intrinsic (e)) + return false; + /* Call to intrinsic with at least one argument. */ if (e->value.function.isym && e->value.function.actual) { -- cgit v1.1 From 8a0861ef29521e90293bd0236d2bb30b71a4970e Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Thu, 30 Sep 2021 20:28:39 +0200 Subject: Fortran: fix reference to Fortran standard in comment gcc/fortran/ * expr.c: The correct reference to Fortran standard is: F2018:10.1.12. --- gcc/fortran/expr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gcc/fortran/expr.c') diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c index 5ad1c4f..6c38935 100644 --- a/gcc/fortran/expr.c +++ b/gcc/fortran/expr.c @@ -990,7 +990,7 @@ done: } -/* Standard intrinsics listed under F2018:10.1.2 (6), which are excluded in +/* Standard intrinsics listed under F2018:10.1.12 (6), which are excluded in constant expressions, except TRANSFER (c.f. item (8)), which would need separate treatment. */ -- cgit v1.1