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.

Reply via email to