Fortran: avoid NULL pointer dereference on missing or bad dummy arguments
authorHarald Anlauf <anlauf@gmx.de>
Wed, 8 Dec 2021 20:14:19 +0000 (21:14 +0100)
committerHarald Anlauf <anlauf@gmx.de>
Wed, 8 Dec 2021 20:14:19 +0000 (21:14 +0100)
gcc/fortran/ChangeLog:

PR fortran/103609
* symbol.c (gfc_sym_get_dummy_args): Catch NULL pointer
dereference.

gcc/testsuite/ChangeLog:

PR fortran/103609
* gfortran.dg/pr103609.f90: New test.

gcc/fortran/symbol.c
gcc/testsuite/gfortran.dg/pr103609.f90 [new file with mode: 0644]

index 179f602..ebd9984 100644 (file)
@@ -5240,6 +5240,9 @@ gfc_sym_get_dummy_args (gfc_symbol *sym)
 {
   gfc_formal_arglist *dummies;
 
+  if (sym == NULL)
+    return NULL;
+
   dummies = sym->formal;
   if (dummies == NULL && sym->ts.interface != NULL)
     dummies = sym->ts.interface->formal;
diff --git a/gcc/testsuite/gfortran.dg/pr103609.f90 b/gcc/testsuite/gfortran.dg/pr103609.f90
new file mode 100644 (file)
index 0000000..57f6a3b
--- /dev/null
@@ -0,0 +1,15 @@
+! { dg-do compile }
+! PR fortran/103609 - ICE in gfc_sym_get_dummy_args
+! Contributed by G.Steinmetz
+
+program p
+  implicit none
+  integer :: i
+  do i = 1, 2
+     call s
+  end do
+contains
+  subroutine s
+    call sub(x) ! { dg-error "has no IMPLICIT type" }
+  end
+end