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

--- Comment #9 from José Rui Faustino de Sousa <jrfsousa at gmail dot com> ---
Hi Paul!

This seems to fix the ICE generated by using -ftrapv -fcheck=bounds

Fixes "nelems" type and adds an optional assert to make sure it stays fixed.

Best regards,
José Rui


diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index be5eb89350f..7954b138605 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -9375,7 +9375,7 @@ structure_alloc_comps (gfc_symbol * der_type, tree decl,
                                                        nelems));
                }
              else
-               nelems = build_int_cst (size_type_node, 1);
+               nelems = build_int_cst (gfc_array_index_type, 1);

              if (CLASS_DATA (c)->attr.dimension
                  || CLASS_DATA (c)->attr.codimension)

diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c
index 2fa17b36c03..258e885faaa 100644
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -1446,6 +1452,7 @@ gfc_copy_class_to_class (tree from, tree to, tree nelems,
bool unlimited)
            name = (const char *)(DECL_NAME (to)->identifier.id.str);

          from_len = gfc_conv_descriptor_size (from_data, 1);
+         gcc_assert (TREE_TYPE (orig_nelems) == gfc_array_index_type);
          tmp = fold_build2_loc (input_location, NE_EXPR,
                                  logical_type_node, from_len, orig_nelems);
          msg = xasprintf ("Array bound mismatch for dimension %d "

Reply via email to