public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR fortran/103217 & 103218 - ICEs during simplification after r12-4967-gbcf3728abe848888
@ 2021-11-09 20:21 Harald Anlauf
  2021-11-10  6:36 ` Thomas Koenig
  0 siblings, 1 reply; 3+ messages in thread
From: Harald Anlauf @ 2021-11-09 20:21 UTC (permalink / raw)
  To: fortran, gcc-patches

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

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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fortran-avoid-NULL-pointer-dereferences.patch --]
[-- Type: text/x-patch, Size: 1785 bytes --]

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] PR fortran/103217 & 103218 - ICEs during simplification after r12-4967-gbcf3728abe848888
  2021-11-09 20:21 [PATCH] PR fortran/103217 & 103218 - ICEs during simplification after r12-4967-gbcf3728abe848888 Harald Anlauf
@ 2021-11-10  6:36 ` Thomas Koenig
  2021-11-10 19:54   ` [PATCH] PR fortran/103137 & 103138 - ICEs during simplification after r12-4967-gbcf3728abe848888 (was: [PATCH] PR fortran/103217 & 103218 ...) Harald Anlauf
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas Koenig @ 2021-11-10  6:36 UTC (permalink / raw)
  To: Harald Anlauf, fortran, gcc-patches


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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] PR fortran/103137 & 103138 - ICEs during simplification after r12-4967-gbcf3728abe848888 (was: [PATCH] PR fortran/103217 & 103218 ...)
  2021-11-10  6:36 ` Thomas Koenig
@ 2021-11-10 19:54   ` Harald Anlauf
  0 siblings, 0 replies; 3+ messages in thread
From: Harald Anlauf @ 2021-11-10 19:54 UTC (permalink / raw)
  To: Thomas Koenig; +Cc: fortran, gcc-patches

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-11-10 19:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-09 20:21 [PATCH] PR fortran/103217 & 103218 - ICEs during simplification after r12-4967-gbcf3728abe848888 Harald Anlauf
2021-11-10  6:36 ` Thomas Koenig
2021-11-10 19:54   ` [PATCH] PR fortran/103137 & 103138 - ICEs during simplification after r12-4967-gbcf3728abe848888 (was: [PATCH] PR fortran/103217 & 103218 ...) 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).