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-10998] Fortran: catch NULL pointer dereferences while simplifying PACK [PR106857]
Date: Thu, 22 Sep 2022 18:37:18 +0000 (GMT)	[thread overview]
Message-ID: <20220922183718.2E5A83858D38@sourceware.org> (raw)

https://gcc.gnu.org/g:cf172d0cdf355042223a3b1ebc04b472386a954e

commit r10-10998-gcf172d0cdf355042223a3b1ebc04b472386a954e
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Thu Sep 15 22:39:24 2022 +0200

    Fortran: catch NULL pointer dereferences while simplifying PACK [PR106857]
    
    gcc/fortran/ChangeLog:
    
            PR fortran/106857
            * simplify.c (gfc_simplify_pack): Check for NULL pointer dereferences
            while walking through constructors (error recovery).
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/106857
            * gfortran.dg/pr106857.f90: New test.
    
    (cherry picked from commit 2b75d5f533b9d6b39f4055949aff64ed0d22dd24)

Diff:
---
 gcc/fortran/simplify.c                 |  2 +-
 gcc/testsuite/gfortran.dg/pr106857.f90 | 12 ++++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c
index 29d4c695302..b3d73935771 100644
--- a/gcc/fortran/simplify.c
+++ b/gcc/fortran/simplify.c
@@ -6293,7 +6293,7 @@ gfc_simplify_pack (gfc_expr *array, gfc_expr *mask, gfc_expr *vector)
       /* Copy only those elements of ARRAY to RESULT whose
 	 MASK equals .TRUE..  */
       mask_ctor = gfc_constructor_first (mask->value.constructor);
-      while (mask_ctor)
+      while (mask_ctor && array_ctor)
 	{
 	  if (mask_ctor->expr->value.logical)
 	    {
diff --git a/gcc/testsuite/gfortran.dg/pr106857.f90 b/gcc/testsuite/gfortran.dg/pr106857.f90
new file mode 100644
index 00000000000..4b0f86a75a6
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr106857.f90
@@ -0,0 +1,12 @@
+! { dg-do compile }
+! PR fortran/106857 - ICE in gfc_simplify_pack
+! Contributed by G.Steinmetz
+
+program p
+  type t
+     integer :: n
+  end type
+  type(t), parameter :: a(2,2) = t(1)
+  type(t), parameter :: b(4) = reshape(a, [2])                          ! { dg-error "Different shape" }
+  type(t), parameter :: c(2) = pack(b, [.false.,.true.,.false.,.true.]) ! { dg-error "Different shape" }
+end

                 reply	other threads:[~2022-09-22 18:37 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=20220922183718.2E5A83858D38@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).