public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-7904] Fortran: avoid NULL pointer dereference checking elemental procedure args
@ 2022-03-29 20:12 Harald Anlauf
  0 siblings, 0 replies; only message in thread
From: Harald Anlauf @ 2022-03-29 20:12 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:69db6e7f4e1d07bf8f33e93a29139cc16c1e0a2f

commit r12-7904-g69db6e7f4e1d07bf8f33e93a29139cc16c1e0a2f
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Tue Mar 29 22:12:15 2022 +0200

    Fortran: avoid NULL pointer dereference checking elemental procedure args
    
    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>

Diff:
---
 gcc/fortran/resolve.cc                 |  5 +++--
 gcc/testsuite/gfortran.dg/pr104571.f90 | 12 ++++++++++++
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index 290767723d8..21c8797c938 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -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
index 00000000000..9a6f2d0e872
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr104571.f90
@@ -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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-03-29 20:12 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-29 20:12 [gcc r12-7904] Fortran: avoid NULL pointer dereference checking elemental procedure args Harald Anlauf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).