public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/104127] New: [9/10/11/12 Regression] ICE in get_array_charlen, at fortran/trans-array.c:7244
@ 2022-01-19 18:46 gscfq@t-online.de
  2022-01-19 19:24 ` [Bug fortran/104127] " anlauf at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: gscfq@t-online.de @ 2022-01-19 18:46 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 104127
           Summary: [9/10/11/12 Regression] ICE in get_array_charlen, at
                    fortran/trans-array.c:7244
           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: ---

Started between 20190310 and 20190331 :


$ cat z1.f90
program p
   call sub (transfer(4_'abcd', 4_'xy', size=0))
end


$ gfortran-8 -c z1.f90
$
$ gfortran-12-20220116 -c z1.f90
z1.f90:2:48:

    2 |    call sub (transfer(4_'abcd', 4_'xy', size=0))
      |                                                1
internal compiler error: Segmentation fault
0xcc359f crash_signal
        ../../gcc/toplev.c:322
0x7b5564 get_array_charlen
        ../../gcc/fortran/trans-array.c:7244
0x7b4a66 gfc_conv_expr_descriptor(gfc_se*, gfc_expr*)
        ../../gcc/fortran/trans-array.c:7680
0x7ba8eb gfc_conv_array_parameter(gfc_se*, gfc_expr*, bool, gfc_symbol const*,
char const*, tree_node**)
        ../../gcc/fortran/trans-array.c:8370
0x7df1d9 gfc_conv_procedure_call(gfc_se*, gfc_symbol*, gfc_actual_arglist*,
gfc_expr*, vec<tree_node*, va_gc, vl_embed>*)
        ../../gcc/fortran/trans-expr.c:6860
0x81d120 gfc_trans_call(gfc_code*, bool, tree_node*, tree_node*, bool)
        ../../gcc/fortran/trans-stmt.c:422
0x7a55f8 trans_code
        ../../gcc/fortran/trans.c:1984
0x7ce56e gfc_generate_function_code(gfc_namespace*)
        ../../gcc/fortran/trans-decl.c:7651
0x7513ce translate_all_program_units
        ../../gcc/fortran/parse.c:6651
0x7513ce gfc_parse_file()
        ../../gcc/fortran/parse.c:6938
0x79e33f gfc_be_parse_file
        ../../gcc/fortran/f95-lang.c:216

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

* [Bug fortran/104127] [9/10/11/12 Regression] ICE in get_array_charlen, at fortran/trans-array.c:7244
  2022-01-19 18:46 [Bug fortran/104127] New: [9/10/11/12 Regression] ICE in get_array_charlen, at fortran/trans-array.c:7244 gscfq@t-online.de
@ 2022-01-19 19:24 ` anlauf at gcc dot gnu.org
  2022-01-19 19:49 ` anlauf at gcc dot gnu.org
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: anlauf at gcc dot gnu.org @ 2022-01-19 19:24 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
                 CC|                            |anlauf at gcc dot gnu.org
   Last reconfirmed|                            |2022-01-19
             Status|UNCONFIRMED                 |NEW

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

Happens even for default character, e.g.

  call sub (transfer('a', 'y', size=0))

Likely an issue with the result being an array of size 0.

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

* [Bug fortran/104127] [9/10/11/12 Regression] ICE in get_array_charlen, at fortran/trans-array.c:7244
  2022-01-19 18:46 [Bug fortran/104127] New: [9/10/11/12 Regression] ICE in get_array_charlen, at fortran/trans-array.c:7244 gscfq@t-online.de
  2022-01-19 19:24 ` [Bug fortran/104127] " anlauf at gcc dot gnu.org
@ 2022-01-19 19:49 ` anlauf at gcc dot gnu.org
  2022-01-19 20:43 ` anlauf at gcc dot gnu.org
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: anlauf at gcc dot gnu.org @ 2022-01-19 19:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from anlauf at gcc dot gnu.org ---
We die here:

