public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Harald Anlauf <anlauf@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r10-11011] Fortran: NULL pointer dereference in invalid simplification [PR106985]
Date: Fri, 30 Sep 2022 20:33:54 +0000 (GMT)	[thread overview]
Message-ID: <20220930203354.A3C153853549@sourceware.org> (raw)

https://gcc.gnu.org/g:12cd4a7c465b1a0874f5bc4419bd19d8041a8e2a

commit r10-11011-g12cd4a7c465b1a0874f5bc4419bd19d8041a8e2a
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Tue Sep 20 22:23:43 2022 +0200

    Fortran: NULL pointer dereference in invalid simplification [PR106985]
    
    gcc/fortran/ChangeLog:
    
            PR fortran/106985
            * expr.c (gfc_simplify_expr): Avoid NULL pointer dereference.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/106985
            * gfortran.dg/pr106985.f90: New test.
    
    (cherry picked from commit 8dbb15bc2d019488240c1e69d93121b0347ac092)

Diff:
---
 gcc/fortran/expr.c                     | 3 ++-
 gcc/testsuite/gfortran.dg/pr106985.f90 | 8 ++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c
index 6d95120be50..1129f5f3302 100644
--- a/gcc/fortran/expr.c
+++ b/gcc/fortran/expr.c
@@ -2277,7 +2277,8 @@ gfc_simplify_expr (gfc_expr *p, int type)
 	 initialization expression, or we want a subsection.  */
       if (p->symtree->n.sym->attr.flavor == FL_PARAMETER
 	  && (gfc_init_expr_flag || p->ref
-	      || p->symtree->n.sym->value->expr_type != EXPR_ARRAY))
+	      || (p->symtree->n.sym->value
+		  && p->symtree->n.sym->value->expr_type != EXPR_ARRAY)))
 	{
 	  if (!simplify_parameter_variable (p, type))
 	    return false;
diff --git a/gcc/testsuite/gfortran.dg/pr106985.f90 b/gcc/testsuite/gfortran.dg/pr106985.f90
new file mode 100644
index 00000000000..f4ed92577a3
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr106985.f90
@@ -0,0 +1,8 @@
+! { dg-do compile }
+! PR fortran/106985 - ICE in gfc_simplify_expr
+! Contributed by G.Steinmetz
+
+program p
+  integer, parameter :: a(2) = 1
+  integer, parameter :: b = a(2) + b ! { dg-error "before its definition is complete" }
+end

                 reply	other threads:[~2022-09-30 20:33 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220930203354.A3C153853549@sourceware.org \
    --to=anlauf@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).