* [Patch, fortran] PR98458 - ICE in gfc_conv_array_initializer due to array expressions within implied do-loop
@ 2021-01-05 12:09 Paul Richard Thomas
2021-01-05 12:54 ` Thomas Koenig
0 siblings, 1 reply; 2+ messages in thread
From: Paul Richard Thomas @ 2021-01-05 12:09 UTC (permalink / raw)
To: fortran; +Cc: Steve Kargl
[-- Attachment #1: Type: text/plain, Size: 816 bytes --]
This is another obvious patch. The first version of the patch just expanded
the constructor. Steve used gfc_reduce_init_expr to fix the immediate
problem within simplify_reshape. Since this has the advantage of doing the
type check as well and so I incorporated it in this inclusive patch.
Regtested on FC33/x86_64 - OK for master (and 9-/10-branches)?
Paul
Fortran:Fix simplification of constructors with implied-do [PR98458]
2021-01-05 Paul Thomas <pault@gcc.gnu.org>
gcc/fortran
PR fortran/98458
* simplify.c (is_constant_array_expr): If an array constructor
expression has elements other than constants or structures, try
fixing the expression with gfc_reduce_init_expr. Also, if shape
is NULL, obtain the array size and set it.
gcc/testsuite/
PR fortran/98458
* gfortran.dg/implied_do_3.f90 : New test.
[-- Attachment #2: submit.diff --]
[-- Type: text/x-patch, Size: 1609 bytes --]
diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c
index bfd410cf31d..06bde5209dd 100644
--- a/gcc/fortran/simplify.c
+++ b/gcc/fortran/simplify.c
@@ -220,6 +220,8 @@ static bool
is_constant_array_expr (gfc_expr *e)
{
gfc_constructor *c;
+ bool array_OK = true;
+ mpz_t size;
if (e == NULL)
return true;
@@ -231,13 +233,43 @@ is_constant_array_expr (gfc_expr *e)
if (e->expr_type != EXPR_ARRAY || !gfc_is_constant_expr (e))
return false;
+ for (c = gfc_constructor_first (e->value.constructor);
+ c; c = gfc_constructor_next (c))
+ if (c->expr->expr_type != EXPR_CONSTANT
+ && c->expr->expr_type != EXPR_STRUCTURE)
+ {
+ array_OK = false;
+ break;
+ }
+
+ /* Check and expand the constructor. */
+ if (!array_OK && gfc_init_expr_flag && e->rank == 1)
+ {
+ array_OK = gfc_reduce_init_expr (e);
+ /* gfc_reduce_init_expr resets the flag. */
+ gfc_init_expr_flag = true;
+ }
+ else
+ return array_OK;
+
+ /* Recheck to make sure that any EXPR_ARRAYs have gone. */
for (c = gfc_constructor_first (e->value.constructor);
c; c = gfc_constructor_next (c))
if (c->expr->expr_type != EXPR_CONSTANT
&& c->expr->expr_type != EXPR_STRUCTURE)
return false;
- return true;
+ /* Make sure that the array has a valid shape. */
+ if (e->shape == NULL && e->rank == 1)
+ {
+ if (!gfc_array_size(e, &size))
+ return false;
+ e->shape = gfc_get_shape (1);
+ mpz_init_set (e->shape[0], size);
+ mpz_clear (size);
+ }
+
+ return array_OK;
}
/* Test for a size zero array. */
[-- Attachment #3: implied_do_3.f90 --]
[-- Type: text/x-fortran, Size: 429 bytes --]
! { dg-do compile }
!
! Test the fix for PR98458 in which array expressions within the implied-do
! array constructor caused an ICE in trans-array.c(gfc_conv_array_initializer).
!
! Contributed by Xiao Liu <xiao.liu@compiler-dev.com>
!
program test
implicit none
integer :: i
integer, parameter :: t(6) = [1,2,3,4,5,6]
integer, parameter :: tmp(3,2) = reshape([(t(i:i+1),i=1,3)],[3,2])
print *, tmp ! Used to ICE
end
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Patch, fortran] PR98458 - ICE in gfc_conv_array_initializer due to array expressions within implied do-loop
2021-01-05 12:09 [Patch, fortran] PR98458 - ICE in gfc_conv_array_initializer due to array expressions within implied do-loop Paul Richard Thomas
@ 2021-01-05 12:54 ` Thomas Koenig
0 siblings, 0 replies; 2+ messages in thread
From: Thomas Koenig @ 2021-01-05 12:54 UTC (permalink / raw)
To: Paul Richard Thomas, fortran; +Cc: Steve Kargl
Hi Paul,
> Regtested on FC33/x86_64 - OK for master (and 9-/10-branches)?
OK.
Thanks for the patch!
Best regards
Thomas
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-01-05 12:54 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-05 12:09 [Patch, fortran] PR98458 - ICE in gfc_conv_array_initializer due to array expressions within implied do-loop Paul Richard Thomas
2021-01-05 12:54 ` Thomas Koenig
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).