* [PATCH] PR fortran/102817 - [12 Regression] ICE in gfc_clear_shape, at fortran/expr.c:422
@ 2021-11-01 21:39 Harald Anlauf
2021-11-05 21:28 ` Mikael Morin
0 siblings, 1 reply; 4+ messages in thread
From: Harald Anlauf @ 2021-11-01 21:39 UTC (permalink / raw)
To: fortran, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 269 bytes --]
Dear Fortranners,
a recent patch uncovered a latent issue with simplification of
array-valued expressions where the resulting shape was not set
from the referenced subobject. Once found, the fix looks obvious.
Regtested on x86_64-pc-linux-gnu. OK?
Thanks,
Harald
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr102817.diff --]
[-- Type: text/x-patch, Size: 1364 bytes --]
Fortran: fix simplification of array-valued parameter expressions
gcc/fortran/ChangeLog:
PR fortran/102817
* expr.c (simplify_parameter_variable): Copy shape of referenced
subobject when simplifying.
gcc/testsuite/ChangeLog:
PR fortran/102817
* gfortran.dg/pr102817.f90: New test.
diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c
index 4dea840e348..c5360dfaede 100644
--- a/gcc/fortran/expr.c
+++ b/gcc/fortran/expr.c
@@ -2129,6 +2129,7 @@ simplify_parameter_variable (gfc_expr *p, int type)
return false;
e->rank = p->rank;
+ e->shape = gfc_copy_shape (p->shape, p->rank);
if (e->ts.type == BT_CHARACTER && p->ts.u.cl)
e->ts = p->ts;
diff --git a/gcc/testsuite/gfortran.dg/pr102817.f90 b/gcc/testsuite/gfortran.dg/pr102817.f90
new file mode 100644
index 00000000000..c081a69f0ea
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr102817.f90
@@ -0,0 +1,17 @@
+! { dg-do compile }
+! PR fortran/102817 - ICE in gfc_clear_shape
+
+program test
+ type t
+ integer :: a(1,2) = 3
+ end type t
+ type(t), parameter :: u = t(4)
+ type(t), parameter :: x(1) = t(4)
+ integer, parameter :: p(1,2) = (x(1)%a)
+ integer :: z(1,2) = (x(1)%a)
+ integer :: y(1,2), v(1,2), w(1,2)
+ v = (u %a)
+ w = x(1)%a
+ y = (x(1)%a)
+ print *, v, w, y, z, p
+end
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] PR fortran/102817 - [12 Regression] ICE in gfc_clear_shape, at fortran/expr.c:422
2021-11-01 21:39 [PATCH] PR fortran/102817 - [12 Regression] ICE in gfc_clear_shape, at fortran/expr.c:422 Harald Anlauf
@ 2021-11-05 21:28 ` Mikael Morin
2021-11-05 22:53 ` Harald Anlauf
0 siblings, 1 reply; 4+ messages in thread
From: Mikael Morin @ 2021-11-05 21:28 UTC (permalink / raw)
To: Harald Anlauf, fortran, gcc-patches
Le 01/11/2021 à 22:39, Harald Anlauf via Fortran a écrit :
> Dear Fortranners,
>
> a recent patch uncovered a latent issue with simplification of
> array-valued expressions where the resulting shape was not set
> from the referenced subobject. Once found, the fix looks obvious.
>
> Regtested on x86_64-pc-linux-gnu. OK?
>
Hello,
> diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c
> index 4dea840e348..c5360dfaede 100644
> --- a/gcc/fortran/expr.c
> +++ b/gcc/fortran/expr.c
> @@ -2129,6 +2129,7 @@ simplify_parameter_variable (gfc_expr *p, int type)
> return false;
>
> e->rank = p->rank;
> + e->shape = gfc_copy_shape (p->shape, p->rank);
>
I think e->shape can be non-null, and should be freed beforehand.
Ok with that change.
Mikael
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] PR fortran/102817 - [12 Regression] ICE in gfc_clear_shape, at fortran/expr.c:422
2021-11-05 21:28 ` Mikael Morin
@ 2021-11-05 22:53 ` Harald Anlauf
2021-11-05 22:53 ` Harald Anlauf
0 siblings, 1 reply; 4+ messages in thread
From: Harald Anlauf @ 2021-11-05 22:53 UTC (permalink / raw)
To: Mikael Morin, fortran, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 1025 bytes --]
Hi Mikael,
Am 05.11.21 um 22:28 schrieb Mikael Morin:
> Le 01/11/2021 à 22:39, Harald Anlauf via Fortran a écrit :
>> Dear Fortranners,
>>
>> a recent patch uncovered a latent issue with simplification of
>> array-valued expressions where the resulting shape was not set
>> from the referenced subobject. Once found, the fix looks obvious.
>>
>> Regtested on x86_64-pc-linux-gnu. OK?
>>
> Hello,
>
>> diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c
>> index 4dea840e348..c5360dfaede 100644
>> --- a/gcc/fortran/expr.c
>> +++ b/gcc/fortran/expr.c
>> @@ -2129,6 +2129,7 @@ simplify_parameter_variable (gfc_expr *p, int type)
>> return false;
>>
>> e->rank = p->rank;
>> + e->shape = gfc_copy_shape (p->shape, p->rank);
>>
>
> I think e->shape can be non-null, and should be freed beforehand.
good point. I've added this and tested again.
See attached patch for the update.
> Ok with that change.
>
> Mikael
>
Thanks for the review!
Harald
[-- Attachment #2: pr102817.diff --]
[-- Type: text/x-patch, Size: 1808 bytes --]
From bcf3728abe8488882922005166d3065fc5fdfea1 Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Fri, 5 Nov 2021 23:48:20 +0100
Subject: [PATCH] Fortran: fix simplification of array-valued parameter
expressions
gcc/fortran/ChangeLog:
PR fortran/102817
* expr.c (simplify_parameter_variable): Copy shape of referenced
subobject when simplifying.
gcc/testsuite/ChangeLog:
PR fortran/102817
* gfortran.dg/pr102817.f90: New test.
---
gcc/fortran/expr.c | 2 ++
gcc/testsuite/gfortran.dg/pr102817.f90 | 17 +++++++++++++++++
2 files changed, 19 insertions(+)
create mode 100644 gcc/testsuite/gfortran.dg/pr102817.f90
diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c
index 087d822021a..941d29cf7cd 100644
--- a/gcc/fortran/expr.c
+++ b/gcc/fortran/expr.c
@@ -2128,6 +2128,8 @@ simplify_parameter_variable (gfc_expr *p, int type)
if (e == NULL)
return false;
+ gfc_free_shape (&e->shape, e->rank);
+ e->shape = gfc_copy_shape (p->shape, p->rank);
e->rank = p->rank;
if (e->ts.type == BT_CHARACTER && p->ts.u.cl)
diff --git a/gcc/testsuite/gfortran.dg/pr102817.f90 b/gcc/testsuite/gfortran.dg/pr102817.f90
new file mode 100644
index 00000000000..c081a69f0ea
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr102817.f90
@@ -0,0 +1,17 @@
+! { dg-do compile }
+! PR fortran/102817 - ICE in gfc_clear_shape
+
+program test
+ type t
+ integer :: a(1,2) = 3
+ end type t
+ type(t), parameter :: u = t(4)
+ type(t), parameter :: x(1) = t(4)
+ integer, parameter :: p(1,2) = (x(1)%a)
+ integer :: z(1,2) = (x(1)%a)
+ integer :: y(1,2), v(1,2), w(1,2)
+ v = (u %a)
+ w = x(1)%a
+ y = (x(1)%a)
+ print *, v, w, y, z, p
+end
--
2.26.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] PR fortran/102817 - [12 Regression] ICE in gfc_clear_shape, at fortran/expr.c:422
2021-11-05 22:53 ` Harald Anlauf
@ 2021-11-05 22:53 ` Harald Anlauf
0 siblings, 0 replies; 4+ messages in thread
From: Harald Anlauf @ 2021-11-05 22:53 UTC (permalink / raw)
To: gcc-patches; +Cc: fortran
[-- Attachment #1: Type: text/plain, Size: 991 bytes --]
Hi Mikael,
Am 05.11.21 um 22:28 schrieb Mikael Morin:
> Le 01/11/2021 à 22:39, Harald Anlauf via Fortran a écrit :
>> Dear Fortranners,
>>
>> a recent patch uncovered a latent issue with simplification of
>> array-valued expressions where the resulting shape was not set
>> from the referenced subobject. Once found, the fix looks obvious.
>>
>> Regtested on x86_64-pc-linux-gnu. OK?
>>
> Hello,
>
>> diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c
>> index 4dea840e348..c5360dfaede 100644
>> --- a/gcc/fortran/expr.c
>> +++ b/gcc/fortran/expr.c
>> @@ -2129,6 +2129,7 @@ simplify_parameter_variable (gfc_expr *p, int type)
>> return false;
>>
>> e->rank = p->rank;
>> + e->shape = gfc_copy_shape (p->shape, p->rank);
>>
>
> I think e->shape can be non-null, and should be freed beforehand.
good point. I've added this and tested again.
See attached patch for the update.
> Ok with that change.
>
> Mikael
>
Thanks for the review!
Harald
[-- Attachment #2: pr102817.diff --]
[-- Type: text/x-patch, Size: 1751 bytes --]
From bcf3728abe8488882922005166d3065fc5fdfea1 Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Fri, 5 Nov 2021 23:48:20 +0100
Subject: [PATCH] Fortran: fix simplification of array-valued parameter
expressions
gcc/fortran/ChangeLog:
PR fortran/102817
* expr.c (simplify_parameter_variable): Copy shape of referenced
subobject when simplifying.
gcc/testsuite/ChangeLog:
PR fortran/102817
* gfortran.dg/pr102817.f90: New test.
---
gcc/fortran/expr.c | 2 ++
gcc/testsuite/gfortran.dg/pr102817.f90 | 17 +++++++++++++++++
2 files changed, 19 insertions(+)
create mode 100644 gcc/testsuite/gfortran.dg/pr102817.f90
diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c
index 087d822021a..941d29cf7cd 100644
--- a/gcc/fortran/expr.c
+++ b/gcc/fortran/expr.c
@@ -2128,6 +2128,8 @@ simplify_parameter_variable (gfc_expr *p, int type)
if (e == NULL)
return false;
+ gfc_free_shape (&e->shape, e->rank);
+ e->shape = gfc_copy_shape (p->shape, p->rank);
e->rank = p->rank;
if (e->ts.type == BT_CHARACTER && p->ts.u.cl)
diff --git a/gcc/testsuite/gfortran.dg/pr102817.f90 b/gcc/testsuite/gfortran.dg/pr102817.f90
new file mode 100644
index 00000000000..c081a69f0ea
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr102817.f90
@@ -0,0 +1,17 @@
+! { dg-do compile }
+! PR fortran/102817 - ICE in gfc_clear_shape
+
+program test
+ type t
+ integer :: a(1,2) = 3
+ end type t
+ type(t), parameter :: u = t(4)
+ type(t), parameter :: x(1) = t(4)
+ integer, parameter :: p(1,2) = (x(1)%a)
+ integer :: z(1,2) = (x(1)%a)
+ integer :: y(1,2), v(1,2), w(1,2)
+ v = (u %a)
+ w = x(1)%a
+ y = (x(1)%a)
+ print *, v, w, y, z, p
+end
--
2.26.2
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-11-05 22:53 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-01 21:39 [PATCH] PR fortran/102817 - [12 Regression] ICE in gfc_clear_shape, at fortran/expr.c:422 Harald Anlauf
2021-11-05 21:28 ` Mikael Morin
2021-11-05 22:53 ` Harald Anlauf
2021-11-05 22:53 ` 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).