public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/98458] New: implied do-loop used in initialization with RESHAPE throw ICE
@ 2020-12-28  4:20 xiao.liu@compiler-dev.com
  2020-12-28 12:03 ` [Bug fortran/98458] PRINT the array constructed from implied do-loop " anlauf at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: xiao.liu@compiler-dev.com @ 2020-12-28  4:20 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98458

            Bug ID: 98458
           Summary: implied do-loop used in initialization with RESHAPE
                    throw ICE
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: xiao.liu@compiler-dev.com
  Target Milestone: ---

test case: 

program test
  implicit none
  integer :: i
  integer, parameter :: t(6) = [1,2,3,4,5,6]
  integer, parameter :: tmp(6,1) = reshape([(t(i:i+1),i=1,3)],[6,1])
  print *, tmp
end

result:

    6 |   print *, tmp
      | 
internal compiler error: in gfc_conv_array_initializer, at
fortran/trans-array.c:6162

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

* [Bug fortran/98458] PRINT the array constructed from implied do-loop throw ICE
  2020-12-28  4:20 [Bug fortran/98458] New: implied do-loop used in initialization with RESHAPE throw ICE xiao.liu@compiler-dev.com
@ 2020-12-28 12:03 ` anlauf at gcc dot gnu.org
  2020-12-28 13:26 ` dominiq at lps dot ens.fr
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: anlauf at gcc dot gnu.org @ 2020-12-28 12:03 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98458

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
                 CC|                            |anlauf at gcc dot gnu.org
      Known to fail|                            |10.2.1, 11.0, 7.5.0, 8.4.1,
                   |                            |9.3.1
           Keywords|                            |ice-on-valid-code
   Last reconfirmed|                            |2020-12-28
     Ever confirmed|0                           |1

--- Comment #1 from anlauf at gcc dot gnu.org ---
Confirmed.

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

* [Bug fortran/98458] PRINT the array constructed from implied do-loop throw ICE
  2020-12-28  4:20 [Bug fortran/98458] New: implied do-loop used in initialization with RESHAPE throw ICE xiao.liu@compiler-dev.com
  2020-12-28 12:03 ` [Bug fortran/98458] PRINT the array constructed from implied do-loop " anlauf at gcc dot gnu.org
@ 2020-12-28 13:26 ` dominiq at lps dot ens.fr
  2020-12-28 20:09 ` kargl at gcc dot gnu.org
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: dominiq at lps dot ens.fr @ 2020-12-28 13:26 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98458

--- Comment #2 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
The test compiles if I replace

  print *, tmp

with

  print *, tmp(3,1) ! or (6,1)

but it prints

           1           2           2           3           3           4

instead of 2 or 4.

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

* [Bug fortran/98458] PRINT the array constructed from implied do-loop throw ICE
  2020-12-28  4:20 [Bug fortran/98458] New: implied do-loop used in initialization with RESHAPE throw ICE xiao.liu@compiler-dev.com
  2020-12-28 12:03 ` [Bug fortran/98458] PRINT the array constructed from implied do-loop " anlauf at gcc dot gnu.org
  2020-12-28 13:26 ` dominiq at lps dot ens.fr
@ 2020-12-28 20:09 ` kargl at gcc dot gnu.org
  2020-12-29 17:28 ` pault at gcc dot gnu.org
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: kargl at gcc dot gnu.org @ 2020-12-28 20:09 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98458

kargl at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kargl at gcc dot gnu.org

