Commit 68577e56 by Erik Edelmann Committed by Erik Edelmann

re PR fortran/21625 ([4.0 only] Nested derived type pointer component not initialized on ALLOCATE)

	PR fortran/21625
	* resolve.c (expr_to_initialize): New function.
	(resolve_allocate_expr): Take current statement as new
	argument. Add default initializers to variables of
	derived types, if they need it.
	(resolve_code): Provide current statement as argument to
	resolve_allocate_expr().

From-SVN: r105642
parent 8c2805d1
2005-10-20 Erik Edelmann <erik.edelmann@iki.fi>
PR fortran/21625
* resolve.c (expr_to_initialize): New function.
(resolve_allocate_expr): Take current statement as new
argument. Add default initializers to variables of
derived types, if they need it.
(resolve_code): Provide current statement as argument to
resolve_allocate_expr().
2005-10-19 Paul Thomas <pault@gcc.gnu.org> 2005-10-19 Paul Thomas <pault@gcc.gnu.org>
PR fortran/24440 PR fortran/24440
......
...@@ -2609,17 +2609,49 @@ resolve_deallocate_expr (gfc_expr * e) ...@@ -2609,17 +2609,49 @@ resolve_deallocate_expr (gfc_expr * e)
} }
/* Given the expression node e for an allocatable/pointer of derived type to be
allocated, get the expression node to be initialized afterwards (needed for
derived types with default initializers). */
static gfc_expr *
expr_to_initialize (gfc_expr * e)
{
gfc_expr *result;
gfc_ref *ref;
int i;
result = gfc_copy_expr (e);
/* Change the last array reference from AR_ELEMENT to AR_FULL. */
for (ref = result->ref; ref; ref = ref->next)
if (ref->type == REF_ARRAY && ref->next == NULL)
{
ref->u.ar.type = AR_FULL;
for (i = 0; i < ref->u.ar.dimen; i++)
ref->u.ar.start[i] = ref->u.ar.end[i] = ref->u.ar.stride[i] = NULL;
result->rank = ref->u.ar.dimen;
break;
}
return result;
}
/* Resolve the expression in an ALLOCATE statement, doing the additional /* Resolve the expression in an ALLOCATE statement, doing the additional
checks to see whether the expression is OK or not. The expression must checks to see whether the expression is OK or not. The expression must
have a trailing array reference that gives the size of the array. */ have a trailing array reference that gives the size of the array. */
static try static try
resolve_allocate_expr (gfc_expr * e) resolve_allocate_expr (gfc_expr * e, gfc_code * code)
{ {
int i, pointer, allocatable, dimension; int i, pointer, allocatable, dimension;
symbol_attribute attr; symbol_attribute attr;
gfc_ref *ref, *ref2; gfc_ref *ref, *ref2;
gfc_array_ref *ar; gfc_array_ref *ar;
gfc_code *init_st;
gfc_expr *init_e;
if (gfc_resolve_expr (e) == FAILURE) if (gfc_resolve_expr (e) == FAILURE)
return FAILURE; return FAILURE;
...@@ -2674,6 +2706,19 @@ resolve_allocate_expr (gfc_expr * e) ...@@ -2674,6 +2706,19 @@ resolve_allocate_expr (gfc_expr * e)
return FAILURE; return FAILURE;
} }
/* Add default initializer for those derived types that need them. */
if (e->ts.type == BT_DERIVED && (init_e = gfc_default_initializer (&e->ts)))
{
init_st = gfc_get_code ();
init_st->loc = code->loc;
init_st->op = EXEC_ASSIGN;
init_st->expr = expr_to_initialize (e);
init_st->expr2 = init_e;
init_st->next = code->next;
code->next = init_st;
}
if (pointer && dimension == 0) if (pointer && dimension == 0)
return SUCCESS; return SUCCESS;
...@@ -4022,7 +4067,7 @@ resolve_code (gfc_code * code, gfc_namespace * ns) ...@@ -4022,7 +4067,7 @@ resolve_code (gfc_code * code, gfc_namespace * ns)
"of type INTEGER", &code->expr->where); "of type INTEGER", &code->expr->where);
for (a = code->ext.alloc_list; a; a = a->next) for (a = code->ext.alloc_list; a; a = a->next)
resolve_allocate_expr (a->expr); resolve_allocate_expr (a->expr, code);
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment