Fortran: avoid NULL pointer dereference checking elemental procedure args
authorHarald Anlauf <anlauf@gmx.de>
Tue, 29 Mar 2022 20:12:15 +0000 (22:12 +0200)
committerHarald Anlauf <anlauf@gmx.de>
Tue, 29 Mar 2022 20:12:15 +0000 (22:12 +0200)
gcc/fortran/ChangeLog:

PR fortran/104571
* resolve.cc (resolve_elemental_actual): Avoid NULL pointer
dereference.

gcc/testsuite/ChangeLog:

PR fortran/104571
* gfortran.dg/pr104571.f90: New test.

Co-authored-by: Steven G. Kargl <kargl@gcc.gnu.org>
gcc/fortran/resolve.cc
gcc/testsuite/gfortran.dg/pr104571.f90 [new file with mode: 0644]

index 2907677..21c8797 100644 (file)
@@ -2397,8 +2397,9 @@ resolve_elemental_actual (gfc_expr *expr, gfc_code *c)
   if (rank > 0 && esym && expr == NULL)
     for (eformal = esym->formal, arg = arg0; arg && eformal;
         arg = arg->next, eformal = eformal->next)
-      if ((eformal->sym->attr.intent == INTENT_OUT
-          || eformal->sym->attr.intent == INTENT_INOUT)
+      if (eformal->sym
+         && (eformal->sym->attr.intent == INTENT_OUT
+             || eformal->sym->attr.intent == INTENT_INOUT)
          && arg->expr && arg->expr->rank == 0)
        {
          gfc_error ("Actual argument at %L for INTENT(%s) dummy %qs of "
diff --git a/gcc/testsuite/gfortran.dg/pr104571.f90 b/gcc/testsuite/gfortran.dg/pr104571.f90
new file mode 100644 (file)
index 0000000..9a6f2d0
--- /dev/null
@@ -0,0 +1,12 @@
+! { dg-do compile }
+! { dg-options "-std=legacy" }
+! PR fortran/104571 - ICE in resolve_elemental_actual
+! Contributed by G.Steinmetz
+
+program p
+  real :: x(3)
+  call g(x)                 ! { dg-error "Missing alternate return" }
+contains
+  elemental subroutine g(*) ! { dg-error "Alternate return specifier" }
+  end
+end