(gdb) l 7244
7239        case EXPR_ARRAY:
7240
7241          /* This is somewhat brutal. The expression for the first
7242             element of the array is evaluated and assigned to a
7243             new string length for the original expression.  */
7244          e = gfc_constructor_first (expr->value.constructor)->expr;
7245
7246          gfc_init_se (&tse, NULL);
7247
7248          /* Avoid evaluating trailing array references since all we need
is

(gdb) p expr->value.constructor
$45 = (gfc_constructor_base) 0x0
(gdb) p expr->ts.u.cl->length
$46 = (gfc_expr *) 0x0
(gdb) p *expr->shape[0]
$47 = {_mp_alloc = 1, _mp_size = 0, _mp_d = 0x2f0c840}

The shape is correct, but the character length is lost.
We could handle a zero-sized array but need the right spec.

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

* [Bug fortran/104127] [9/10/11/12 Regression] ICE in get_array_charlen, at fortran/trans-array.c:7244
  2022-01-19 18:46 [Bug fortran/104127] New: [9/10/11/12 Regression] ICE in get_array_charlen, at fortran/trans-array.c:7244 gscfq@t-online.de
  2022-01-19 19:24 ` [Bug fortran/104127] " anlauf at gcc dot gnu.org
  2022-01-19 19:49 ` anlauf at gcc dot gnu.org
@ 2022-01-19 20:43 ` anlauf at gcc dot gnu.org
  2022-01-20  7:56 ` rguenth at gcc dot gnu.org
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: anlauf at gcc dot gnu.org @ 2022-01-19 20:43 UTC (permalink / raw)
  To: gcc-bugs

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

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

diff --git a/gcc/fortran/simplify.cc b/gcc/fortran/simplify.cc
index 3881370d947..366b00c28dd 100644
--- a/gcc/fortran/simplify.cc
+++ b/gcc/fortran/simplify.cc
@@ -8162,7 +8162,15 @@ gfc_simplify_transfer (gfc_expr *source, gfc_expr *mold,
gfc_expr *size)
      set even for array expressions, in order to pass this information into
      gfc_target_interpret_expr.  */
   if (result->ts.type == BT_CHARACTER && gfc_is_constant_expr (mold_element))
-    result->value.character.length = mold_element->value.character.length;
+    {
+      result->value.character.length = mold_element->value.character.length;
+
+      /* A zero-sized result array needs to inherit the string length.  */
+      if (result_length == 0)
+       result->ts.u.cl->length =
+         gfc_get_int_expr (gfc_charlen_int_kind, NULL,
+                           mold_element->value.character.length);
+    }

   /* Set the number of elements in the result, and determine its size.  */


This fixes the ICE as well as now produces a correct result e.g. for

  print *, len (transfer('ab', 'xyz', size=0))

However, looking at the tree dump of comment#0 I see very similar multiple
temporaries being generated as for other empty array constructors being passed
to procedures (pr86277).

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

* [Bug fortran/104127] [9/10/11/12 Regression] ICE in get_array_charlen, at fortran/trans-array.c:7244
  2022-01-19 18:46 [Bug fortran/104127] New: [9/10/11/12 Regression] ICE in get_array_charlen, at fortran/trans-array.c:7244 gscfq@t-online.de
                   ` (2 preceding siblings ...)
  2022-01-19 20:43 ` anlauf at gcc dot gnu.org
@ 2022-01-20  7:56 ` rguenth at gcc dot gnu.org
  2022-01-20 10:16 ` marxin at gcc dot gnu.org
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-01-20  7:56 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |9.5
           Priority|P3                          |P4

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

* [Bug fortran/104127] [9/10/11/12 Regression] ICE in get_array_charlen, at fortran/trans-array.c:7244
  2022-01-19 18:46 [Bug fortran/104127] New: [9/10/11/12 Regression] ICE in get_array_charlen, at fortran/trans-array.c:7244 gscfq@t-online.de
                   ` (3 preceding siblings ...)
  2022-01-20  7:56 ` rguenth at gcc dot gnu.org
@ 2022-01-20 10:16 ` marxin at gcc dot gnu.org
  2022-01-20 21:49 ` anlauf at gcc dot gnu.org
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-01-20 10:16 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |marxin at gcc dot gnu.org,
                   |                            |pault at gcc dot gnu.org

--- Comment #4 from Martin Liška <marxin at gcc dot gnu.org> ---
Started with r9-6726-gd5f48c7c62d3d8cf.

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

* [Bug fortran/104127] [9/10/11/12 Regression] ICE in get_array_charlen, at fortran/trans-array.c:7244
  2022-01-19 18:46 [Bug fortran/104127] New: [9/10/11/12 Regression] ICE in get_array_charlen, at fortran/trans-array.c:7244 gscfq@t-online.de
                   ` (4 preceding siblings ...)
  2022-01-20 10:16 ` marxin at gcc dot gnu.org
@ 2022-01-20 21:49 ` anlauf at gcc dot gnu.org
  2022-01-22 15:09 ` cvs-commit at gcc dot gnu.org
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: anlauf at gcc dot gnu.org @ 2022-01-20 21:49 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

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

