diff options
author | Paul Thomas <pault@gcc.gnu.org> | 2024-04-29 11:52:11 +0100 |
---|---|---|
committer | Paul Thomas <pault@gcc.gnu.org> | 2024-04-29 11:52:11 +0100 |
commit | bca41a8d55e830c882b0f39246afead4fcfae6f7 (patch) | |
tree | 913b30b448eabf17f6c75dcadadbd5fa9c561369 /gcc/fortran | |
parent | add51a2514a39978dc66976a8974f8435c86168f (diff) | |
download | gcc-bca41a8d55e830c882b0f39246afead4fcfae6f7.zip gcc-bca41a8d55e830c882b0f39246afead4fcfae6f7.tar.gz gcc-bca41a8d55e830c882b0f39246afead4fcfae6f7.tar.bz2 |
Fortran: Fix regression caused by r14-9752 [PR114959]
2024-04-29 Paul Thomas <pault@gcc.gnu.org>
gcc/fortran
PR fortran/114959
* trans-expr.cc (gfc_trans_class_init_assign): Return NULL_TREE
if the default initializer has all NULL fields. Guard this
by a requirement that the code not be EXEC_INIT_ASSIGN and that
the object be an INTENT_OUT dummy.
* trans-stmt.cc (gfc_trans_allocate): Change the initializer
code for allocate with mold to EXEC_ALLOCATE to allow an
initializer with all NULL fields.
gcc/testsuite/
PR fortran/114959
* gfortran.dg/pr114959.f90: New test.
Diffstat (limited to 'gcc/fortran')
-rw-r--r-- | gcc/fortran/trans-expr.cc | 28 | ||||
-rw-r--r-- | gcc/fortran/trans-stmt.cc | 5 |
2 files changed, 21 insertions, 12 deletions
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc index 072adf3..0280c44 100644 --- a/gcc/fortran/trans-expr.cc +++ b/gcc/fortran/trans-expr.cc @@ -1720,6 +1720,7 @@ gfc_trans_class_init_assign (gfc_code *code) gfc_se dst,src,memsz; gfc_expr *lhs, *rhs, *sz; gfc_component *cmp; + gfc_symbol *sym; gfc_start_block (&block); @@ -1736,18 +1737,25 @@ gfc_trans_class_init_assign (gfc_code *code) /* The _def_init is always scalar. */ rhs->rank = 0; - /* Check def_init for initializers. If this is a dummy with all default - initializer components NULL, return NULL_TREE and use the passed value as - required by F2018(8.5.10). */ - if (!lhs->ref && lhs->symtree->n.sym->attr.dummy) + /* Check def_init for initializers. If this is an INTENT(OUT) dummy with all + default initializer components NULL, return NULL_TREE and use the passed + value as required by F2018(8.5.10). */ + sym = code->expr1->expr_type == EXPR_VARIABLE ? code->expr1->symtree->n.sym + : NULL; + if (code->op != EXEC_ALLOCATE + && sym && sym->attr.dummy + && sym->attr.intent == INTENT_OUT) { - cmp = rhs->ref->next->u.c.component->ts.u.derived->components; - for (; cmp; cmp = cmp->next) + if (!lhs->ref && lhs->symtree->n.sym->attr.dummy) { - if (cmp->initializer) - break; - else if (!cmp->next) - return build_empty_stmt (input_location); + cmp = rhs->ref->next->u.c.component->ts.u.derived->components; + for (; cmp; cmp = cmp->next) + { + if (cmp->initializer) + break; + else if (!cmp->next) + return NULL_TREE; + } } } diff --git a/gcc/fortran/trans-stmt.cc b/gcc/fortran/trans-stmt.cc index c34e0b4..d355009 100644 --- a/gcc/fortran/trans-stmt.cc +++ b/gcc/fortran/trans-stmt.cc @@ -7262,11 +7262,12 @@ gfc_trans_allocate (gfc_code * code, gfc_omp_namelist *omp_allocate) { /* Use class_init_assign to initialize expr. */ gfc_code *ini; - ini = gfc_get_code (EXEC_INIT_ASSIGN); + ini = gfc_get_code (EXEC_ALLOCATE); ini->expr1 = gfc_find_and_cut_at_last_class_ref (expr, true); tmp = gfc_trans_class_init_assign (ini); gfc_free_statements (ini); - gfc_add_expr_to_block (&block, tmp); + if (tmp != NULL_TREE) + gfc_add_expr_to_block (&block, tmp); } else if ((init_expr = allocate_get_initializer (code, expr))) { |