public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Harald Anlauf <anlauf@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r9-9872] Fortran: prevent NULL pointer dereference in check of passed do-loop variable
Date: Thu, 16 Dec 2021 22:33:58 +0000 (GMT)	[thread overview]
Message-ID: <20211216223358.E2AB53858D28@sourceware.org> (raw)

https://gcc.gnu.org/g:54947545e364016d396c2e4012b1d7e6fc5cc6ba

commit r9-9872-g54947545e364016d396c2e4012b1d7e6fc5cc6ba
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Tue Dec 14 21:57:04 2021 +0100

    Fortran: prevent NULL pointer dereference in check of passed do-loop variable
    
    gcc/fortran/ChangeLog:
    
            PR fortran/103717
            * frontend-passes.c (doloop_code): Prevent NULL pointer
            dereference when checking for passing a do-loop variable to a
            contained procedure with an interface mismatch.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/103717
            * gfortran.dg/do_check_19.f90: New test.
    
    (cherry picked from commit ca39102e10643a6b3f07d06934cc0907ba83d9ee)

Diff:
---
 gcc/fortran/frontend-passes.c             |  2 +-
 gcc/testsuite/gfortran.dg/do_check_19.f90 | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/frontend-passes.c b/gcc/fortran/frontend-passes.c
index dba21517972..7b0428d27f2 100644
--- a/gcc/fortran/frontend-passes.c
+++ b/gcc/fortran/frontend-passes.c
@@ -2416,7 +2416,7 @@ doloop_code (gfc_code **c, int *walk_subtrees ATTRIBUTE_UNUSED,
 
 	      do_sym = cl->ext.iterator->var->symtree->n.sym;
 
-	      if (a->expr && a->expr->symtree
+	      if (a->expr && a->expr->symtree && f->sym
 		  && a->expr->symtree->n.sym == do_sym)
 		{
 		  if (f->sym->attr.intent == INTENT_OUT)
diff --git a/gcc/testsuite/gfortran.dg/do_check_19.f90 b/gcc/testsuite/gfortran.dg/do_check_19.f90
new file mode 100644
index 00000000000..1373a7374ce
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/do_check_19.f90
@@ -0,0 +1,21 @@
+! { dg-do compile }
+! { dg-prune-output "Obsolescent feature: Alternate-return argument" }
+! PR fortran/103717 - ICE in doloop_code
+! Contributed by G.Steinmetz
+
+program p
+  integer :: i
+  do i = 1, 2
+     call s(i) ! { dg-error "Missing alternate return specifier" }
+  end do
+contains
+  subroutine s(*)
+  end
+end
+
+recursive subroutine s(*)
+  integer :: i
+  do i = 1, 2
+     call s(i) ! { dg-error "Missing alternate return specifier" }
+  end do
+end


                 reply	other threads:[~2021-12-16 22:33 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=20211216223358.E2AB53858D28@sourceware.org \
    --to=anlauf@gcc.gnu.org \
    --cc=gcc-cvs@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).