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);
}
return se.expr;
case BT_CHARACTER:
- {
- tree ctor = gfc_conv_string_init (ts->u.cl->backend_decl,expr);
- TREE_STATIC (ctor) = 1;
- return ctor;
- }
+ if (expr->expr_type == EXPR_CONSTANT)
+ {
+ tree ctor = gfc_conv_string_init (ts->u.cl->backend_decl, expr);
+ TREE_STATIC (ctor) = 1;
+ return ctor;
+ }
+ /* Fallthrough. */
default:
gfc_init_se (&se, NULL);
gfc_conv_constant (&se, expr);
--- /dev/null
+! { dg-do run }
+! PR93685 - ICE in gfc_constructor_append_expr, at fortran/constructor.c:135
+
+program p
+ implicit none
+ type t
+ character, pointer :: a
+ end type t
+ type u
+ integer, pointer :: i
+ end type u
+ type(t) :: x
+ type(u) :: y
+ character, target :: c = 'c'
+ integer , target :: i = 10
+ data x%a /c/
+ data y%i /i/
+ if (x% a /= "c") stop 1
+ if (y% i /= 10) stop 2
+end
--- /dev/null
+! { dg-do compile }
+! PR93685 - ICE in gfc_constructor_append_expr, at fortran/constructor.c:135
+
+program p
+ implicit none
+ type t
+ character :: a
+ end type t
+ type u
+ integer :: i
+ end type u
+ type(t) :: x
+ type(u) :: y
+ character, target :: c = 'c'
+ integer , target :: i = 10
+ data x%a /c/ ! { dg-error "non-constant initialization expression" }
+ data y%i /i/ ! { dg-error "non-constant initialization expression" }
+end