PR fortran/103473 - [11/12 Regression] ICE in simplify_minmaxloc_nodim, at fortran/simplify.c:5287
Commit Message
Dear all,
another trivial and obvious one, discovered by Gerhard.
We can have a NULL pointer dereference simplifying MINLOC/MAXLOC
on an array that was not properly declared.
OK for mainline / affected 11-branch after regtesting completes?
Thanks,
Harald
Comments
Le 29/11/2021 à 23:01, Harald Anlauf via Fortran a écrit :
> Dear all,
>
> another trivial and obvious one, discovered by Gerhard.
>
> We can have a NULL pointer dereference simplifying MINLOC/MAXLOC
> on an array that was not properly declared.
>
> OK for mainline / affected 11-branch after regtesting completes?
>
Yes, fine as well.
I have the impression that there are quite a number of bugs of this
kind, and that maybe we could take a more systematic approach to not try
to simplify something with errors.
Thanks.
From 6bdecd3805eb0d55722992ccb517d08b9bafe605 Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Mon, 29 Nov 2021 22:56:30 +0100
Subject: [PATCH] Fortran: error recovery when simplifying MINLOC/MAXLOC
gcc/fortran/ChangeLog:
PR fortran/103473
* simplify.c (simplify_minmaxloc_nodim): Avoid NULL pointer
dereference when shape is not set.
gcc/testsuite/ChangeLog:
PR fortran/103473
* gfortran.dg/minmaxloc_15.f90: New test.
---
gcc/fortran/simplify.c | 3 +++
gcc/testsuite/gfortran.dg/minmaxloc_15.f90 | 11 +++++++++++
2 files changed, 14 insertions(+)
create mode 100644 gcc/testsuite/gfortran.dg/minmaxloc_15.f90
@@ -5280,6 +5280,9 @@ simplify_minmaxloc_nodim (gfc_expr *result, gfc_expr *extremum,
&& !mask->value.logical)
goto finish;
+ if (array->shape == NULL)
+ goto finish;
+
for (i = 0; i < array->rank; i++)
{
count[i] = 0;
new file mode 100644
@@ -0,0 +1,11 @@
+! { dg-do compile }
+! PR fortran/103473 - ICE in simplify_minmaxloc_nodim
+! Test case by Gerhard Steinmetz.
+
+subroutine s
+ implicit none
+ integer, parameter :: a(+'1') = [1] ! { dg-error "unary numeric operator" }
+ print *, minloc (a)
+end
+
+! { dg-prune-output "Parameter array" }
--
2.26.2