public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/102521] New: ICE in gfc_conv_array_initializer, at fortran/trans-array.c:6240
@ 2021-09-28 19:10 gscfq@t-online.de
  2021-09-28 19:47 ` [Bug fortran/102521] " anlauf at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: gscfq@t-online.de @ 2021-09-28 19:10 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 102521
           Summary: ICE in gfc_conv_array_initializer, at
                    fortran/trans-array.c:6240
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gscfq@t-online.de
  Target Milestone: ---

Affects versions down to at least r5 :
(should print 1 1 1 1)


$ cat z1.f90
program p
   type t
      integer :: n
   end type
   type(t), parameter :: a(4) = t(1)
   type(t), parameter :: b(2,2) = reshape(a, [2,2])
   print *, b
end


$ gfortran-12-20210926 -c z1.f90
z1.f90:7:13:

    7 |    print *, b
      |             1
internal compiler error: in gfc_conv_array_initializer, at
fortran/trans-array.c:6240
0x85f8ea gfc_conv_array_initializer(tree_node*, gfc_expr*)
        ../../gcc/fortran/trans-array.c:6240
0x88a250 gfc_conv_initializer(gfc_expr*, gfc_typespec*, tree_node*, bool, bool,
bool)
        ../../gcc/fortran/trans-expr.c:8014
0x86c70f gfc_get_symbol_decl(gfc_symbol*)
        ../../gcc/fortran/trans-decl.c:1940
0x87be08 gfc_conv_variable
        ../../gcc/fortran/trans-expr.c:2994
0x877faa gfc_conv_expr(gfc_se*, gfc_expr*)
        ../../gcc/fortran/trans-expr.c:9041
0x87ae20 gfc_conv_expr_lhs(gfc_se*, gfc_expr*)
        ../../gcc/fortran/trans-expr.c:9071
0x84dcb8 gfc_conv_ss_descriptor
        ../../gcc/fortran/trans-array.c:3087
0x850560 gfc_conv_ss_startstride(gfc_loopinfo*)
        ../../gcc/fortran/trans-array.c:4417
0x8a9245 gfc_trans_transfer(gfc_code*)
        ../../gcc/fortran/trans-io.c:2645
0x849d57 trans_code
        ../../gcc/fortran/trans.c:2138
0x8a6bde build_dt
        ../../gcc/fortran/trans-io.c:2026
0x849d37 trans_code
        ../../gcc/fortran/trans.c:2110
0x870394 gfc_generate_function_code(gfc_namespace*)
        ../../gcc/fortran/trans-decl.c:6919
0x7f6646 translate_all_program_units
        ../../gcc/fortran/parse.c:6572
0x7f6646 gfc_parse_file()
        ../../gcc/fortran/parse.c:6841
0x842daf gfc_be_parse_file
        ../../gcc/fortran/f95-lang.c:216

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

* [Bug fortran/102521] ICE in gfc_conv_array_initializer, at fortran/trans-array.c:6240
  2021-09-28 19:10 [Bug fortran/102521] New: ICE in gfc_conv_array_initializer, at fortran/trans-array.c:6240 gscfq@t-online.de
@ 2021-09-28 19:47 ` anlauf at gcc dot gnu.org
  2021-09-29 21:14 ` anlauf at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: anlauf at gcc dot gnu.org @ 2021-09-28 19:47 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-09-28
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

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

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

* [Bug fortran/102521] ICE in gfc_conv_array_initializer, at fortran/trans-array.c:6240
  2021-09-28 19:10 [Bug fortran/102521] New: ICE in gfc_conv_array_initializer, at fortran/trans-array.c:6240 gscfq@t-online.de
  2021-09-28 19:47 ` [Bug fortran/102521] " anlauf at gcc dot gnu.org
@ 2021-09-29 21:14 ` anlauf at gcc dot gnu.org
  2021-10-01 18:43 ` anlauf at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: anlauf at gcc dot gnu.org @ 2021-09-29 21:14 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

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

--- Comment #2 from anlauf at gcc dot gnu.org ---
Possibly related:

program p
  type t
     integer :: n
  end type
  type(t), parameter :: a(4)   = t(1)
  type(t), parameter :: c(*)   = a
end

This gives an ICE already in add_init_expr_to_sym.
So we likely screw up long before trans*.

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

* [Bug fortran/102521] ICE in gfc_conv_array_initializer, at fortran/trans-array.c:6240
  2021-09-28 19:10 [Bug fortran/102521] New: ICE in gfc_conv_array_initializer, at fortran/trans-array.c:6240 gscfq@t-online.de
  2021-09-28 19:47 ` [Bug fortran/102521] " anlauf at gcc dot gnu.org
  2021-09-29 21:14 ` anlauf at gcc dot gnu.org
