[committed] PR fortran/103717 - ICE in doloop_code, at fortran/frontend-passes.c:2656
Commit Message
Dear all,
the attached patch fixes an obvious NULL pointer dereference.
Committed as obvious after regtesting on x86_64-pc-linux-gnu.
Will "backport" to 11-branch after waiting a few days unless
someone protests.
Thanks,
Harald
From ca39102e10643a6b3f07d06934cc0907ba83d9ee Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Tue, 14 Dec 2021 21:57:04 +0100
Subject: [PATCH] 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.
---
gcc/fortran/frontend-passes.c | 2 +-
gcc/testsuite/gfortran.dg/do_check_19.f90 | 21 +++++++++++++++++++++
2 files changed, 22 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gfortran.dg/do_check_19.f90
@@ -2653,7 +2653,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)
new file mode 100644
@@ -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
--
2.26.2