[Bug fortran/102717] ICE in gfc_simplify_reshape, at fortran/simplify.c:6843

anlauf at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Oct 12 21:33:32 GMT 2021


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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P4
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2021-10-12
                 CC|                            |anlauf at gcc dot gnu.org
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from anlauf at gcc dot gnu.org ---
Tentative fix (not regtested):

diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c
index f40e4930b58..5d29ab23dff 100644
--- a/gcc/fortran/simplify.c
+++ b/gcc/fortran/simplify.c
@@ -6840,7 +6840,13 @@ gfc_simplify_reshape (gfc_expr *source, gfc_expr
*shape_exp,
       gfc_extract_int (e, &shape[rank]);

       gcc_assert (rank >= 0 && rank < GFC_MAX_DIMENSIONS);
-      gcc_assert (shape[rank] >= 0);
+      if (shape[rank] < 0)
+       {
+         gfc_error ("The SHAPE array for the RESHAPE intrinsic has a "
+                    "negative value %d for dimension %d",
+                    shape[rank], rank+1);
+         return &gfc_bad_expr;
+       }

       rank++;
     }


More information about the Gcc-bugs mailing list