[8/9/10/11,Regression] ICE on invalid with argument list for module procedure

Message ID trinity-fab64c0b-fd2a-4d6d-8111-3468a2ca755c-1593118639634@3c-app-gmx-bs31
State New
Headers show
Series
  • [8/9/10/11,Regression] ICE on invalid with argument list for module procedure
Related show

Commit Message

Harald Anlauf June 25, 2020, 8:57 p.m.
A simple situation where a NULL pointer dereference occurs during error recovery.

Regtested on x86_64-pc-linux-gnu.

OK for master / backports?

Thanks,
Harald


PR fortran/93423 - ICE on invalid with argument list for module procedure

When recovering from an error, a NULL pointer dereference could occur.
Check for that situation and punt.

gcc/fortran/
	PR fortran/93423
	* resolve.c (resolve_symbol): Avoid NULL pointer dereference.

Comments

Harald Anlauf June 29, 2020, 7:03 p.m. | #1
Early ping (might make it into 10.2).

> A simple situation where a NULL pointer dereference occurs during error recovery.

>

> Regtested on x86_64-pc-linux-gnu.

>

> OK for master / backports?

>

> Thanks,

> Harald

>

>

> PR fortran/93423 - ICE on invalid with argument list for module procedure

>

> When recovering from an error, a NULL pointer dereference could occur.

> Check for that situation and punt.

>

> gcc/fortran/

> 	PR fortran/93423

> 	* resolve.c (resolve_symbol): Avoid NULL pointer dereference.

>


Thanks,
Harald

Patch

diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index 6fa34caec54..c9447a24885 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -15901,7 +15901,7 @@  resolve_symbol (gfc_symbol *sym)
       if (formal)
 	{
 	  sym->formal_ns = formal->sym->ns;
-          if (sym->ns != formal->sym->ns)
+	  if (sym->ns != formal->sym->ns && sym->formal_ns)
 	    sym->formal_ns->refs++;
 	}
     }
diff --git a/gcc/testsuite/gfortran.dg/pr93423.f90 b/gcc/testsuite/gfortran.dg/pr93423.f90
new file mode 100644
index 00000000000..fed5914daba
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr93423.f90
@@ -0,0 +1,21 @@ 
+! { dg-do compile }
+! PR fortran/93423 - ICE on invalid with argument list for module procedure
+
+module t
+  type :: b
+   contains
+     procedure :: p => bp
+  end type b
+  interface
+     module function bp(s)
+       class(b), intent(inout) :: s
+       integer, pointer :: bp
+     end function
+  end interface
+end module t
+
+submodule (t) ts
+contains
+  module procedure bp(s) ! { dg-error "must be in a generic module interface" }
+  end procedure bp       ! { dg-error "Expecting END SUBMODULE statement" }
+end submodule ts