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

--- Comment #5 from anlauf at gcc dot gnu.org ---
The following patch fixes the ICE and regtests OK:

diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc
index bd586e75008..3e04f45e9ac 100644
--- a/gcc/fortran/decl.cc
+++ b/gcc/fortran/decl.cc
@@ -2775,6 +2775,17 @@ variable_decl (int elem)
                  else
                    gfc_free_expr (n);
                }
+             /* For bounds of an array spec that are both constant, ensure
+                that the upper bound is not lower than lower bound minus
+                one.  Otherwise fix it.  */
+             if (as->lower[i]->expr_type == EXPR_CONSTANT
+                 && as->upper[i]->expr_type == EXPR_CONSTANT
+                 && as->lower[i]->ts.type == BT_INTEGER
+                 && as->upper[i]->ts.type == BT_INTEGER
+                 && mpz_cmp (as->upper[i]->value.integer,
+                             as->lower[i]->value.integer) < 0)
+               mpz_sub_ui (as->upper[i]->value.integer,
+                           as->lower[i]->value.integer, 1);
            }
        }
     }

Reply via email to