]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: Fix ICE in resolve.cc with -pedantic
authorJerry DeLisle <jvdelisle@gcc.gnu.org>
Sat, 8 Mar 2025 02:33:29 +0000 (18:33 -0800)
committerJerry DeLisle <jvdelisle@gcc.gnu.org>
Sun, 9 Mar 2025 18:36:10 +0000 (11:36 -0700)
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).

PR fortran/119054

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 <peter.hill@york.ac.uk>
(cherry picked from commit 3014f8787196d7c0d15d24195c8f07167968ff55)

gcc/fortran/resolve.cc
gcc/testsuite/gfortran.dg/pr95446.f90

index a0ed0e516da349db22dc6054fd67c95f724fd668..0261b4e6b246d144a8c61395130f94a193a5c164 100644 (file)
@@ -2409,7 +2409,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;
index 86e1019d7af9aeafc4c092d3ae4405067ea56c55..0787658813aa58728736209f65f68fd5c034b848 100644 (file)
@@ -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