Fortran: error recovery on checking procedure argument intent [PR103608]
authorSteve Kargl <kargl@gcc.gnu.org>
Wed, 15 Feb 2023 21:40:37 +0000 (22:40 +0100)
committerHarald Anlauf <anlauf@gmx.de>
Wed, 15 Feb 2023 21:45:20 +0000 (22:45 +0100)
gcc/fortran/ChangeLog:

PR fortran/103608
* frontend-passes.cc (do_intent): Catch NULL pointer dereference on
reference to invalid formal argument.

gcc/testsuite/ChangeLog:

PR fortran/103608
* gfortran.dg/pr103608.f90: New test.

gcc/fortran/frontend-passes.cc
gcc/testsuite/gfortran.dg/pr103608.f90 [new file with mode: 0644]

index 1cbc63016dabeac4928233967dd13e00b60635ac..02fcb41dbc4112abceb0dd397d01b8d557450765 100644 (file)
@@ -3049,7 +3049,8 @@ do_intent (gfc_expr **e)
          do_sym = dl->ext.iterator->var->symtree->n.sym;
 
          if (a->expr && a->expr->symtree
-             && a->expr->symtree->n.sym == do_sym)
+             && a->expr->symtree->n.sym == do_sym
+             && f->sym)
            {
              if (f->sym->attr.intent == INTENT_OUT)
                gfc_error_now ("Variable %qs at %L set to undefined value "
diff --git a/gcc/testsuite/gfortran.dg/pr103608.f90 b/gcc/testsuite/gfortran.dg/pr103608.f90
new file mode 100644 (file)
index 0000000..5c37cb7
--- /dev/null
@@ -0,0 +1,14 @@
+! { dg-do compile }
+! { dg-options "-w" }
+! PR fortran/103608 - ICE in do_intent
+! Contributed by G.Steinmetz
+
+program p
+  implicit none
+  integer :: i
+  integer :: x     ! { dg-error "Alternate return specifier" }
+  x(*) = 0
+  do i = 1, 2
+     print *, x(i) ! { dg-error "Missing alternate return specifier" }
+  end do
+end