public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r10-10998] Fortran: catch NULL pointer dereferences while simplifying PACK [PR106857]
@ 2022-09-22 18:37 Harald Anlauf
  0 siblings, 0 replies; only message in thread
From: Harald Anlauf @ 2022-09-22 18:37 UTC (permalink / raw)
  To: gcc-cvs

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-09-22 18:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-22 18:37 [gcc r10-10998] Fortran: catch NULL pointer dereferences while simplifying PACK [PR106857] Harald Anlauf

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).