public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/106049] New: ICE in gfc_simplify_pack, at fortran/simplify.cc:6481
@ 2022-06-21 18:52 gscfq@t-online.de
  2022-06-22 19:51 ` [Bug fortran/106049] " anlauf at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: gscfq@t-online.de @ 2022-06-21 18:52 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 106049
           Summary: ICE in gfc_simplify_pack, at fortran/simplify.cc:6481
           Product: gcc
           Version: 13.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 :


$ cat z1.f90
program p
   type t
   end type
   type(t), parameter :: a = [t ::]
   type(t), parameter :: b(1,1) = a
   type(t) :: c(1) = pack(reshape(b, [1]), [.true.])
end


$ gfortran-13-20220619 -c z1.f90
f951: internal compiler error: Segmentation fault
0xcd90df crash_signal
        ../../gcc/toplev.cc:322
0x7929dd gfc_simplify_pack(gfc_expr*, gfc_expr*, gfc_expr*)
        ../../gcc/fortran/simplify.cc:6481
0x70f64a do_simplify
        ../../gcc/fortran/intrinsic.cc:4677
0x71a52a gfc_intrinsic_func_interface(gfc_expr*, int)
        ../../gcc/fortran/intrinsic.cc:5056
0x76f068 resolve_unknown_f
        ../../gcc/fortran/resolve.cc:2990
0x76f068 resolve_function
        ../../gcc/fortran/resolve.cc:3347
0x76f068 gfc_resolve_expr(gfc_expr*)
        ../../gcc/fortran/resolve.cc:7187
0x6ff504 gfc_reduce_init_expr(gfc_expr*)
        ../../gcc/fortran/expr.cc:3163
0x702490 gfc_match_init_expr(gfc_expr**)
        ../../gcc/fortran/expr.cc:3211
0x6ec7d4 variable_decl
        ../../gcc/fortran/decl.cc:3004
0x6ec7d4 gfc_match_data_decl()
        ../../gcc/fortran/decl.cc:6299
0x757583 match_word
        ../../gcc/fortran/parse.cc:67
0x757583 decode_statement
        ../../gcc/fortran/parse.cc:378
0x758fca next_free
        ../../gcc/fortran/parse.cc:1397
0x758fca next_statement
        ../../gcc/fortran/parse.cc:1629
0x75a55b parse_spec
        ../../gcc/fortran/parse.cc:4168
0x75d6fc parse_progunit
        ../../gcc/fortran/parse.cc:6210
0x75edc1 gfc_parse_file()
        ../../gcc/fortran/parse.cc:6755
0x7acb6f gfc_be_parse_file
        ../../gcc/fortran/f95-lang.cc:229

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

* [Bug fortran/106049] ICE in gfc_simplify_pack, at fortran/simplify.cc:6481
  2022-06-21 18:52 [Bug fortran/106049] New: ICE in gfc_simplify_pack, at fortran/simplify.cc:6481 gscfq@t-online.de
@ 2022-06-22 19:51 ` anlauf at gcc dot gnu.org
  2022-07-05 20:09 ` anlauf at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: anlauf at gcc dot gnu.org @ 2022-06-22 19:51 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

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

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

Error recovery issue while trying to simplify pack.
The chain of bad declarations passes an invalid constructor for the ARRAY
argument.

The following patch solves the problem at hand:

diff --git a/gcc/fortran/simplify.cc b/gcc/fortran/simplify.cc
index e8e3ec63669..c4ba2e615a1 100644
--- a/gcc/fortran/simplify.cc
+++ b/gcc/fortran/simplify.cc
@@ -6373,6 +6374,10 @@ gfc_simplify_pack (gfc_expr *array, gfc_expr *mask,
gfc_expr *vector)
           && !is_constant_array_expr (mask)))
     return NULL;

+  if (mask->expr_type == EXPR_ARRAY
+      && gfc_is_size_zero_array (mask) != gfc_is_size_zero_array (array))
+    return NULL;
+
   result = gfc_get_array_expr (array->ts.type, array->ts.kind, &array->where);
   if (array->ts.type == BT_DERIVED)
     result->ts.u.derived = array->ts.u.derived;

Maybe there is a better solution.

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

* [Bug fortran/106049] ICE in gfc_simplify_pack, at fortran/simplify.cc:6481
  2022-06-21 18:52 [Bug fortran/106049] New: ICE in gfc_simplify_pack, at fortran/simplify.cc:6481 gscfq@t-online.de
  2022-06-22 19:51 ` [Bug fortran/106049] " anlauf at gcc dot gnu.org
@ 2022-07-05 20:09 ` anlauf at gcc dot gnu.org
  2022-07-05 20:33 ` anlauf at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: anlauf at gcc dot gnu.org @ 2022-07-05 20:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from anlauf at gcc dot gnu.org ---