--- Comment #5 from anlauf at gcc dot gnu.org ---
Submitted: https://gcc.gnu.org/pipermail/fortran/2022-January/057428.html

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

* [Bug fortran/104127] [9/10/11/12 Regression] ICE in get_array_charlen, at fortran/trans-array.c:7244
  2022-01-19 18:46 [Bug fortran/104127] New: [9/10/11/12 Regression] ICE in get_array_charlen, at fortran/trans-array.c:7244 gscfq@t-online.de
                   ` (5 preceding siblings ...)
  2022-01-20 21:49 ` anlauf at gcc dot gnu.org
@ 2022-01-22 15:09 ` cvs-commit at gcc dot gnu.org
  2022-01-26 18:16 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-01-22 15:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- 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:6c1a93102b41a558f3ad49a7c66015257535c747

commit r12-6816-g6c1a93102b41a558f3ad49a7c66015257535c747
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Thu Jan 20 22:36:50 2022 +0100

    Fortran: fix simplification of TRANSFER for zero-sized character array
result

    gcc/fortran/ChangeLog:

            PR fortran/104127
            * simplify.cc (gfc_simplify_transfer): Ensure that the result
            typespec is set up for TRANSFER with MOLD of type CHARACTER
            including character length even if the result is a zero-sized
            array.

    gcc/testsuite/ChangeLog:

            PR fortran/104127
            * gfortran.dg/transfer_simplify_11.f90: Fix logic.
            * gfortran.dg/transfer_simplify_13.f90: New test.

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

* [Bug fortran/104127] [9/10/11/12 Regression] ICE in get_array_charlen, at fortran/trans-array.c:7244
  2022-01-19 18:46 [Bug fortran/104127] New: [9/10/11/12 Regression] ICE in get_array_charlen, at fortran/trans-array.c:7244 gscfq@t-online.de
                   ` (6 preceding siblings ...)
  2022-01-22 15:09 ` cvs-commit at gcc dot gnu.org
@ 2022-01-26 18:16 ` cvs-commit at gcc dot gnu.org
  2022-01-29 22:06 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-01-26 18:16 UTC (permalink / raw)
  To: gcc-bugs

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

--- 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:c3251374af4b82888b6be3eb9cfa6b0b3944907b

commit r11-9516-gc3251374af4b82888b6be3eb9cfa6b0b3944907b
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Thu Jan 20 22:36:50 2022 +0100

    Fortran: fix simplification of TRANSFER for zero-sized character array
result

    gcc/fortran/ChangeLog:

            PR fortran/104127
            * simplify.c (gfc_simplify_transfer): Ensure that the result
            typespec is set up for TRANSFER with MOLD of type CHARACTER
            including character length even if the result is a zero-sized
            array.

    gcc/testsuite/ChangeLog:

            PR fortran/104127
            * gfortran.dg/transfer_simplify_11.f90: Fix logic.
            * gfortran.dg/transfer_simplify_13.f90: New test.

    (cherry picked from commit 6c1a93102b41a558f3ad49a7c66015257535c747)

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

* [Bug fortran/104127] [9/10/11/12 Regression] ICE in get_array_charlen, at fortran/trans-array.c:7244
  2022-01-19 18:46 [Bug fortran/104127] New: [9/10/11/12 Regression] ICE in get_array_charlen, at fortran/trans-array.c:7244 gscfq@t-online.de
                   ` (7 preceding siblings ...)
  2022-01-26 18:16 ` cvs-commit at gcc dot gnu.org
