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 r12-3967] Fortran: fix error recovery for invalid constructor
Date: Wed, 29 Sep 2021 18:12:17 +0000 (GMT)	[thread overview]
Message-ID: <20210929181217.993163858406@sourceware.org> (raw)

https://gcc.gnu.org/g:5e2adfeed21ee584a82cdcdfa7eed41202eb67cd

commit r12-3967-g5e2adfeed21ee584a82cdcdfa7eed41202eb67cd
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Wed Sep 29 20:11:53 2021 +0200

    Fortran: fix error recovery for invalid constructor
    
    gcc/fortran/ChangeLog:
    
            PR fortran/102520
            * array.c (expand_constructor): Do not dereference NULL pointer.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/102520
            * gfortran.dg/pr102520.f90: New test.

Diff:
---
 gcc/fortran/array.c                    |  3 +++
 gcc/testsuite/gfortran.dg/pr102520.f90 | 12 ++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/gcc/fortran/array.c b/gcc/fortran/array.c
index b858bada18a..a4d1cb4c72d 100644
--- a/gcc/fortran/array.c
+++ b/gcc/fortran/array.c
@@ -1798,6 +1798,9 @@ expand_constructor (gfc_constructor_base base)
 
       e = c->expr;
 
+      if (e == NULL)
+	return false;
+
       if (empty_constructor)
 	empty_ts = e->ts;
 
diff --git a/gcc/testsuite/gfortran.dg/pr102520.f90 b/gcc/testsuite/gfortran.dg/pr102520.f90
new file mode 100644
index 00000000000..1c98c185c17
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr102520.f90
@@ -0,0 +1,12 @@
+! { dg-do compile }
+! PR fortran/102520 - ICE in expand_constructor, at fortran/array.c:1802
+
+program p
+  type t
+  end type
+  type(t), parameter :: a(4)   = shape(1)         ! { dg-error "Incompatible" }
+  type(t), parameter :: b(2,2) = reshape(a,[2,2]) ! { dg-error "Incompatible" }
+  type(t), parameter :: c(2,2) = transpose(b)     ! { dg-error "Unclassifiable" }
+end
+
+! { dg-error "Different shape for array assignment" " " { target *-*-* } 7 }


                 reply	other threads:[~2021-09-29 18:12 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=20210929181217.993163858406@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).