PR fortran/103217 & 103218 - ICEs during simplification after r12-4967-gbcf3728abe848888

Message ID trinity-020f031b-943e-4153-89ed-2ff6157737f2-1636489277236@3c-app-gmx-bap54
State New
Headers
Series PR fortran/103217 & 103218 - ICEs during simplification after r12-4967-gbcf3728abe848888 |

Commit Message

Harald Anlauf Nov. 9, 2021, 8:21 p.m. UTC
  Dear all,

I'd like to commit the attached patch as obvious within the next 24 hours
unless anybody objects, or earlier if there is positive feedback.

The patch only fixes three obvious NULL pointer dereferences that were
latent before the referenced commit and exhibited in the testcases,
see PRs.

The submitted testcases in the PRs hint at unimplemented parts of the
F2018 standard in gfortran.  I consider it unlikely that these parts are
written before 12-release, so fixing the ICE is something that can be
done now.  After that, either the regression marker can be removed from
the PRs, or they are closed and the remaining issues moved to a new PR.

Regtested on x86_64-pc-linux-gnu.  Comments welcome.

Thanks,
Harald
  

Comments

Thomas Koenig Nov. 10, 2021, 6:36 a.m. UTC | #1
Hi Harald,

> I'd like to commit the attached patch as obvious within the next 24 hours
> unless anybody objects, or earlier if there is positive feedback.

OK with a ChangeLog entry and the correct PR numbers (I believe
they are 103137 and 103138) :-)

Best regards

	Thomas
  
Harald Anlauf Nov. 10, 2021, 7:54 p.m. UTC | #2
Hi Thomas,

> > I'd like to commit the attached patch as obvious within the next 24 hours
> > unless anybody objects, or earlier if there is positive feedback.
>
> OK with a ChangeLog entry and the correct PR numbers (I believe
> they are 103137 and 103138) :-)

I think I had really fat fingers when typing the subject of the mail.
The ChangeLog was actually fine.  :-)

> Best regards
>
> 	Thomas
>

Thanks,
Harald
  

Patch

From a40cbf2b28db7824740ff1cff3eaffcd768fe456 Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Tue, 9 Nov 2021 21:02:44 +0100
Subject: [PATCH] Fortran: avoid NULL pointer dereferences

gcc/fortran/ChangeLog:

	PR fortran/103137
	PR fortran/103138
	* check.c (gfc_check_shape): Avoid NULL pointer dereference on
	missing ref.
	* simplify.c (gfc_simplify_cshift): Avoid NULL pointer dereference
	when shape not set.
	(gfc_simplify_transpose): Likewise.
---
 gcc/fortran/check.c    | 3 +++
 gcc/fortran/simplify.c | 6 ++++++
 2 files changed, 9 insertions(+)

diff --git a/gcc/fortran/check.c b/gcc/fortran/check.c
index 15772009af4..ffa07b510cd 100644
--- a/gcc/fortran/check.c
+++ b/gcc/fortran/check.c
@@ -5096,6 +5096,9 @@  gfc_check_shape (gfc_expr *source, gfc_expr *kind)
   if (source->rank == 0 || source->expr_type != EXPR_VARIABLE)
     return true;

+  if (source->ref == NULL)
+    return false;
+
   ar = gfc_find_array_ref (source);

   if (ar->as && ar->as->type == AS_ASSUMED_SIZE && ar->type == AR_FULL)
diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c
index d675f2c3aef..6a6b3fbd037 100644
--- a/gcc/fortran/simplify.c
+++ b/gcc/fortran/simplify.c
@@ -2109,6 +2109,9 @@  gfc_simplify_cshift (gfc_expr *array, gfc_expr *shift, gfc_expr *dim)
   else
     which = 0;

+  if (array->shape == NULL)
+    return NULL;
+
   gfc_array_size (array, &size);
   arraysize = mpz_get_ui (size);
   mpz_clear (size);
@@ -8174,6 +8177,9 @@  gfc_simplify_transpose (gfc_expr *matrix)

   gcc_assert (matrix->rank == 2);

+  if (matrix->shape == NULL)
+    return NULL;
+
   result = gfc_get_array_expr (matrix->ts.type, matrix->ts.kind,
 			       &matrix->where);
   result->rank = 2;
--
2.26.2