PR fortran/102817 - [12 Regression] ICE in gfc_clear_shape, at fortran/expr.c:422

Message ID trinity-45303764-1042-4399-a4e2-68ced122e6a8-1635802792835@3c-app-gmx-bap65
State New
Headers
Series PR fortran/102817 - [12 Regression] ICE in gfc_clear_shape, at fortran/expr.c:422 |

Commit Message

Harald Anlauf Nov. 1, 2021, 9:39 p.m. UTC
  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
  

Comments

Mikael Morin Nov. 5, 2021, 9:28 p.m. UTC | #1
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
  
Harald Anlauf Nov. 5, 2021, 10:53 p.m. UTC | #2
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
  

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.

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