public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Harald Anlauf <anlauf@gmx.de>
To: fortran <fortran@gcc.gnu.org>, gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [PATCH] PR fortran/102520 - [10/11/12 Regression] ICE in expand_constructor, at fortran/array.c:1802
Date: Tue, 28 Sep 2021 22:45:30 +0200	[thread overview]
Message-ID: <trinity-3e5df94d-a6a5-414e-a10a-88d4e0623356-1632861930464@3c-app-gmx-bs02> (raw)

[-- Attachment #1: Type: text/plain, Size: 266 bytes --]

Dear Fortranners,

Gerhard's testcase triggers a NULL pointer dereference during the
attempt to expand an invalid constructor.  The simple and obvious
solution is to catch that case.

Regtested on x86_64-pc-linux-gnu.  OK for all affected branches?

Thanks,
Harald


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr102520.diff --]
[-- Type: text/x-patch, Size: 1300 bytes --]

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 --git a/gcc/fortran/array.c b/gcc/fortran/array.c
index b858bada18a..8d66e009f66 100644
--- a/gcc/fortran/array.c
+++ b/gcc/fortran/array.c
@@ -1798,6 +1805,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-28 20:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-28 20:45 Harald Anlauf [this message]
2021-09-28 21:15 ` Thomas Koenig

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=trinity-3e5df94d-a6a5-414e-a10a-88d4e0623356-1632861930464@3c-app-gmx-bs02 \
    --to=anlauf@gmx.de \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@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).