@ 2022-01-29 22:06 ` cvs-commit at gcc dot gnu.org
  2022-01-29 22:33 ` [Bug fortran/104127] [9 " anlauf at gcc dot gnu.org
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-01-29 22:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- 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:6da0c19bdcf992bd18c32335342fc3511683f314

commit r10-10426-g6da0c19bdcf992bd18c32335342fc3511683f314
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Thu Jan 20 22:36:50 2022 +0100

    Fortran: fix simplification of TRANSFER for zero-sized character array
result

    gcc/fortran/ChangeLog:

            PR fortran/104127
            * simplify.c (gfc_simplify_transfer): Ensure that the result
            typespec is set up for TRANSFER with MOLD of type CHARACTER
            including character length even if the result is a zero-sized
            array.

    gcc/testsuite/ChangeLog:

            PR fortran/104127
            * gfortran.dg/transfer_simplify_11.f90: Fix logic.
            * gfortran.dg/transfer_simplify_13.f90: New test.

    (cherry picked from commit 6c1a93102b41a558f3ad49a7c66015257535c747)

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

* [Bug fortran/104127] [9 Regression] ICE in get_array_charlen, at fortran/trans-array.c:7244
  2022-01-19 18:46 [Bug fortran/104127] New: [9/10/11/12 Regression] ICE in get_array_charlen, at fortran/trans-array.c:7244 gscfq@t-online.de
                   ` (8 preceding siblings ...)
  2022-01-29 22:06 ` cvs-commit at gcc dot gnu.org
@ 2022-01-29 22:33 ` anlauf at gcc dot gnu.org
  2022-01-29 23:14 ` cvs-commit at gcc dot gnu.org
  2022-01-29 23:17 ` anlauf at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: anlauf at gcc dot gnu.org @ 2022-01-29 22:33 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[9/10/11/12 Regression] ICE |[9 Regression] ICE in
                   |in get_array_charlen, at    |get_array_charlen, at
                   |fortran/trans-array.c:7244  |fortran/trans-array.c:7244

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

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

* [Bug fortran/104127] [9 Regression] ICE in get_array_charlen, at fortran/trans-array.c:7244
  2022-01-19 18:46 [Bug fortran/104127] New: [9/10/11/12 Regression] ICE in get_array_charlen, at fortran/trans-array.c:7244 gscfq@t-online.de
                   ` (9 preceding siblings ...)
  2022-01-29 22:33 ` [Bug fortran/104127] [9 " anlauf at gcc dot gnu.org
@ 2022-01-29 23:14 ` cvs-commit at gcc dot gnu.org
  2022-01-29 23:17 ` anlauf at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-01-29 23:14 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

commit r9-9932-gbb05ddea976a7a8b3f02175050a5d53356ccab9d
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Thu Jan 20 22:36:50 2022 +0100

    Fortran: fix simplification of TRANSFER for zero-sized character array
result

    gcc/fortran/ChangeLog:

            PR fortran/104127
            * simplify.c (gfc_simplify_transfer): Ensure that the result
            typespec is set up for TRANSFER with MOLD of type CHARACTER
            including character length even if the result is a zero-sized
            array.

    gcc/testsuite/ChangeLog:

            PR fortran/104127
            * gfortran.dg/transfer_simplify_11.f90: Fix logic.
            * gfortran.dg/transfer_simplify_13.f90: New test.

    (cherry picked from commit 6c1a93102b41a558f3ad49a7c66015257535c747)

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

* [Bug fortran/104127] [9 Regression] ICE in get_array_charlen, at fortran/trans-array.c:7244
  2022-01-19 18:46 [Bug fortran/104127] New: [9/10/11/12 Regression] ICE in get_array_charlen, at fortran/trans-array.c:7244 gscfq@t-online.de
                   ` (10 preceding siblings ...)
  2022-01-29 23:14 ` cvs-commit at gcc dot gnu.org
@ 2022-01-29 23:17 ` anlauf at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: anlauf at gcc dot gnu.org @ 2022-01-29 23:17 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

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

--- Comment #11 from anlauf at gcc dot gnu.org ---
Fixed on 9-branch for the reported testcase.

The extended testcase committed on 10-branch and higher needed deactivating
of two lines which seem to require additional fixes and likely failed before.

Closing.

Thanks for the report!

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

end of thread, other threads:[~2022-01-29 23:17 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-19 18:46 [Bug fortran/104127] New: [9/10/11/12 Regression] ICE in get_array_charlen, at fortran/trans-array.c:7244 gscfq@t-online.de
2022-01-19 19:24 ` [Bug fortran/104127] " anlauf at gcc dot gnu.org
2022-01-19 19:49 ` anlauf at gcc dot gnu.org
2022-01-19 20:43 ` anlauf at gcc dot gnu.org
2022-01-20  7:56 ` rguenth at gcc dot gnu.org
2022-01-20 10:16 ` marxin at gcc dot gnu.org
2022-01-20 21:49 ` anlauf at gcc dot gnu.org
2022-01-22 15:09 ` cvs-commit at gcc dot gnu.org
2022-01-26 18:16 ` cvs-commit at gcc dot gnu.org
2022-01-29 22:06 ` cvs-commit at gcc dot gnu.org
2022-01-29 22:33 ` [Bug fortran/104127] [9 " anlauf at gcc dot gnu.org
2022-01-29 23:14 ` cvs-commit at gcc dot gnu.org
2022-01-29 23:17 ` 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).