diff mbox series

[committed] PR fortran/103609 - [11/12 Regression] ICE in gfc_sym_get_dummy_args, at fortran/symbol.c:5243

Message ID trinity-908cc5a1-9a84-4034-961c-6a0d50365802-1638994881166@3c-app-gmx-bs37
State New
Headers show
Series [committed] PR fortran/103609 - [11/12 Regression] ICE in gfc_sym_get_dummy_args, at fortran/symbol.c:5243 | expand

Commit Message

Harald Anlauf Dec. 8, 2021, 8:21 p.m. UTC
Dear all,

the attached patch fixes a NULL pointer dereference for a missed
declaration of a dummy argument or a conflict of a procedure with
another decl.

Committed as obvious after regtesting on x86_64-pc-linux-gnu:

commit r12-5847-gb77968a70537429b4f548f90c369d26e6b6943cc
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Wed Dec 8 21:14:19 2021 +0100

    Fortran: avoid NULL pointer dereference on missing or bad dummy arguments

    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.

Thanks,
Harald
diff mbox series

Patch

From b77968a70537429b4f548f90c369d26e6b6943cc Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Wed, 8 Dec 2021 21:14:19 +0100
Subject: [PATCH] Fortran: avoid NULL pointer dereference on missing or bad
 dummy arguments

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                   |  3 +++
 gcc/testsuite/gfortran.dg/pr103609.f90 | 15 +++++++++++++++
 2 files changed, 18 insertions(+)
 create mode 100644 gcc/testsuite/gfortran.dg/pr103609.f90

diff --git a/gcc/fortran/symbol.c b/gcc/fortran/symbol.c
index 179f6029ca3..ebd99846610 100644
--- a/gcc/fortran/symbol.c
+++ b/gcc/fortran/symbol.c
@@ -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
index 00000000000..57f6a3b1531
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr103609.f90
@@ -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
--
2.26.2