Dear all,
The attached patch fixes an ICE in gfc_resolve_code when passing an
optional array to an elemental procedure with `-pedantic` enabled.
PR95446 added the original check, this patch fixes the case where the
other actual argument is an array literal (or something else other
than a variable). The ICE is present since 11.1, so this could be
backported?
Cheers,
Peter
gcc/fortran/Changelog
* resolve.cc (resolve_elemental_actual): When checking other
actual arguments to elemental procedures, don't check
attributes of literals and function calls
gcc/testsuite/Changelog
* gfortran.dg/pr95446.f90: Expand test case to literals and
function calls
Signed-off-by: Peter Hill <[email protected]>
---
gcc/fortran/resolve.cc | 4 +++-
gcc/testsuite/gfortran.dg/pr95446.f90 | 14 ++++++++++++++
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index 6a83a7967a8..bf602389d5b 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -2429,7 +2429,9 @@ resolve_elemental_actual (gfc_expr *expr, gfc_code *c)
for (a = arg0; a; a = a->next)
if (a != arg
&& a->expr->rank == arg->expr->rank
- && !a->expr->symtree->n.sym->attr.optional)
+ && (a->expr->expr_type != EXPR_VARIABLE
+ || (a->expr->expr_type == EXPR_VARIABLE
+ && !a->expr->symtree->n.sym->attr.optional)))
{
t = true;
break;
diff --git a/gcc/testsuite/gfortran.dg/pr95446.f90
b/gcc/testsuite/gfortran.dg/pr95446.f90
index 86e1019d7af..0787658813a 100644
--- a/gcc/testsuite/gfortran.dg/pr95446.f90
+++ b/gcc/testsuite/gfortran.dg/pr95446.f90
@@ -22,6 +22,20 @@ program elemental_optional
end function outer
+ function outer_literal(o) result(l)
+ integer, intent(in), optional :: o(5)
+ integer :: l(5)
+
+ l = inner(o, [1,2,3,4,5])
+ end function outer_literal
+
+ function outer_func(o) result(l)
+ integer, intent(in), optional :: o(5)
+ integer :: l(5)
+
+ l = inner(o, outer())
+ end function outer_func
+
elemental function inner(a,b) result(x)
integer, intent(in), optional :: a
integer, intent(in) :: b
--
2.48.1