public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: Harald Anlauf <anlauf@gmx.de>
To: fortran <fortran@gcc.gnu.org>, gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [PATCH, committed] PR fortran/104571 - ICE in resolve_elemental_actual, at fortran/resolve.cc:2383
Date: Tue, 29 Mar 2022 22:18:34 +0200	[thread overview]
Message-ID: <trinity-30ecdae6-e871-49da-a289-445a0d1dcebf-1648585114032@3c-app-gmx-bap05> (raw)

[-- Attachment #1: Type: text/plain, Size: 275 bytes --]

Dear all,

I committed an obvious patch by Steve to avoid a NULL pointer dereference
on checking for invalid specification of an elemental procedure argument:

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

Regtested on x86_64-pc-linux-gnu.

Thanks,
Harald


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr104571.diff --]
[-- Type: text/x-patch, Size: 2069 bytes --]

From 69db6e7f4e1d07bf8f33e93a29139cc16c1e0a2f Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Tue, 29 Mar 2022 22:12:15 +0200
Subject: [PATCH] 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>
---
 gcc/fortran/resolve.cc                 |  5 +++--
 gcc/testsuite/gfortran.dg/pr104571.f90 | 12 ++++++++++++
 2 files changed, 15 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/pr104571.f90

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
--
2.34.1


                 reply	other threads:[~2022-03-29 20:18 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=trinity-30ecdae6-e871-49da-a289-445a0d1dcebf-1648585114032@3c-app-gmx-bap05 \
    --to=anlauf@gmx.de \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).