--- Comment #3 from kargl at gcc dot gnu.org ---
Index: gcc/fortran/simplify.c
===================================================================
--- gcc/fortran/simplify.c      (revision 1050250)
+++ gcc/fortran/simplify.c      (working copy)
@@ -6728,13 +6731,18 @@ gfc_simplify_reshape (gfc_expr *source, gfc_expr *shap
   bool zerosize = false;

   /* Check that argument expression types are OK.  */
-  if (!is_constant_array_expr (source)
-      || !is_constant_array_expr (shape_exp)
-      || !is_constant_array_expr (pad)
-      || !is_constant_array_expr (order_exp))
-    return NULL;
+  if (!is_constant_array_expr (source))
+    {
+      if (gfc_init_expr_flag && !gfc_reduce_init_expr (source))
+         return NULL;
+    }

   if (source->shape == NULL)
+    return NULL;
+
+  if (!is_constant_array_expr (shape_exp)
+      || !is_constant_array_expr (pad)
+      || !is_constant_array_expr (order_exp))
     return NULL;

   /* Proceed with simplification, unpacking the array.  */

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

* [Bug fortran/98458] PRINT the array constructed from implied do-loop throw ICE
  2020-12-28  4:20 [Bug fortran/98458] New: implied do-loop used in initialization with RESHAPE throw ICE xiao.liu@compiler-dev.com
                   ` (2 preceding siblings ...)
  2020-12-28 20:09 ` kargl at gcc dot gnu.org
@ 2020-12-29 17:28 ` pault at gcc dot gnu.org
  2020-12-30  0:52 ` xiao.liu@compiler-dev.com
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pault at gcc dot gnu.org @ 2020-12-29 17:28 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98458

Paul Thomas <pault at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |pault at gcc dot gnu.org
                 CC|                            |pault at gcc dot gnu.org

--- Comment #4 from Paul Thomas <pault at gcc dot gnu.org> ---
Created attachment 49856
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49856&action=edit
Fix for the PR

Thank you for the report on this problem.

The attached patch fixes the problem and regression tests OK. I need to do a
bit more thinking about it because I was unable to find a point in general
expression simplification where the fix could be applied. Instead, it only
seems to work in the simplification of intrinsic functions. Fortunately, this
seems to be the only place where it is needed.

Paul

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

* [Bug fortran/98458] PRINT the array constructed from implied do-loop throw ICE
  2020-12-28  4:20 [Bug fortran/98458] New: implied do-loop used in initialization with RESHAPE throw ICE xiao.liu@compiler-dev.com
                   ` (3 preceding siblings ...)
  2020-12-29 17:28 ` pault at gcc dot gnu.org
@ 2020-12-30  0:52 ` xiao.liu@compiler-dev.com
  2020-12-30  2:19 ` sgk at troutmask dot apl.washington.edu
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: xiao.liu@compiler-dev.com @ 2020-12-30  0:52 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98458

--- Comment #5 from xiao.liu@compiler-dev.com <xiao.liu@compiler-dev.com> ---
(In reply to Paul Thomas from comment #4)
> Created attachment 49856 [details]
> Fix for the PR
> 
> Thank you for the report on this problem.
> 
> The attached patch fixes the problem and regression tests OK. I need to do a
> bit more thinking about it because I was unable to find a point in general
> expression simplification where the fix could be applied. Instead, it only
> seems to work in the simplification of intrinsic functions. Fortunately,
> this seems to be the only place where it is needed.
> 
> Paul

As a beginner of FORTRAN, I am not sure about the result of implied do-loop
which contains array section, so add "print" to check. Thanks for your
attention on this problem.

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

* [Bug fortran/98458] PRINT the array constructed from implied do-loop throw ICE
  2020-12-28  4:20 [Bug fortran/98458] New: implied do-loop used in initialization with RESHAPE throw ICE xiao.liu@compiler-dev.com
                   ` (4 preceding siblings ...)
  2020-12-30  0:52 ` xiao.liu@compiler-dev.com
@ 2020-12-30  2:19 ` sgk at troutmask dot apl.washington.edu
  2020-12-30 13:40 ` [Bug fortran/98458] ICE in gfc_conv_array_initializer due to array expressions within implied do-loop pault at gcc dot gnu.org
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: sgk at troutmask dot apl.washington.edu @ 2020-12-30  2:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98458

--- Comment #6 from Steve Kargl <sgk at troutmask dot apl.washington.edu> ---
On Wed, Dec 30, 2020 at 12:52:03AM +0000, xiao.liu@compiler-dev.com wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98458
> 
> --- Comment #5 from xiao.liu@compiler-dev.com <xiao.liu@compiler-dev.com> ---
> (In reply to Paul Thomas from comment #4)
> > Created attachment 49856 [details]
> > Fix for the PR
> > 
> > Thank you for the report on this problem.
> > 
> > The attached patch fixes the problem and regression tests OK. I need to do a
> > bit more thinking about it because I was unable to find a point in general
> > expression simplification where the fix could be applied. Instead, it only
> > seems to work in the simplification of intrinsic functions. Fortunately,
> > this seems to be the only place where it is needed.
> > 
> > Paul
> 
> As a beginner of FORTRAN, I am not sure about the result of implied do-loop
> which contains array section, so add "print" to check. Thanks for your
> attention on this problem.
> 

PRINT has nothing to do with the problem.  I simply
have no interest in fixing the changed and now misleading
subject line.  I've been asked to stop.

My proposed patch fixes the issue in one spot.  Paul's
patch fixes potentially many spots.  Unfortunately, the
handling of implied do-loops is done in an ad hoc fashion,
and is complicated by the potential problem of exhausting
the stack.

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

* [Bug fortran/98458] ICE in gfc_conv_array_initializer due to array expressions within implied do-loop
  2020-12-28  4:20 [Bug fortran/98458] New: implied do-loop used in initialization with RESHAPE throw ICE xiao.liu@compiler-dev.com
                   ` (5 preceding siblings ...)
  2020-12-30  2:19 ` sgk at troutmask dot apl.washington.edu
@ 2020-12-30 13:40 ` pault at gcc dot gnu.org
  2020-12-30 18:12 ` sgk at troutmask dot apl.washington.edu
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pault at gcc dot gnu.org @ 2020-12-30 13:40 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98458

Paul Thomas <pault at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|PRINT the array constructed |ICE in
                   |from implied do-loop throw  |gfc_conv_array_initializer
                   |ICE                         |due to array expressions
                   |                            |within implied do-loop

--- Comment #7 from Paul Thomas <pault at gcc dot gnu.org> ---
(In reply to Steve Kargl from comment #6)

Hi Steve,

I didn't check for any new postings when I attached my version of the patch.
Apologies for treading on your toes.... again :-)

> PRINT has nothing to do with the problem.  I simply
> have no interest in fixing the changed and now misleading
> subject line.  I've been asked to stop.

Who asked you to stop? Anyway, I have added a slightly more informative subject
line.

> 
> My proposed patch fixes the issue in one spot.  Paul's
> patch fixes potentially many spots.  Unfortunately, the
> handling of implied do-loops is done in an ad hoc fashion,
> and is complicated by the potential problem of exhausting
> the stack.

I like your use of gfc_reduce_init_expr since it also does a type check. Note
though that it resets gfc_reduce_init_expr and so it needs to be set once again
after the call.

I had totally forgotten about the 'fatal' flag needing to be set in the call to
gfc_expand_constructor to avoid stack exhaustion. I had to rediscover it
experimentally.

A combined patch is being regtested now.

Cheers

Paul

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

* [Bug fortran/98458] ICE in gfc_conv_array_initializer due to array expressions within implied do-loop
  2020-12-28  4:20 [Bug fortran/98458] New: implied do-loop used in initialization with RESHAPE throw ICE xiao.liu@compiler-dev.com
                   ` (6 preceding siblings ...)
  2020-12-30 13:40 ` [Bug fortran/98458] ICE in gfc_conv_array_initializer due to array expressions within implied do-loop pault at gcc dot gnu.org
@ 2020-12-30 18:12 ` sgk at troutmask dot apl.washington.edu
  2021-01-05 11:39 ` pault at gcc dot gnu.org
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: sgk at troutmask dot apl.washington.edu @ 2020-12-30 18:12 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98458

--- Comment #8 from Steve Kargl <sgk at troutmask dot apl.washington.edu> ---
On Wed, Dec 30, 2020 at 01:40:22PM +0000, pault at gcc dot gnu.org wrote:
> --- Comment #7 from Paul Thomas <pault at gcc dot gnu.org> ---
> (In reply to Steve Kargl from comment #6)
> 
> Hi Steve,
> 
> I didn't check for any new postings when I attached my version
> of the patch.  Apologies for treading on your toes.... again :-)

You didn't step on any toes.  I think your original patch is
better than mine, because it applies to any place where
is_constant_array_expr() is called.  I suspect your patch is
probably better placed someplace in gfc_simplify_expr(), but
that is for another day.

> > My proposed patch fixes the issue in one spot.  Paul's
> > patch fixes potentially many spots.  Unfortunately, the
> > handling of implied do-loops is done in an ad hoc fashion,
> > and is complicated by the potential problem of exhausting
> > the stack.
> 
> I like your use of gfc_reduce_init_expr since it also does
> a type check.  Note though that it resets gfc_reduce_init_expr
> and so it needs to be set once again after the call.

Ah, good point about resetting gfc_reduce_init_expr flag.

When debugging the problem, I found that

source=[ [1,2], [2,3], [3,4] ]

so the implied do-loop was expanded, but the array was not
simplified to [1, 2, 2, 3, 3, 4].  This was causing 
gfc_simplify_reshape to return NULL. 

> I had totally forgotten about the 'fatal' flag needing to be
> set in the call to gfc_expand_constructor to avoid stack
> exhaustion. I had to rediscover it experimentally.

implied do-loops in PARAMETER statements have been a problem
for a long time.  I only remember the problem with exhausting
the stack, because I chose flag_max_array_constructor = 65535.

> A combined patch is being regtested now.

Thanks.

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

* [Bug fortran/98458] ICE in gfc_conv_array_initializer due to array expressions within implied do-loop
  2020-12-28  4:20 [Bug fortran/98458] New: implied do-loop used in initialization with RESHAPE throw ICE xiao.liu@compiler-dev.com
                   ` (7 preceding siblings ...)
  2020-12-30 18:12 ` sgk at troutmask dot apl.washington.edu
@ 2021-01-05 11:39 ` pault at gcc dot gnu.org
  2021-01-08 10:11 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pault at gcc dot gnu.org @ 2021-01-05 11:39 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98458

--- Comment #9 from Paul Thomas <pault at gcc dot gnu.org> ---
Created attachment 49883
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49883&action=edit
Updated versionof the patch

I have rolled in Steve's use of gfc_reduce_init_expr and will submit within the
hour.

Best regards

Paul

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

* [Bug fortran/98458] ICE in gfc_conv_array_initializer due to array expressions within implied do-loop
  2020-12-28  4:20 [Bug fortran/98458] New: implied do-loop used in initialization with RESHAPE throw ICE xiao.liu@compiler-dev.com
                   ` (8 preceding siblings ...)
  2021-01-05 11:39 ` pault at gcc dot gnu.org
@ 2021-01-08 10:11 ` cvs-commit at gcc dot gnu.org
  2021-05-04 12:31 ` rguenth at gcc dot gnu.org
  2023-10-31 17:19 ` pault at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-01-08 10:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98458

--- Comment #10 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Paul Thomas <pault@gcc.gnu.org>:

https://gcc.gnu.org/g:c231fca5de8e455b263495b20a416a5e47d1029a

commit r11-6538-gc231fca5de8e455b263495b20a416a5e47d1029a
Author: Paul Thomas <pault@gcc.gnu.org>
Date:   Fri Jan 8 10:11:00 2021 +0000

    Fortran:Fix simplification of constructors with implied-do [PR98458]

    2021-01-08  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.

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

* [Bug fortran/98458] ICE in gfc_conv_array_initializer due to array expressions within implied do-loop
  2020-12-28  4:20 [Bug fortran/98458] New: implied do-loop used in initialization with RESHAPE throw ICE xiao.liu@compiler-dev.com
                   ` (9 preceding siblings ...)
  2021-01-08 10:11 ` cvs-commit at gcc dot gnu.org
@ 2021-05-04 12:31 ` rguenth at gcc dot gnu.org
  2023-10-31 17:19 ` pault at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-05-04 12:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98458

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED

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

* [Bug fortran/98458] ICE in gfc_conv_array_initializer due to array expressions within implied do-loop
  2020-12-28  4:20 [Bug fortran/98458] New: implied do-loop used in initialization with RESHAPE throw ICE xiao.liu@compiler-dev.com
                   ` (10 preceding siblings ...)
  2021-05-04 12:31 ` rguenth at gcc dot gnu.org
@ 2023-10-31 17:19 ` pault at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: pault at gcc dot gnu.org @ 2023-10-31 17:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98458

Paul Thomas <pault at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #11 from Paul Thomas <pault at gcc dot gnu.org> ---
I am closing this as fixed, as I should have done a long time ago. Thanks for
the report.

Best regards

Paul

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

end of thread, other threads:[~2023-10-31 17:19 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-28  4:20 [Bug fortran/98458] New: implied do-loop used in initialization with RESHAPE throw ICE xiao.liu@compiler-dev.com
2020-12-28 12:03 ` [Bug fortran/98458] PRINT the array constructed from implied do-loop " anlauf at gcc dot gnu.org
2020-12-28 13:26 ` dominiq at lps dot ens.fr
2020-12-28 20:09 ` kargl at gcc dot gnu.org
2020-12-29 17:28 ` pault at gcc dot gnu.org
2020-12-30  0:52 ` xiao.liu@compiler-dev.com
2020-12-30  2:19 ` sgk at troutmask dot apl.washington.edu
2020-12-30 13:40 ` [Bug fortran/98458] ICE in gfc_conv_array_initializer due to array expressions within implied do-loop pault at gcc dot gnu.org
2020-12-30 18:12 ` sgk at troutmask dot apl.washington.edu
2021-01-05 11:39 ` pault at gcc dot gnu.org
2021-01-08 10:11 ` cvs-commit at gcc dot gnu.org
2021-05-04 12:31 ` rguenth at gcc dot gnu.org
2023-10-31 17:19 ` pault at gcc dot gnu.org

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).