(In reply to anlauf from comment #1)
> Maybe there is a better solution.

Here's an alternative, probably more general approach that modifies
is_constant_array_expr: when the array size - as implied by the shape -
is larger than zero, but the constructor is empty, then something went
wrong, and we return false:

diff --git a/gcc/fortran/simplify.cc b/gcc/fortran/simplify.cc
index ab59fbca622..fb725994653 100644
--- a/gcc/fortran/simplify.cc
+++ b/gcc/fortran/simplify.cc
@@ -233,6 +233,18 @@ is_constant_array_expr (gfc_expr *e)
   if (e->expr_type != EXPR_ARRAY || !gfc_is_constant_expr (e))
     return false;

+  /* A non-zero-sized constant array shall have a non-empty constructor.  */
+  if (e->rank > 0 && e->shape != NULL && e->value.constructor == NULL)
+    {
+      mpz_init_set_ui (size, 1);
+      for (int j = 0; j < e->rank; j++)
+       mpz_mul (size, size, e->shape[j]);
+      bool not_size0 = (mpz_cmp_si (size, 0) != 0);
+      mpz_clear (size);
+      if (not_size0)
+       return false;
+    }
+
   for (c = gfc_constructor_first (e->value.constructor);
        c; c = gfc_constructor_next (c))
     if (c->expr->expr_type != EXPR_CONSTANT

This seems to regtest OK.

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

* [Bug fortran/106049] ICE in gfc_simplify_pack, at fortran/simplify.cc:6481
  2022-06-21 18:52 [Bug fortran/106049] New: ICE in gfc_simplify_pack, at fortran/simplify.cc:6481 gscfq@t-online.de
  2022-06-22 19:51 ` [Bug fortran/106049] " anlauf at gcc dot gnu.org
  2022-07-05 20:09 ` anlauf at gcc dot gnu.org
@ 2022-07-05 20:33 ` anlauf at gcc dot gnu.org
  2022-07-12 18:20 ` cvs-commit at gcc dot gnu.org
  2022-07-12 18:25 ` anlauf at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: anlauf at gcc dot gnu.org @ 2022-07-05 20:33 UTC (permalink / raw)
  To: gcc-bugs

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

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 #3 from anlauf at gcc dot gnu.org ---
Submitted: https://gcc.gnu.org/pipermail/fortran/2022-July/057990.html

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

* [Bug fortran/106049] ICE in gfc_simplify_pack, at fortran/simplify.cc:6481
  2022-06-21 18:52 [Bug fortran/106049] New: ICE in gfc_simplify_pack, at fortran/simplify.cc:6481 gscfq@t-online.de
                   ` (2 preceding siblings ...)
  2022-07-05 20:33 ` anlauf at gcc dot gnu.org
@ 2022-07-12 18:20 ` cvs-commit at gcc dot gnu.org
  2022-07-12 18:25 ` anlauf at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-07-12 18:20 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 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:6e9d5dfc2911e3acc6039ebfe3837e7ba4be197f

commit r13-1650-g6e9d5dfc2911e3acc6039ebfe3837e7ba4be197f
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Tue Jul 5 22:20:05 2022 +0200

    Fortran: error recovery simplifying PACK with invalid arguments [PR106049]

    gcc/fortran/ChangeLog:

            PR fortran/106049
            * simplify.cc (is_constant_array_expr): A non-zero-sized constant
            array shall have a non-empty constructor.  When the constructor is
            empty or missing, treat as non-constant.

    gcc/testsuite/ChangeLog:

            PR fortran/106049
            * gfortran.dg/pack_simplify_1.f90: New test.

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

* [Bug fortran/106049] ICE in gfc_simplify_pack, at fortran/simplify.cc:6481
  2022-06-21 18:52 [Bug fortran/106049] New: ICE in gfc_simplify_pack, at fortran/simplify.cc:6481 gscfq@t-online.de
                   ` (3 preceding siblings ...)
  2022-07-12 18:20 ` cvs-commit at gcc dot gnu.org
@ 2022-07-12 18:25 ` anlauf at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: anlauf at gcc dot gnu.org @ 2022-07-12 18:25 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

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

--- Comment #5 from anlauf at gcc dot gnu.org ---
Fixed.

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

end of thread, other threads:[~2022-07-12 18:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-21 18:52 [Bug fortran/106049] New: ICE in gfc_simplify_pack, at fortran/simplify.cc:6481 gscfq@t-online.de
2022-06-22 19:51 ` [Bug fortran/106049] " anlauf at gcc dot gnu.org
2022-07-05 20:09 ` anlauf at gcc dot gnu.org
2022-07-05 20:33 ` anlauf at gcc dot gnu.org
2022-07-12 18:20 ` cvs-commit at gcc dot gnu.org
2022-07-12 18:25 ` 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).