Fortran: prevent NULL pointer dereference in check of passed do-loop variable
authorHarald Anlauf <anlauf@gmx.de>
Tue, 14 Dec 2021 20:57:04 +0000 (21:57 +0100)
committerHarald Anlauf <anlauf@gmx.de>
Tue, 14 Dec 2021 20:57:04 +0000 (21:57 +0100)
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
gcc/testsuite/gfortran.dg/do_check_19.f90 [new file with mode: 0644]

index c106ee0..6ffe072 100644 (file)
@@ -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)
diff --git a/gcc/testsuite/gfortran.dg/do_check_19.f90 b/gcc/testsuite/gfortran.dg/do_check_19.f90
new file mode 100644 (file)
index 0000000..1373a73
--- /dev/null
@@ -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