@ 2021-10-01 18:43 ` anlauf at gcc dot gnu.org
  2021-10-02 19:39 ` anlauf at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: anlauf at gcc dot gnu.org @ 2021-10-01 18:43 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from anlauf at gcc dot gnu.org ---
The code works if we replace the r.h.s. in the initialization by an array:

program p
  type t
     integer :: n
  end type
! type(t), parameter :: a(4)   = t(1)                            ! ICE
  type(t), parameter :: a(4)   = spread (t(1), dim=1, ncopies=4) ! works
  type(t), parameter :: c(*)   = a
  type(t), parameter :: b(2,2) = reshape(a, [2,2])
  print *, b
end

The code in add_init_expr_to_sym looks fishy.  We might possibly handle the
ICEing code here but don't:

2224          /* Add initializer.  Make sure we keep the ranks sane.  */
2225          if (sym->attr.dimension && init->rank == 0)
2226            {
2227              mpz_t size;
2228              gfc_expr *array;
2229              int n;
2230              if (sym->attr.flavor == FL_PARAMETER
2231                    && init->expr_type == EXPR_CONSTANT
2232                    && spec_size (sym->as, &size)
2233                    && mpz_cmp_si (size, 0) > 0)

(gdb) p init->expr_type
$1 = EXPR_STRUCTURE

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

* [Bug fortran/102521] ICE in gfc_conv_array_initializer, at fortran/trans-array.c:6240
  2021-09-28 19:10 [Bug fortran/102521] New: ICE in gfc_conv_array_initializer, at fortran/trans-array.c:6240 gscfq@t-online.de
                   ` (2 preceding siblings ...)
  2021-10-01 18:43 ` anlauf at gcc dot gnu.org
@ 2021-10-02 19:39 ` anlauf at gcc dot gnu.org
  2021-10-03 19:22 ` anlauf at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: anlauf at gcc dot gnu.org @ 2021-10-02 19:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from anlauf at gcc dot gnu.org ---
Tentative patch:

diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
index b3c65b7175b..cebc59e4ab5 100644
--- a/gcc/fortran/decl.c
+++ b/gcc/fortran/decl.c
@@ -2228,12 +2228,15 @@ add_init_expr_to_sym (const char *name, gfc_expr
**initp, locus *var_locus)
          gfc_expr *array;
          int n;
          if (sym->attr.flavor == FL_PARAMETER
-               && init->expr_type == EXPR_CONSTANT
-               && spec_size (sym->as, &size)
-               && mpz_cmp_si (size, 0) > 0)
+             && (init->expr_type == EXPR_CONSTANT
+                 || init->expr_type == EXPR_STRUCTURE)
+             && spec_size (sym->as, &size)
+             && mpz_cmp_si (size, 0) > 0)
            {
              array = gfc_get_array_expr (init->ts.type, init->ts.kind,
                                          &init->where);
+             if (init->ts.type == BT_DERIVED)
+               array->ts.u.derived = init->ts.u.derived;
              for (n = 0; n < (int)mpz_get_si (size); n++)
                gfc_constructor_append_expr (&array->value.constructor,
                                             n == 0

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

* [Bug fortran/102521] ICE in gfc_conv_array_initializer, at fortran/trans-array.c:6240
  2021-09-28 19:10 [Bug fortran/102521] New: ICE in gfc_conv_array_initializer, at fortran/trans-array.c:6240 gscfq@t-online.de
                   ` (3 preceding siblings ...)
  2021-10-02 19:39 ` anlauf at gcc dot gnu.org
@ 2021-10-03 19:22 ` anlauf at gcc dot gnu.org
  2021-10-10 18:12 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: anlauf at gcc dot gnu.org @ 2021-10-03 19:22 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |anlauf at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

--- Comment #5 from anlauf at gcc dot gnu.org ---
Submitted: https://gcc.gnu.org/pipermail/fortran/2021-October/056617.html

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

* [Bug fortran/102521] ICE in gfc_conv_array_initializer, at fortran/trans-array.c:6240
  2021-09-28 19:10 [Bug fortran/102521] New: ICE in gfc_conv_array_initializer, at fortran/trans-array.c:6240 gscfq@t-online.de
                   ` (4 preceding siblings ...)
  2021-10-03 19:22 ` anlauf at gcc dot gnu.org
@ 2021-10-10 18:12 ` cvs-commit at gcc dot gnu.org
  2021-11-07 20:54 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-10-10 18:12 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>:

https://gcc.gnu.org/g:74ccca380cde5e79e082d39214b306a90ded0344

commit r12-4278-g74ccca380cde5e79e082d39214b306a90ded0344
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Sun Oct 10 20:11:43 2021 +0200

    Fortran: handle initialization of derived type parameter arrays from scalar

    gcc/fortran/ChangeLog:

            PR fortran/99348
            PR fortran/102521
            * decl.c (add_init_expr_to_sym): Extend initialization of
            parameter arrays from scalars to handle derived types.

    gcc/testsuite/ChangeLog:

            PR fortran/99348
            PR fortran/102521
            * gfortran.dg/parameter_array_init_8.f90: New test.

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

* [Bug fortran/102521] ICE in gfc_conv_array_initializer, at fortran/trans-array.c:6240
  2021-09-28 19:10 [Bug fortran/102521] New: ICE in gfc_conv_array_initializer, at fortran/trans-array.c:6240 gscfq@t-online.de
                   ` (5 preceding siblings ...)
  2021-10-10 18:12 ` cvs-commit at gcc dot gnu.org
@ 2021-11-07 20:54 ` cvs-commit at gcc dot gnu.org
  2021-11-13 20:15 ` cvs-commit at gcc dot gnu.org
  2021-11-13 20:16 ` anlauf at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-11-07 20:54 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Harald Anlauf
<anlauf@gcc.gnu.org>:

https://gcc.gnu.org/g:1b740d8000cac8048c728fb0bd75c71464eeee29

commit r11-9213-g1b740d8000cac8048c728fb0bd75c71464eeee29
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Sun Oct 10 20:11:43 2021 +0200

    Fortran: handle initialization of derived type parameter arrays from scalar

    gcc/fortran/ChangeLog:

            PR fortran/99348
            PR fortran/102521
            * decl.c (add_init_expr_to_sym): Extend initialization of
            parameter arrays from scalars to handle derived types.

    gcc/testsuite/ChangeLog:

            PR fortran/99348
            PR fortran/102521
            * gfortran.dg/parameter_array_init_8.f90: New test.

    (cherry picked from commit 74ccca380cde5e79e082d39214b306a90ded0344)

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

* [Bug fortran/102521] ICE in gfc_conv_array_initializer, at fortran/trans-array.c:6240
  2021-09-28 19:10 [Bug fortran/102521] New: ICE in gfc_conv_array_initializer, at fortran/trans-array.c:6240 gscfq@t-online.de
                   ` (6 preceding siblings ...)
  2021-11-07 20:54 ` cvs-commit at gcc dot gnu.org
@ 2021-11-13 20:15 ` cvs-commit at gcc dot gnu.org
  2021-11-13 20:16 ` anlauf at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-11-13 20:15 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Harald Anlauf
<anlauf@gcc.gnu.org>:

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

commit r10-10267-gcb85933717e52f1cd91786e6bb595494629ca5c9
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Sun Oct 10 20:11:43 2021 +0200

    Fortran: handle initialization of derived type parameter arrays from scalar

    gcc/fortran/ChangeLog:

            PR fortran/99348
            PR fortran/102521
            * decl.c (add_init_expr_to_sym): Extend initialization of
            parameter arrays from scalars to handle derived types.

    gcc/testsuite/ChangeLog:

            PR fortran/99348
            PR fortran/102521
            * gfortran.dg/parameter_array_init_8.f90: New test.

    (cherry picked from commit 74ccca380cde5e79e082d39214b306a90ded0344)

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

* [Bug fortran/102521] ICE in gfc_conv_array_initializer, at fortran/trans-array.c:6240
  2021-09-28 19:10 [Bug fortran/102521] New: ICE in gfc_conv_array_initializer, at fortran/trans-array.c:6240 gscfq@t-online.de
                   ` (7 preceding siblings ...)
  2021-11-13 20:15 ` cvs-commit at gcc dot gnu.org
@ 2021-11-13 20:16 ` anlauf at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: anlauf at gcc dot gnu.org @ 2021-11-13 20:16 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

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

--- Comment #9 from anlauf at gcc dot gnu.org ---
Fixed on mainline for gcc-12, and on 11- and 10-branch.  Closing.

Thanks for the report!

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

end of thread, other threads:[~2021-11-13 20:16 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-28 19:10 [Bug fortran/102521] New: ICE in gfc_conv_array_initializer, at fortran/trans-array.c:6240 gscfq@t-online.de
2021-09-28 19:47 ` [Bug fortran/102521] " anlauf at gcc dot gnu.org
2021-09-29 21:14 ` anlauf at gcc dot gnu.org
2021-10-01 18:43 ` anlauf at gcc dot gnu.org
2021-10-02 19:39 ` anlauf at gcc dot gnu.org
2021-10-03 19:22 ` anlauf at gcc dot gnu.org
2021-10-10 18:12 ` cvs-commit at gcc dot gnu.org
2021-11-07 20:54 ` cvs-commit at gcc dot gnu.org
2021-11-13 20:15 ` cvs-commit at gcc dot gnu.org
2021-11-13 20:16 ` anlauf 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).