[Bug fortran/93685] [9/10/11 Regression] ICE in gfc_constructor_append_expr, at fortran/constructor.c:135

anlauf at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Sun Dec 20 21:26:12 GMT 2020


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

--- Comment #4 from anlauf at gcc dot gnu.org ---
A first attempt to fix the character / non-character issue seem to require
a replacement of the following hunk from

commit eb401400f59e4d1f28bbdc788c3234e0968081d7
Author: Andre Vehreschild <vehre@gcc.gnu.org>
Date:   Wed Dec 14 12:52:09 2016 +0100

    re PR fortran/78672 (Gfortran test suite failures with a sanitized
compiler)


diff --git a/gcc/fortran/data.c b/gcc/fortran/data.c
index 139ce880534..ea19732ccc3 100644
--- a/gcc/fortran/data.c
+++ b/gcc/fortran/data.c
@@ -483,7 +483,10 @@ gfc_assign_data_value (gfc_expr *lvalue, gfc_expr *rvalue,
mpz_t index,

   if (ref || last_ts->type == BT_CHARACTER)
     {
-      if (lvalue->ts.u.cl->length == NULL && !(ref && ref->u.ss.length !=
NULL))
+      /* An initializer has to be constant.  */
+      if (rvalue->expr_type != EXPR_CONSTANT
+         || (lvalue->ts.u.cl->length == NULL
+             && !(ref && ref->u.ss.length != NULL)))
        return false;
       expr = create_character_initializer (init, last_ts, ref, rvalue);
     }

by

diff --git a/gcc/fortran/data.c b/gcc/fortran/data.c
index 3e52a5717b5..76ddd9dab7f 100644
--- a/gcc/fortran/data.c
+++ b/gcc/fortran/data.c
@@ -546,12 +546,11 @@ gfc_assign_data_value (gfc_expr *lvalue, gfc_expr
*rvalue, mpz_t index,
        return false;
     }

-  if (ref || last_ts->type == BT_CHARACTER)
+  if (ref || (last_ts->type == BT_CHARACTER
+             && rvalue->expr_type == EXPR_CONSTANT))
     {
       /* An initializer has to be constant.  */
-      if (rvalue->expr_type != EXPR_CONSTANT
-         || (lvalue->ts.u.cl->length == NULL
-             && !(ref && ref->u.ss.length != NULL)))
+      if (lvalue->ts.u.cl->length == NULL && !(ref && ref->u.ss.length !=
NULL))
        return false;
       expr = create_character_initializer (init, last_ts, ref, rvalue);
     }

which fixes the ICE to the second testcase in comment#3.
However, it changes the traceback for comment#0 to:

pr93685.f90:1:9:

    1 | program p
      |         1
internal compiler error: in gfc_conv_string_init, at fortran/trans-const.c:148
0x79a56a gfc_conv_string_init(tree_node*, gfc_expr*)
        ../../gcc-trunk/gcc/fortran/trans-const.c:148
0x7c735f gfc_conv_initializer(gfc_expr*, gfc_typespec*, tree_node*, bool, bool,
bool)
        ../../gcc-trunk/gcc/fortran/trans-expr.c:7883
0x7c79e6 gfc_conv_structure(gfc_se*, gfc_expr*, int)
        ../../gcc-trunk/gcc/fortran/trans-expr.c:8754
0x7c7391 gfc_conv_initializer(gfc_expr*, gfc_typespec*, tree_node*, bool, bool,
bool)
        ../../gcc-trunk/gcc/fortran/trans-expr.c:7876
0x7a7f2a gfc_get_symbol_decl(gfc_symbol*)
        ../../gcc-trunk/gcc/fortran/trans-decl.c:1917
0x7aba8f generate_local_decl
        ../../gcc-trunk/gcc/fortran/trans-decl.c:5950
0x75bf12 do_traverse_symtree
        ../../gcc-trunk/gcc/fortran/symbol.c:4171
0x7acfcc generate_local_vars
        ../../gcc-trunk/gcc/fortran/trans-decl.c:6156
0x7acfcc gfc_generate_function_code(gfc_namespace*)
        ../../gcc-trunk/gcc/fortran/trans-decl.c:6815
0x724cc7 translate_all_program_units
        ../../gcc-trunk/gcc/fortran/parse.c:6351
0x724cc7 gfc_parse_file()
        ../../gcc-trunk/gcc/fortran/parse.c:6620
0x77187f gfc_be_parse_file
        ../../gcc-trunk/gcc/fortran/f95-lang.c:212


More information about the Gcc-bugs mailing list